File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes forms and input Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "forms and input" Watch "forms and input" New topic

forms and input

John Rainey

Joined: Dec 05, 2002
Posts: 17
I'm returning an com.test.Account object from a database and need to display it on the page. I've set up a dynaForm and given it 1 property -account - with a type of com.test.Account. The user can then edit the data and submit the form. My question is follows: Is it better to create forms to match your object(have getter and setters for each field) or can you do it like I did above and reference the field in the JSP page like - account.accountnumber??
The issue I see with doing it the second way is when the user resubmits the form, how does Struts automatically populate the form if you don't have each field listed in the form?
Adam Hardy
Ranch Hand

Joined: Oct 09, 2001
Posts: 567
If you have a bean in a form, struts will match request names like account.accountnumber with the setAccountnumber() setter method on the 'account' bean that it gets from the formbean's getAccount() getter.
I actually did a whole project like this. Most of my formbeans contained 2 or 3 properties only, one of which was another bean, a value bean, containing the data that the user would see.
Seemed more logical and fitted the MVC design pattern better, I thought, although I never asked the big boys on the struts-user list what they thought.

I have seen things you people would not believe, attack ships on fire off the shoulder of Orion, c-beams sparkling in the dark near the Tennhauser Gate. All these moments will be lost in time, like tears in the rain.
I agree. Here's the link:
subject: forms and input
jQuery in Action, 3rd edition