LookupForm.java
The LookupForm.java is a simple Java Bean that extends org.apache.struts.action.ActionForm, as must all ActionForm objects, with get and set accessor methods that map to the corresponding data members in the jsp view page. In the case it is a single data member symbol, on the index.jsp page.
When the from is submitted, the Struts Framework populates the matching data members of the ActionForm with the corresponding values entered in the <html:input /> tags. The struts framework does this by using JavaBean introspection, therefore, the accessors of the ActionForm must follow the JavaBean standard naming convention.
To satisfy the JavaBean standard, the accessor used to set the symbol data member must be prefixed with set and get followed by the data member name, with the first letter of the data member being capitalized.
This ActionForm also has a specific ActionForm bean: the reset() method. The reset(0 method is called by the Struts Framework with each request that uses the LookupForm. The purpose of this method is to reset all the LookupForm's data members and allow the LookupForm object to be pooled for reuse for that session.
After compiling this class we move the class file to <CATALINA_HOME>/webapps/getquote/WEB-INF/classes/src directory and add the following lines in the struts-config.xml file.
<action-mappings>
<action path="/Lookup"
type="src.LookupAction"
name="lookupForm" >
<forward name="success" path="/quote.jsp" />
<forward name="failure" path="/index.jsp" />
</action>
</action-mappings>
package src;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
public class LookupForm extends ActionForm {
private String symbol = null;
public String getSymbol(){
return (symbol);
}
public void setSymbol (String symbol) {
this.symbol = symbol;
}
public void reset (ActionMapping mapping, HttpServletRequest request) {
this.symbol = null;
}
}
The ActionForm class object that gets created, is used to collect the data from the index.jsp view. On the Index.jsp page, when the <html:form /> is submitted, the struts framework populates the matching data members of the ActionForm with the values entered in <html:input /> tags. The struts framework does this by using JavaBean introspection, therefore, the accessors of the ActionForm must follow the JavaBean standard naming convention.
To satisfy the JavaBean standard, the accessors used to set the "symbol" data member must be prefixed with set and get followed by the data member name with the first letter of the data member capitalized.
So in this case for the data member "symbol", we must define the setSymbol and the getSymbol methods.
The LookupForm.java is a simple Java Bean that extends org.apache.struts.action.ActionForm as must all the ActionForm objects, with get and set accessors that match the data members defined in the <html:text /> tags in index.jsp. This LookupForm has a reset method that gets called on clicking the RESET button which does nothing but initializes the "symbol" data member to a null value. The purpose of this method is to reset all of the data members of LookupForm to null values and allow the LookupForm object to be pooled for reuse.
We make an entry for this form in the
<CATALINA_HOME>/webapps/strutsapp/WEB-INF/struts-config.xml file. as follows
<form-beans>
<form-bean name="lookupForm"
type="src.LookupForm"/>
</form-beans>
When we compile this form, a class object for this form will get created which we have to move to
<CALALINA_HOME>/webapps/strutsapp/WEB-INF/classes/src folder path. Or in the ant script you can specify the path in which the class file is to be created.
References
Professional Jakarta Struts by James Goodwill, Richard Hightower
God's Word for the day
Never trust your enemy,
For like corrosion in copper, so is his wickedness
Even if he humbles himself and walks bowed down,
Take care to be on your guard against him
Be to him like one who polishes a mirror,
To be sure it does not become completely tarnished.
Do not put him next to you,
Or he may overthrow you and take your place.
Do not let him sit at your right hand
Or else he may try to take your seat
And at last you will realize the truth of my words
and be stung by what I have said.
Sirach 12:10-11
No comments:
Post a Comment