• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to populate form B from form A ?

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

Thanks
 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Tokunbo Oke
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic