29.01.2013 Views

WebSphere Application Server - IBM Redbooks

WebSphere Application Server - IBM Redbooks

WebSphere Application Server - IBM Redbooks

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Figure 12-33 Creating an ActionForm class<br />

This generates the template code for the LoginForm class and opens the<br />

corresponding file in the Java editor.<br />

Note: In the JavaSource folder of the OnlineCatalog project, a package<br />

called onlinecatalog.forms has been created and contains the<br />

LoginForm.java file.<br />

11.Replace the validate method with the following code.<br />

Example 12-12 Validate method code<br />

public ActionErrors validate(<br />

ActionMapping mapping,<br />

HttpServletRequest request) {<br />

ActionErrors errors = new ActionErrors();<br />

// Validate the fields in your form, adding each error to<br />

this.errors as found.<br />

if((username == null) || (username.length() < 1))<br />

errors.add("username", new<br />

ActionError("error.username.required"));<br />

if((password == null) || (password.length() < 1))<br />

errors.add("password", new<br />

ActionError("error.password.required"));<br />

return<br />

errors;<br />

Chapter 12. Using Struts 443

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!