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

valueChangelistener vs Javascript  RSS feed

 
bert brutzel
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

One of the input fields of my form should be mandatory in dependency of the currently selected item of an item list. The label of this input field should be bold only if the value of the list is (e.g) 2 or 3. This should be done without validating any other field.

So I wrote this valueChangeListener:



But the event obviously occurs only when the whole form is submitted, evan with immediate="true". But then all other fields are validated also
Because I'm new to JSF, I don't understand, which action is fired at which time.

So is it better to write a special validator and handle the style of the label with Javascript? I think this is very dirty! How can I do this with JSF?

Sorry for my english and many thanks for your help!
utzel

 
bert brutzel
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the meantime I've found out, I was successful (beside fixing some errors in the listener) with <f:ajax ...
 
suresh dasari
Ranch Hand
Posts: 121
Chrome Eclipse IDE Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I faced the same issue.
it worked for me, but when you submit the page without selecting any value from dropdown then valueChangeListener is called once and then for the second click page is submitting resulting in double submission of a page when dropdown is not altered

if you change the dropdown once, then for single submission is working fine.

can any one help me out?
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you use RichFaces, this is fairly simple. Your valuechangelistener only needs to set a "render" flag. Use the ajaxSingle attribute on the AJAX event definition to limit input to just the input control in question and a reRender= that includes the control whose state you want updated. The valuechangelistener ONLY needs to set a flag - no mucking around with the component tree is required, since RichFaces does all the sordid little details automatically, as long as the affected control has its render= attribute set to monitor the flag that the valuechangelistener toggles.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!