Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

help in understanding the struts-example

 
azure ss
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,I am going through the struts-example comes with the struts package.I have some question about the mainMenu.jsp and EditRegistrationAction.java:
1.In the mainMenu.jsp,the action class is trigerred by <html:link page="/editRegistration.do?action=Edit">.And we can found that in the structs-config.xml,there is a action mapping as follows:
<action path="/editRegistration"
type="org.apache.struts.webapp.example.EditRegistrationAction"
name="registrationForm"
scope="request"
validate="false">
<forward name="success" path="/registration.jsp"/>
</action>
I understand that When the ActionServlet received the request from mainMenu.jsp,it will first create an instance of registrationForm if it's not exits yet.And then try to update the fields in it if there is a attribute with the same name from the request.In this case,I think only the action fields in the FormBean will be updated,and the form parameter in the EditRegistrationAction class won't be null,right?
2.in the EditRegistrationAction.java,before setting the value of the formbean,there is a statement:
RegistrationForm regform = (RegistrationForm) form;
what's the use of it?why not use the variable form directly?
 
Varadaraj Krishnam
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
When you click on the link, the Controller would create create an object of the class type "RegistrationForm". This RegistrationForm Class itself is an extension of the class "ActionForm". The Controller would populate the QueryString value into the property of the "RegistrationForm" object and passes this to the Process method of the Action class as a Parameter "form" of the type "ActionForm". Now when you want to use this form, you have to typecast the "form" object to "RegistrationForm" then use the corresponding get Method to retrive the variable.
 
Varadaraj Krishnam
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, it is not "Process" Method but "Perform" method.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic