Hi All,
I was wondering if anyone knew what the lifecycle of an ActionForm is?
The reason I ask is in regards to the display of variables with a <html:form>.
I have noticed that the values displayed within a <html:form> are values after a
reset() method has been called,
and not after a validate method is called. Can anyone tell me the reason for this, as
I seem to think this is a bug
within the Struts framework.
An example follows as to what I am talking about (based upon the following ActionForm):
// Example ActionForm
public class MyActionForm extends ActionForm {
private String maximumDocuments = "3";
... // More variables
public MyActionForm() {
super();
System.out.println("Constructor called");
}
public void setMaximumDocuments(String maximumDocuments) {
this.maximumDocuments = maximumDocuments;
}
public String getMaximumDocuments() {
return maximumDocuments;
}
... // More get/set methods
public ActionErrors validate(ActionMapping actionMapping, HttpServletRequest
httpServletRequest) {
ActionErrors errors = new ActionErrors();
System.out.println("validate called");
System.out.println("before processing maximumDocuments: " + maximumDocuments);
if(maximumDocuments == null) {
maximumDocuments = "50"; // The supposed default value (if no value
entered)
}
System.out.println("after processing maximumDocuments: " + maximumDocuments);
... // Say an error has been returned
return errors;
}
public void reset(ActionMapping mapping, HttpServletRequest request) {
System.out.println("reset called");
System.out.println("before processing maximumDocuments: " +
this.maximumDocuments);
this.maximumDocuments = "50";
System.out.println("after processign maximumDocuments: " +
this.maximumDocuments);
}
}
SCENARIOS:
------------------------------------------------------------------------------------------------------------------------
LIFECYCLE 1: From a previous page to a form which uses this ActionForm
The following output gets displayed:
Constructor called
reset called
before processing maximumDocuments: 3
after processing maximumDocuments: 50
RESULT: Here the value displayed in the form is 50 for maximumDocuments (Correct)
------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
LIFECYCLE 2: If an error occurs within the ActionForm (and the value 1 has been
entered for maximumDocuments)
The following output gets displayed:
Constructor called
reset called
before processing maximumDocuments: 3
after processing maximumDocuments: 50
validate called
before processing maximumDocuments: 1
after processing maximumDocuments: 1
RESULT: Here the value displayed in the form is 50 for maximumDocuments (Incorrect
as it should be 1)
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Can anyone please tell me why this is happening, and how to correct this problem.
Cheers
Rodneyt Paul