my dog learned polymorphism
The moose likes Struts and the fly likes Using a form with Struts 2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Using a form with Struts 2" Watch "Using a form with Struts 2" New topic

Using a form with Struts 2

m pa

Joined: Apr 17, 2013
Posts: 17
I am familiar with struts 1.3 where in the struts.xml file you can define a form that contains beans, lists of beans etc and then that form can be used by different actions.
example in struts 1.3

The examples I have found is having a Person bean and then importing into the action class, see

If I wanted to have a form like that above in Struts 2, am I correct in thinking I would define a class e.g. CustInfoForm, have getters/setters for all the properties and then include the form in whatever class it is needed?

In other words, is there no equivalent of the DynaActionForm in struts 2 that allows forms to be defined in the struts.xml file?
Joe Ess

Joined: Oct 29, 2001
Posts: 9189

Struts 2 does away with forms beans (thank goodness!). It uses Plain Old Java Objects (POJO's), so instead of creating a form bean, you'd just create a POJO for your customer information and create it or populate it in your action class. Since the action has a direct reference to it, there's no need to configure it in an XML file.
DynaActionForm was a work-around for having to create a form bean for each form. Since we don't have form beans, we don't need DynaActionForm.

[How To Ask Questions On JavaRanch]
I agree. Here's the link:
subject: Using a form with Struts 2
jQuery in Action, 3rd edition