• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Multiple selectOneMenu with same value

 
Ranch Hand
Posts: 72
Eclipse IDE Firefox Browser Suse
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI all,
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.

Any suggestions/comments?

Thanks.
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can try giving different names in your ba cking bean. Any specific reason to have the same name for 2 variables.
 
Ad Rajesh
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also you can't have the same 2 variable in the backing bean.
 
Janardan Kelkar
Ranch Hand
Posts: 72
Eclipse IDE Firefox Browser Suse
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

Thanks.
 
Saloon Keeper
Posts: 27752
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think I'd avoid duplicating the control, actually. But the alternative is to add JavaScript so that when you select on one menu, the value is propagated to the other menu via client-side code so there's no disagreement. Either that or use 2 different properties on the backing bean and try and determine which one is authoritative.

The JavaScript solution has the disadvantage that if the user disables JavaScript, you're right back where you started.
 
Janardan Kelkar
Ranch Hand
Posts: 72
Eclipse IDE Firefox Browser Suse
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Tim,
Yes, the idea of having two properties in the backing bean was what i thought of first too....so basically this means that we cannot have the same property for two different components on the page, right? even though it wont throw any exception or error, it will give abnormalities in behaviour....ill try the javascript solution once and then decide from the two!!

 
Tim Holloway
Saloon Keeper
Posts: 27752
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Janardan Kelkar wrote:Thanks Tim,
Yes, the idea of having two properties in the backing bean was what i thought of first too....so basically this means that we cannot have the same property for two different components on the page, right? even though it wont throw any exception or error, it will give abnormalities in behaviour....ill try the javascript solution once and then decide from the two!!



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.
 
Janardan Kelkar
Ranch Hand
Posts: 72
Eclipse IDE Firefox Browser Suse
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Janardan Kelkar
Ranch Hand
Posts: 72
Eclipse IDE Firefox Browser Suse
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Tim,

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.

Inspite of this i am facing the same issue!! So Finally did it the javascript way...As you mentioned, this is not foolproof, so would prefer a method that does this thing in the backend, any workarounds?


Thanks.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Mike Maurer
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic