• 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

A viewpage, a table and two backing beans

 
Ranch Hand
Posts: 300
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Just a concept question if that's ok.
Is this ok in JSF.
- You have one view page (e.g. a .xhtml file)
- This page has a Html Datatable (i.e. h:datatable)
- This datatable gets its values from one backing bean - ValuesBackingBean
- This datatable is bound to a HtmlDataTable in another backing bean - BindingBackingBean
- It is possible to select a row on this table. This is done by making one column a command link.
- When this command link is pressed, an action method on BindingBackingBean is invoked.
- Can the BindingBackingBean get a handle to what was selected?


If not and you have to use one backing bean for both the value of the datatable and the binding of it, how do you pass values from one backing bean to the other?

Thanks.
 
Saloon Keeper
Posts: 27752
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
The easiest way to get 2 backing beans to co-operate is to inject one of them into the other one. In other words, make "bean2" a property of "bean1", provide a "setBean2(Bean2 bean)" method in bean1, and configure bean2 as a managed-property in your JSF config for managed bean1.

Once you do that, bean1's code can simply do things like "x = bean2.getX()".
 
Luke Murphy
Ranch Hand
Posts: 300
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Holloway wrote:The easiest way to get 2 backing beans to co-operate is to inject one of them into the other one. In other words, make "bean2" a property of "bean1", provide a "setBean2(Bean2 bean)" method in bean1, and configure bean2 as a managed-property in your JSF config for managed bean1.

Once you do that, bean1's code can simply do things like "x = bean2.getX()".


Thanks Tim. What would your view of the above be? Do you think it's very messy to have a DataTable getting values from one backing bean and being bound to a component in another backing bean?

Thanks.
 
Tim Holloway
Saloon Keeper
Posts: 27752
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
You'll know ugly when you see it.

 
Luke Murphy
Ranch Hand
Posts: 300
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Holloway wrote:You'll know ugly when you see it.


Ha Ha!Sorry if my questions are a bit trivial. I have read the latest JSF 2 book from Sun. But it really doesn't cover some things I'd like to know.

Thanks again,
 
reply
    Bookmark Topic Watch Topic
  • New Topic