This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Struts and the fly likes why do we typecast ActionForm into our plain java bean class in Action class? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "why do we typecast ActionForm into our plain java bean class in Action class? " Watch "why do we typecast ActionForm into our plain java bean class in Action class? " New topic
Author

why do we typecast ActionForm into our plain java bean class in Action class?

p hasini
Ranch Hand

Joined: Oct 24, 2009
Posts: 92
why do we typecast ActionForm into our plain java bean class in Action class? What is the reason.
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9291
    
  17

Take a look at the API doc of ActionForm class.
Now I typical subclass of ActionForm that we create would look something like this

Now in your action class, if you don't cast ActionForm to LogicForm, then you won't be able to call getUsername or getPassword methods. So basically you can access only the methods of ActionForm class. So then what's the use of ActionForm if you can't access the properties that you created in the bean associated with your Action?? You won't be able to leverage the automatic request parameter transferring capability of Struts as you'll have to access request parameters from the HttpServletRequest object...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
 
Consider Paul's rocket mass heater.
 
subject: why do we typecast ActionForm into our plain java bean class in Action class?
 
Similar Threads
Struts 1 Would ActionForm be Null
ActionForm
Why do we need ActionForm ?
can't typecasting in struts??
Display the contents of folder when the link is clicked