Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A viewpage, a table and two backing beans

 
Luke Murphy
Ranch Hand
Posts: 300
  • Mark post as helpful
  • send pies
  • 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.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18152
52
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • 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
  • 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
Pie
Posts: 18152
52
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • 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
  • 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,
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic