• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

To map more than one form bean to one action

 
Ranch Hand
Posts: 344
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using struts with hibernate.
I have one long application form. The application form is for filling up th personal details,employment details and others. My requirement is, for personal details I have one separate form bean and for the employment details in another form bean.

How to map more than one form bean to one action? How to achieve this in struts?
 
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You cannot map an action to more than one form. You can create a single form that has all the data you need and then populate your database objects based on this data. Forms are part of the presentation layer and they should map closely to your web pages. It sounds like you are letting your database structure influence your forms.

- Brent
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Brent is right: You can't have more than one form bean for a given page. However, a possible work-around would be to use "embedded objects" in your form bean. You could, for example have two properties in your form bean: personalDetails and employmentDetails, each of which is a JavaBean containing properties that describe the respective areas. Then in your JSP, use "dot notation" to identify the properties. Example:


Note: It is a security risk to have a Hibernate controlled object as either a Struts ActionForm bean or an embedded object in a form bean. The reason is that someone could cause an unauthorized update to the database by "spoofing" the page. For example, if you have an Employee bean that is embedded in an ActionForm bean and you have a page that updates something about the employee such as date of hire, a spoofer could create a copy of that page, add "salary" as one of the input fields and succeed in updating the salary in the database.
[ March 13, 2007: Message edited by: Merrill Higginson ]
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could have both the personal details bean and the employment details bean as fields in an employee action form and then access them.
If you want to populate the name field of the personal details bean then it can be done by:

Your employee action form will have a getter and setter for the personalDetails bean similar to any other field in the action form.

I have no clue as to how hibernate and struts work together but I think the above approach should suit your requirement.
 
Dileep Kamath
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Dileep Kamath:
You could have both the personal details bean and the employment details bean as fields in an employee action form and then access them.
If you want to populate the name field of the personal details bean then it can be done by:

Your employee action form will have a getter and setter for the personalDetails bean similar to any other field in the action form.

I have no clue as to how hibernate and struts work together but I think the above approach should suit your requirement.



EDIT:
I saw only after I posted my reply that Merrill has already answered the question
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic