| By Sonny Hastomo | Article Rating: |
|
| April 6, 2007 10:00 AM EDT | Reads: |
94,606 |
Build Action and Action Form
For the Struts action, we just forward to the JSP we already built. The Action code will look as follows:
public ActionForward execute(...) {
return mapping.findForward("success");
}
The Action Form code will validate the requiredText property if the input is blank. Remember to extend this form from the AjaxForm class. The validate method of action form will appear as follows:
public ActionErrors validate(...) {
ActionErrors errors = new ActionErrors();
if (StringUtils.isEmpty(this.requiredText)) {
errors.add("requiredText", new ActionError("error.required.input"));
}
request.setAttribute(Globals.ERROR_KEY, errors);
}
Applying Struts Validation Rules
The configure Struts validation rule, such as minimum length, maximum length, e-mail, and pattern text, will be applied to the input object of the client and the configuration will be similar to Listing 4.
Validation Processing Flow
First the client will initiate the XMLHTTP component to perform the request to the server and, then, on the event the user trigger starts to build, the parameter of the URL will be sent to the server. After its finish building the parameter, the client will attach the event of the oneadystatechange XMLHTTP to listen to the response from the server-side. When the response is accepted, the client side will start to parse the XML validation message and set the message into the right area (see Figure 6).
When the request is accepted to the server, the server will start to check the parameter of the AJAX validation condition and process the validation. Once it's finished, the errors object generated will be filtered into the specific error that is related to the user input object. From this point, the XML message will be generated after the filtering process is done and sent back to the client (see Figure 7).
Summary
In this article we built a controller that has the ability to receive asynchronous requests from the client and incorporate with the struts validation process to produce the action error object. Filtering the specific input object being validated will be done after the error object produces and generates the XML message as a reply to the client-side to indicate the error message (See Image 8 and Image 9).
Published April 6, 2007 Reads 94,606
Copyright © 2007 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Sonny Hastomo
Sonny Hastomo is an IT architect at Sun Microsystems, Indonesia, for the telecommunication industry division. His currently is focusing on providing solution design, sizing, implementation, consulting services, and quality support to customers in their evaluation of their IT challenges.
![]() |
hanan mahmoud 07/27/08 03:39:45 AM EDT | |||
hi all |
||||
![]() |
Commenter 05/17/06 01:40:52 PM EDT | |||
I just need examples, and I can´t find it here. This article is weak. |
||||
![]() |
SYS-CON Belgium News Desk 05/02/06 03:27:56 PM EDT | |||
Struts Validations Framework Using AJAX |
||||
![]() |
SYS-CON Australia News Desk 05/02/06 01:44:38 PM EDT | |||
Real-time data validation is one of the advantages of AJAX technology. By applying this technology, the struts validation framework will enrich the struts MVC and move the Web application closer to the desktop application. |
||||
![]() |
AJAX News Desk 05/02/06 12:55:46 PM EDT | |||
AjaxWorld: Struts Validations Framework Using AJAX |
||||
![]() |
Rajesh 05/02/06 12:17:24 PM EDT | |||
The article was really nice.It would have been better if the source code was included. Thanks |
||||
![]() |
waikit 02/08/06 04:11:11 AM EST | |||
can I have a sample code of the example shown in this article, please regards |
||||
![]() |
SYS-CON Australia News Desk 01/27/06 02:21:45 PM EST | |||
Real-time data validation is one of the advantages of AJAX technology. By applying this technology, the struts validation framework will enrich the struts MVC and move the Web application closer to the desktop application. |
||||
![]() |
Artem Vasiliev 01/26/06 06:18:56 AM EST | |||
Sonnie, thank you for your article, it brings pretty interesting idea. |
||||
- Kindle 2 vs Nook
- Why IBM’s Server Chief Got Busted
- Is Cloud Computing Like Teenage Sex?
- Industry Experts Discuss the State of Cloud Computing
- Performance Tuning Essentials for Java
- Confessions of a Ulitzer Addict
- Tactical Cloud Computing Panel at 1st Annual GovIT Expo
- It's the Java vs. C++ Shootout Revisited!
- Cloud Computing Can Revitalize Your Career as Software Developer
- IBM Could "Reinvent" Java: Mills
- Oracle & Cloud Computing: Exclusive Q&A with SVP Richard Sarwal
- A Brief History of Cloud Computing
- Kindle 2 vs Nook
- Cloud CEOs, CTOs & SVPs to Speak at 4th International Cloud Computing Expo
- Why IBM’s Server Chief Got Busted
- Is Cloud Computing Like Teenage Sex?
- Industry Experts Discuss the State of Cloud Computing
- Performance Tuning Essentials for Java
- The Difference Between Web Hosting and Cloud Computing
- Cloud Computing Expo: Exclusive Q&A with Yahoo! SVP Cloud Computing
- Ajax in RichFaces 3.3, JSF 2 and RichFaces 4
- Confessions of a Ulitzer Addict
- My Thoughts on Ulitzer
- Tactical Cloud Computing Panel at 1st Annual GovIT Expo
- A Cup of AJAX? Nay, Just Regular Java Please
- Java Developer's Journal Exclusive: 2006 "JDJ Editors' Choice" Awards
- The i-Technology Right Stuff
- JavaServer Faces (JSF) vs Struts
- Rich Internet Applications with Adobe Flex 2 and Java
- Java vs C++ "Shootout" Revisited
- Bean-Managed Persistence Using a Proxy List
- Reporting Made Easy with JasperReports and Hibernate
- Creating a Pet Store Application with JavaServer Faces, Spring, and Hibernate
- What's New in Eclipse?
- Why Do 'Cool Kids' Choose Ruby or PHP to Build Websites Instead of Java?
- i-Technology Predictions for 2007: Where's It All Headed?








































