Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

ValueChangeEvent newValue method giving wrong value when component values change indirectly  RSS feed

 
Akhil Pratap Singh
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • 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.
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!