Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
p hasini
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why do we typecast ActionForm into our plain java bean class in Action class? What is the reason.
 
Ankit Garg
Sheriff
Posts: 9527
32
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic