• 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

required field...but only if enabled

 
bronco
Posts: 161
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This seems like it should be SO simple...

I've got a checkbox and a text field. When the checkbox is checked, the field gets enabled; uncheck it, field gets disabled.

I want the text field to be required only when the box is checked.

What seems to happen is this:

1. Checkbox initially disabled.
2. Check the box; field is enabled.
3. Submit the form.
4. Get validation error (good!)
5. Uncheck the box; field is disabled.
6. Submit the form.
7. STILL get the validation error (NOT GOOD! ...since the field is disabled)

I'm hoping I'm just having a brain-is-ready-for-the-weekend day and there's a simple fix for this. Suggestions?

[Oh, possibly of interest...I'm handling the enable/disable via javascript...here's the JSF code:


Thanks.
 
Ranch Hand
Posts: 1400
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Dave Wood:

7. STILL get the validation error (NOT GOOD! ...since the field is disabled)



How did you disabled the field ...
Using javascript or JSF ?
[ January 14, 2005: Message edited by: K Varun ]
 
Varun Khanna
Ranch Hand
Posts: 1400
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oops, I missed your post comment "the enable/disable via javascript":

But did you my question provided any hint
You disabled the field using javascript and didn't bother to inform Server and now you are expecting Server to know your component's state
Not fair




[ January 14, 2005: Message edited by: K Varun ]
 
Dave Wood
bronco
Posts: 161
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
...hmm, but its initial disabled state was also set by javascript and it seemed to do the right thing (ignoring the disabled field) in that case. So I'm still a bit confused.

(I have since reworked the thing to do the validation in the bean's action method...which is fine, I suppose)
 
Varun Khanna
Ranch Hand
Posts: 1400
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Dave Wood:
...hmm, but its initial disabled state



I couldn't understand your initial 2 points:
1. Checkbox initially disabled.
2. Check the box; field is enabled.

How did u checked the box in step 2, which was disabled in step -1

anyways, if you are playing around with component's state in front end @javascript, do ensure same is reflected in server state also.
When you submit any page, the server component behaves as per the state information they have in store.

Check out Restore_View phase description@jsf_specification.
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How to change the component state via jsf?
Do i have to submit the page?

If i do state changes by javascript how do I inform the server then?

Another question which is bothering me is that i have used validator="#{mybean.validateRequiredIf}" when the required="true" is not set for the component.

However if i do not enter any value then the validateRequiredIf is not called.
I am completely new to JSF and these are basics i guess.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic