• 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 ...
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
  • Piet Souris
  • Himai Minh

ValueChangeEvent newValue method giving wrong value when component values change indirectly

Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My form looks like this:

As you can see there are two listener in my xhtml file one for filetype and other for signmethod. When filtype changes signmethod has to change which in turn changes servers. And if user changes signmethod using dropdown then also server should change. But my problem is when filetype changes, both the listeners are called, as signmethod also changea but the value in event object (e.getNewValue()) is not the new one but old one. Here is the SelectView Bean:

This is the static initialisation part just for checking the output at the end of question.

This are the bean valuechange methods and constructor.

This is the output on changing filetypes from Windows(default) to Mobile to Mac to Solaris:

I am changing servers in changeServerAndSignmethod by selecting first signmethod from signmethod arraylist which is giving correct result. But changeServers is also getting fired taking wrong event object's newValue method and changing servers to wrong values. When changeServers is fired bydirectly changing signmethod, by dropdown, it gives correct result. Is there a way I can stop changeServers to fire when the change came from changing filetypes rather than direct change by user on signmethod selectOneMenu. Or any other solution.
Saloon Keeper
Posts: 25477
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
Actually, all that static code did was clutter up the question. I'll take it for granted that you've initialized stuff.

When you fire an JSF command (commandButton, commandLink) or AJAX action, each of the controls in the submitted form (or for AJAX, the selected parts of the form) are processed.

First the incoming values are validated. Failure to validate aborts processing,

Then the valueChangeListeners are invoked for each control which has a listener. The actual pseudo code is:

You can get false firings if the "equals" test fails. One common way for that to happen is if the value used to populate the form had trailing spaces, since HTML will remove the spaces as it does with any space-padded output text. Then when the value is submitted, the trimmed value is visually equal to the original value, but in raw comparison it is unequal.

A less common problem would be if the backing bean property value didn't convert to the exact same (character-by-character) String value as the value being recieved from the form. Since HTML is text-based, the form value is always text, but properties can be of many types, and JSF whill automatically convert them where possible, or require an explicit converter where no automatic conversion is suitable.
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Example http://www.webtuts.in/jsf2-internationalization-example/ and http://www.webtuts.in/valuechangelistener-example-in-jsf-2/
Yeah, but how did the squirrel get in there? Was it because of the tiny ad?
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
    Bookmark Topic Watch Topic
  • New Topic