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 :

Adding AJAX

There are dozens of reasons why you would want to add AJAX to this code—sometimes it's for a sensible reason, other times it's simply because it's became a buzzword. In this case, you're using AJAX to maintain a static page with only one table being updated. This looks slick and adheres to the rules of Web 2.0. In any case, it's up to you to decide whether your application truly needs AJAX or whether you just want a fancy feature.

You'll be using the AjaxTags framework to AJAX-ify your Displaytag code. The first step is adding the libraries, all of which are included in the AjaxTags distro.

The second step involves JavaScripts. You will need four of them: prototype-1.4.0.js, scriptaculous.js, overlibmws.js, and ajaxtags.js.

The third step is the stylesheet. You can make your own or you may decide not to use a stylesheet at all.

Here are the modifications you'll make to list_mailings.jsp:


 1. <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
 2. <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
 3. <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>

 4. <%@ taglib prefix="display" uri="http://displaytag.sf.net" %>
 5. <%@ taglib prefix="dtsource" uri="http://dt-source.sf.net" %>
 6. <%@ taglib prefix="ajax" uri="http://ajaxtags.org/tags/ajax" %>

 7. <html>
 8. <head>
 9. <title>List All Mailings</title>

10. <link type="text/css" rel="stylesheet" href="css/display.css" />
11. <link type="text/css" rel="stylesheet" href="css/ajax.css" />

12. <script type="text/javascript" src="js/prototype-1.4.0.js" />
13. <script type="text/javascript" src="js/scriptaculous.js" />
14. <script type="text/javascript" src="js/overlibmws.js" />
15. <script type="text/javascript" src="js/ajaxtags.js" />

16. </head>
17. <body>

18.     <center>

19.     <dtsource:search id="mailingHS" requestURI="">
20.         from|FROM	to|TO	subject|SUBJECT	id|ID
21.     </dtsource:search>

22.     <dtsource:hibernate pagesize="20" id="mailingHS" list="mlng" 
sizelist="sizemlng" defaultsortName="id" entity="Mailing" alias="m">
23. 	    select ~alias~ from ~entity~ as ~alias~ order by ~sort~
24.     </dtsource:hibernate>

25.     <ajax:displayTag id="displayTagFrame" ajaxFlag="false" tableClass="mlngClass">

26.     <display:table class="mlngClass" name="mlng" sort="external" 
pagesize="20" id="mailingHS" partialList="true" size="sizemlng">
27.         <display:column property="id" sortable="true" sortName="id" title="ID" />
28.         <display:column sortable="true" title="FROM" sortName="from">
29.         <center>
30.             ${fn:escapeXml(mailingHS.from)}
31.         </center>
32.         </display:column>
33.         <display:column sortable="true" title="TO" sortName="to">
34.         <center>
35.             ${fn:escapeXml(mailingHS.to)}
36.         </center>
37.         </display:column>
38.         <display:column property="subject" sortable="true" 
sortName="subject" title="SUBJECT" />
39.     </display:table>

40.     </ajax:displayTag>

41.     </center>

42. </body>
43. </html>
That was easy, wasn't it?

Now, go through the code to see what has changed:

  • Line 6 adds the taglib.
  • Lines 11-15 include the stylesheet (you may not have it) and JavaScript. Please note that the order in which the JavaScript tags are added is important.
  • Line 25 starts the "framing" of Displaytag's part. It's important to set the tableClass the same as class in display:table, otherwise, your code will not be AJAX-ified.
  • Line 40 closes the "framing."

You are now ready to deploy your application.

In Pursuit of Time Better Spent

While this article hasn't uncovered any new technology or hidden features, it can help you in your daily work: when you find yourself messing with a lot of different screens, but your time would be better spent writing business logic, hopefully the tricks you learned in this article will save you some time.

Resources

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.

 Internet.com eBook Library
 IBM Software Construction Toolbox
 Microsoft RIA Development Center
 Destination .NET
XML error: not well-formed (invalid token) at line 38
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%.

Mozilla's Ubquity Mashup: For The Masses?
iPhone Users Just Want to Have Fun
Oops! I Fixed the Linux Kernel
Jim Zemlin: The New Center of Linux Gravity
Microsoft's Novell Investment Tops $340M
Fedora 10 Takes Shape
IBM Gives a Mobile Voice to Developers
Inadequate Tools Send Software Down the Drain
USB 3.0 One Step Closer to Reality
Would-Be Linux Contributors May Get a Leg Up

Develop a Mobile RSS Feed the Easy Way
State of the Semantic Web: Know Where to Look
A 3D Exploration of the HTML Canvas Element
Setting Up and Running Subversion and Tortoise SVN with Visual Studio and .NET
Java/JRuby Developers, Say Open 'Sesame' to the Semantic Web
Interpreting Images with MRDS Services
DevXtra Editors' Blog: Executives Avoiding Cloud Computing in Droves
Q&A with James Reinders on the Intel Parallel Studio Beta Program
The Pros and Cons of Outsourcing Enterprise Emails
Hosting Options: Shared or Dedicated Server

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