This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes JSF and the fly likes How to populate form B from form A ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » JSF
Bookmark "How to populate form B from form A ?" Watch "How to populate form B from form A ?" New topic

How to populate form B from form A ?

Tokunbo Oke
Ranch Hand

Joined: Sep 09, 2003
Posts: 57
If two forms appear in the same screen (JSP/JSF file) say forms A and B, can a button on form A, populate the fields of form B via JSF lifecycle?

Form B works well i.e. it gets populated with data when its action method is called from a button attached to it (form B), but not when the form B's action method is called from a backing bean method of form A.

Please note, although the forms are in the same screen each form has a separate backing bean.

Please tell me how to get this to work.

Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17033

HTML (not JSF) mandates that if you have more than one form on a page, only the items within that form will be passed to the server when you submit the form. No data from any other form on the page will be submitted.

People do occasionally simulate the submission of the other form's data, but that's done by using client-side JavaScript to actually stuff the data into the DOM representation of the submitted form before submitting it. In other words, by moving the extra fields off of the form not being submitted and into the form that is being submitted.

When a JSF page is (re)rendered, all data from all the backing beans is retrieved. So if your submit changes a property on a backing bean that's got properties references in some other form, the display for that other form will reflect those changes.

All of that can be altered by AJAX and other JavaScript functions, but I'm referring to basic HTML, which is all that the core JSF functions provide.

So in summary, when you submit, only the data on the submitted form is sent, but data on all forms is retrieved when the page redisplays.

An IDE is no substitute for an Intelligent Developer.
Tokunbo Oke
Ranch Hand

Joined: Sep 09, 2003
Posts: 57
Thank you very much for your response.

Your JSF related comments reflects what my research has also indicated i.e. that I should get the relevant bean from the relevant scope and then update the relevant properties.

I will post an update after experimenting.

Tokunbo Oke
Ranch Hand

Joined: Sep 09, 2003
Posts: 57
Getting the relevant backing bean (backing bean of form B) from the relevant scope and updating the relevant properties, made it possible to achieve my goal. Once again, thanks a lot Tim.
Have you checked out Aspose?
subject: How to populate form B from form A ?
It's not a secret anymore!