The ActionForm

I l @ ve RuBoard

The ActionForm

When one of the Submit buttons is hit, the controller looks up the name of the requested ACTION in the struts-config.xml file. In this case, it finds that the page requested /myAccount and therefore needs to store any form data into accountForm (see Listing 16.3) through introspection. accountForm just holds the values in normal bean property fashion.

Listing 16.3 accountForm.java
 package com.bfg.struts; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionMapping; public class accountForm extends ActionForm {   protected String action;   protected String cardIndex;   protected int addressIndex;   public void setAction(String text) {     action = text;   }   public String getAction() {     return action;   }   public void setCardIndex(String text) {     cardIndex = text;   }   public String getCardIndex() {     return cardIndex;   }   public void setAddressIndex(int val) {     addressIndex = val;   }   public int getAddressIndex() {     return addressIndex;   } } 

After storing the values, Struts checks to see if a validator method has been defined for the ActionForm . In this case, there isn't, which is the same as having a successful validation. The config file also specified the class of the bean that implements the business logic, which must extend Action and implement the method perform .

Because ActionForm and Action sound so similar, it's worth repeating the distinction. The ActionForm has the placeholders for any submitted data and validates the data. The Action defines the business logic and determines what the ultimate destination of the action is.

I l @ ve RuBoard


MySQL and JSP Web Applications. Data-Driven Programming Using Tomcat and MySQL
MySQL and JSP Web Applications: Data-Driven Programming Using Tomcat and MySQL
ISBN: 0672323095
EAN: 2147483647
Year: 2002
Pages: 203
Authors: James Turner

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net