aspose file tools*
The moose likes JSF and the fly likes Gather dataTable with selectOneMenu to bean 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 "Gather dataTable with selectOneMenu to bean" Watch "Gather dataTable with selectOneMenu to bean" New topic
Author

Gather dataTable with selectOneMenu to bean

Matthew Constans
Greenhorn

Joined: May 10, 2011
Posts: 3
Hi, for couple days i struggle with that task.
I need to display datatable with names and choose from list another names to coapt.

Here is the snippet of code:


MyBean.performers returns list of performers with getName() method;
MyBean.userList returns list of users with getName() and getId() methods;

Whats the problem:
When i click "Save" i want to save the matches, e.g. Performer1: User2 (2), Performer2: User1(1), Performer3: User3(3).

I don't know how to get to these matchings from bean. I tried
HtmlDataTable htDT = (HtmlDataTable) FacesContext.getCurrentInstance().getUIViewRoot().findComponent("someDataTableId");
but it always returns null.

I did something with binding attribute but couldn't get that to work either.

Any sugestions?
Thanks in advance :-)
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1018
You are displaying a list of performers in your data table.
Each "row" in that datatable should be related to one performer.
Each control in that datatable should be related to a field on that performer

I think your issue is that you have mapped the <f:selectOneMenu > control to your main backing bean #{MyBean.user} when it should be related to the object you are iterating with: #{perf.user} or similar.
The list of options in the menu (f:selectItems) can come from MyBean - thats the same list for all rows in the datatable presumably.

When you submit the page it should iterate through your list of performers, and set the value of "user" for each performer based on what you selected in each select one menu.

Matthew Constans
Greenhorn

Joined: May 10, 2011
Posts: 3
Stefan Evans wrote:
When you submit the page it should iterate through your list of performers, and set the value of "user" for each performer based on what you selected in each select one menu.


That's the thing i would like to achieve

I did like you said, moved the userList into performer but when i do saveIt the list of performers is null!

That is the part of bean i am talking about:



I did also control prints in setter methods of WFPerformers, none of them is called after i press "Save"
Matthew Constans
Greenhorn

Joined: May 10, 2011
Posts: 3
Issue resolved, the problem was in import of sessionScope (faces.bean. / enterprise.context.). Me, dumb one, spent 7 hours of analysing code, when mistake wasn't there...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Gather dataTable with selectOneMenu to bean