File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to get multiple h:selectOneMenu values inside h:dataTable on form submit

 
Ajay Kamble
Ranch Hand
Posts: 51
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

How can I get multiple h:selectOneMenu values inside h:dataTable on form submit?

I know that for checkbox inside dataTable I can use a HashMap to get values,



What can I do for dropDowns?

Also we just dont want array of values, we need some way to check what value was for which row!

-Ajay
 
Tim Holloway
Saloon Keeper
Pie
Posts: 17646
39
Android Eclipse IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is totally confusing. You ask about selectOneMenu, but your example is a selectBooleanCheckbox. You claim to want to use the multi-value list selection option, but you don't want multiple values (an array) posted to your bean.

Could you clarify, please?
 
Ajay Kamble
Ranch Hand
Posts: 51
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

1. You imagine this with a datatable which has data for countries, there are two columns, one is country name and other is a checkbox. My concern is that when I submit page I need to know which Country was checked and which was not. The code snippet that I have shown shows how to do this. With this code when I submit page I get values in selectedRows HashMap. This code is explained here- http://balusc.blogspot.com/2006/06/using-datatables.html

2. Now imagine the datatable with one column as country name and other is a drop down to select say timezone options. Now when this form is submitted I need to know what option was selected for which country.

3. I do not want multi-value list. Just one option should be selected for each country. I just want some way to get this data on form submit along with information for which country?

I can do this thing easily with lets say plain Servlet/JSP. JSF simplifies some things but then it is making some simple things hard to do .

-Ajay

 
Tim Holloway
Saloon Keeper
Pie
Posts: 17646
39
Android Eclipse IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Selected" doesn't mean what you think it does. In JSF terms, the "selected" row of a datamodel is the one corresponding to a commandLink or a commandButton that was clicked. You can have zero or many checkboxes in a datatable, so how would the framework know which one was the "selection" checkbox?

JSF is based on MVC and part of that basis means that the code to update the model is in the Controller and doesn't need to be written by you. In the case of the DataTable, the controller is the DataTable element itself.

If you create a DataTable with writable row elements - such as a ListDataModel provides - the rows would be mapped to the GUI. So normally, you'd define row classes such that there'd be a property to back the checkbox value and one to back the selection value. JSF itself would ensure that the values were set properly, automatically.

Which brings up a point. A lot of people think that JSF is supposed to be directly mapping to their persistence datamodels. While it can, very often it should not. The backing beans are actually GUI datamodels, so when you do that, you're overloading 2 functional roles onto one object. In cases where you don't want the persistent datamodel to be directly updated from the GUI (for example, only update checked selections), and for cases where the persistent object doesn't translate well to the GUI (database ORM objects often don't handle booleans well), it's more appropriate to keep the GUI and persistence model objects separate and insert a business layer to translate between them. The business layer is normally invoked by the backing bean's action processor.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic