advertisement
javaboutique
Search Tips
Articles  |   Tutorials  |   Reviews  |   Tools  |   by Category  |   by Date  |   by Name  |   Submit  |   Source  |   Forums  |  
javaboutique
Browse DevX


Partners & Affiliates











advertisement

Tutorials : Simplify List Screen Creation with AJAX :

The Sample Application

Here are snippets of the real Web application, which generates a mailing and keeps information regarding these mailings in a database (using the Hibernate).

Consider the following listing page (list_mailings.jsp):


<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<html>
<head>
<title>List All Mailings</title>
</head>
<body>

	<center>
	<table border="1">
	<tr>
		<td align="center">ID</td>
		<td align="center">FROM</td>
		<td align="center">TO</td>
		<td align="center">SUBJECT</td>
	</tr>
	<c:forEach var="m" items="${allMailings}">
	<tr>
		<td>${m.id}</td>
		<td>${fn:escapeXml(m.from)}</td>
		<td>${fn:escapeXml(m.to)}</td>
		<td>${m.subject}</td>
	/tr>
	</c:forEach>
	</table>
	</center>

</body>
</html>
This is part of a simple Web application acts as a front-end for a mailing engine. This screen shows the list of all mailings made, the ID of the mailings, and the headers "From," "To," and "Subject."

The Spring MVC configuration looks like springmvc-servlet.xml:


<bean id="listMailingsController" 
class="us.prokhorenko.samples.ListMailingsController">
        ...
    </bean>

    <bean id="urlMapping"
	class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
        <property name="mappings">
            <props>
                ...
                <prop key="/listMailings.html">listMailingsController</prop>
                ...
            </props>
        </property>
        ...
    </bean>
The sessionFactory bean, in the applicationContext.xml file, is used to integrate Hibernate using Spring's code. It contains a complete Hibernate configuration, much like hibernate.cfg.xml:

    ...
    <bean id="sessionFactory"
	class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        ...
        <property name="mappingResources">
            <list>
                ...
                <value>Mailing.hbm.xml</value>
                ...
            </list>
        </property>
        ...
    </bean>
    ...
Now take a look at the controller code for the list of mailings (ListMailingController.java):
package us.prokhorenko.samples;

import us.prokhorenko.samples.MailingManager;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class ListMailingsController implements Controller {

    private MailingManager mailingManager;
    public void setMailingManager(MailingManager mailingManager) {
	        this.mailingManager = mailingManager;
    }

    public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse
	response) throws Exception {

        request.setAttribute("allMailings", 
		mailingManager.listMailings("from Mailing m"));

        return new ModelAndView("list_mailings");
    }
}
MailingManager is a manager bean which provides service for working with Mailing object (mapped by Hibernate). The sample described above doesn't need any special configuration at all.

While it's a nice list screen, it's probably not good enough for this application. First of all, as the number of mailings grow, it will be harder to see them, so you need paging. Secondly, you will probably want to add search capabilities so you can find a particular recepient or filter by subject. Lastly, you will definitely want sorting.

How to Add Java Applets to Your Site

New on the Java Boutique:

New Review:

Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling API boasts simplicity, ease-of-integration, a well-rounded feature set, and it's free!

New Applet:

Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA sequences into three useful formats.

Elsewhere on internet.com:

WebDeveloper Java
Lots of Java information on webdeveloper.com

WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.

ScriptSearch Java
Hundreds of free Java code files to download.

jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.

 Microsoft RIA Development Center
 IBM Rational Resource Center
 Destination .NET
XML error: not well-formed (invalid token) at line 33
advertisement
Receive Articles via our XML/RSS feed
Receive Articles via our XML/RSS feed

JavaBytes
Internet Cyclone
This powerful, easy-to-use, internet optimizer is for Windows 95, 98, ME, NT, 2000 and XP. It's designed to automatically optimize your Windows settings, boosting your Internet connection up to 200%.

JUNOS: Open, but Not Open Source
Sun Gives Enterprises a New Mobility Option
iPhone Knocking on the Enterprise
Linux 2.6.26 Opens Up to Debugging
Borland Launches ALM Management Tools
Nominations Open for CEO Vision Awards
A Look at Google's Open Source Protocol Buffer
MySpace Catches iPhone Fever
Software Drives the iPhone 3G
Novell's Linux Build Service Goes Open

Introduction to Scrum
Semantic Search Arrives at the Web
Using the New ListView Control in ASP.NET 3.5
SMS Messaging Using the .NET Compact Framework
Security Enhancements Abound in Windows Server 2008
Design and Use of Moveable and Resizable Graphics, Part 2
Control Your Linux Server Remotely with GnuPG, procmail, and PHP
The Baker's Dozen: 13 Tips for Building Database Web Applications Using ASP.NET 3.5, LINQ, and SQL Server 2005 Reporting Services
Probe and Modify Your Types' Alignment Programmatically
.NET Building Blocks: Custom User Controls in Practice

Advertising Info  |   Member Services  |   Contact Us  |   Help  |   Feedback  |   Site Map  |   Network Map  |   About



JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers