I want to display two selectOneMenu components on my screen at two different locations. I have the same value(same variable in the bean) for both and the same listener method in the bean too. When i do this, i am getting following issues:
1. When i change the value in either of the selectOneMenu Component, the event Listener is triggered and the code in the bean is executed.
2. If it was serially first selectOneMenu that was changed, then both the selectOneMenu still carry the old value.
3. If it was the second selectOneMenu that was changed, then both the components carry the new value.
When the compiler's not happy, ain't nobody happy.
Actually i am displaying a datatable wth pagination. I want to display a choice to the user to display as many records per page as he/she wants. So the drop down will contain values for recordsPerPage. This drop down i want to display at the top and the bottom of the table and user should be able to change the value in any one.
So basically there are no 2 variables in use, but just one, which is being acted upon by two selectOneMenus
Customer surveys are for companies who didn't pay proper attention to begin with.
Janardan Kelkar wrote:Thanks Tim,
Well, if by "abnormalities in behaviour", you mean "It doesn't do what I want it to do", probably so. I think the behaviour itself is within the JSF specs - and thus predictable, for what consolation that's worth.
I do display-only references to the same property multiple places on a page all the time. Classic example is a table where both the ID and caption columns have hyperlinks to detail editing of the row in question.
I Tried using two properties in the backing bean and bind them to the the two selectOneMenus, but it still did not work. Here's what i did in detail:
1. Declare two variables in the backing bean.
2.Have a method in the bean that is common to both the selectOneMenus and is invoked onchange.
3.Ensured that the two variables are set to the new value selected by the user.
I have this same issue with a selectOneMenu component in a datatable column, bound to a single property in the backing bean, and using the same items list. The number of rows in the table is dynamic, but let's say there are 25, thus 25 instances of the selectOneMenu component. No matter which record I change the selectOneMenu value for, the value of the backing bean property will always end up being whatever the current value of LAST instance of the component in the table is set to. For example, if I select "value 2" on the the 4th row, and the 25th (last) row is still set to the default value of "value 1", then calling the getter for that property will always return "value 1". If I change that last instance to something else, like "value 3", then every other selectOneMenu instance will always return "value 3". I put a valueChangeListener on the component with the backing bean method doing a print of the old & new value, and print statements on the 'setter' for that property as well so I could see what was going on. The method called by the valueChangeListener does indeed show correct old and new values. And the setter method is called properly with the new value. But the same setter method is then called again, once for every row in the table, so the property value immediately gets set back to the value of the next call. That's why it always ends up with the value of the component in the LAST row of the table. I can't have unique bean properties and setter/getter methods for each row in the datatable. But surely there is a way to make this work. HELP!
Joined: Jul 13, 2010
Found the solution. Just a dumb oversight on my part. My selectOneMenu component inside the datatable was bound to a single property in the backing bean. I moved that property out of the backing bean and into the object ("Order" object) that my datatable was bound to instead. My datatable is bound to an array of these "Order" objects, and each row is its own unique instance of the Order object, and each contains its own unique instance of the property to hold the value of its selectOneMenu.