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?
Customer surveys are for companies who didn't pay proper attention to begin with.
Joined: Jan 23, 2009
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 .
"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.
subject: How to get multiple h:selectOneMenu values inside h:dataTable on form submit