aspose file tools*
The moose likes JSF and the fly likes A viewpage, a table and two backing beans Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "A viewpage, a table and two backing beans" Watch "A viewpage, a table and two backing beans" New topic
Author

A viewpage, a table and two backing beans

Luke Murphy
Ranch Hand

Joined: May 12, 2010
Posts: 300
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

Joined: Jun 25, 2001
Posts: 16145
    
  21

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()".


Customer surveys are for companies who didn't pay proper attention to begin with.
Luke Murphy
Ranch Hand

Joined: May 12, 2010
Posts: 300
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

Joined: Jun 25, 2001
Posts: 16145
    
  21

You'll know ugly when you see it.

Luke Murphy
Ranch Hand

Joined: May 12, 2010
Posts: 300
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,
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: A viewpage, a table and two backing beans