0

I am working on a JSP project, and I need a functionality that

  1. whenever the check-box is checked, users are REQUIRED to choose an option (from a dropdown menu)
  2. However, whenever the check-box is unchecked, picking an option will not be required.

Right now, my check-box looks like this:

<h:selectBooleanCheckbox class="someClass" value="#{someBean.check}" />

the check is a boolean value in my JAVA class, and my html page should be able to recognize the state of checkbox.

I am wondering how to apply the current state to my dropdown menu, so my dropdown menu will know if user needs to pick one option or not..

Will the use of Ajax listner work in this case? How to get state of SelectBooleanCheckbox in Ajax Listener? Or there's any other suggestions? Thanks a lot!

my previous related question Conditionally make inputs required depending on checkbox value

Community
  • 1
  • 1
yla
  • 187
  • 1
  • 2
  • 10
  • 1
    Your question is very confusing. Are you ultimately asking how to show/hide a `` on click of a ``? The answer on your previous question has already answered how to validate the `` as required depending on the value of ``. – BalusC Oct 03 '13 at 16:58
  • hi, I have done the show/hide, but I am still stuck at the validation. The web page gets me error when I tried binding the checkbox with Javabean.check variable. – yla Oct 03 '13 at 17:10
  • in addition, value="#{someBean.check}" /> gives no error, but the variable does nothing to my dropdown menu... so I was thinking maybe Im just missing something or there's alternative way of doing this – yla Oct 03 '13 at 17:12
  • In other words, you simply didn't apply the answer to your previous question at all? Why not? You need to add `binding="#{checkbox}"` to the `` and do a `required="#{checkbox.value}" ` on the ``. That's all. I have absolutely no idea why you complain that it stopped working after you removed that part. – BalusC Oct 03 '13 at 17:14
  • I did try the solution you provided, but I was not sure why binding the whole class to a element (and my webpage gives me error). I'm not complaining, I am just too newbie on jsf, sorry =(. hmm, I guess I will look up how binding attribute work then. thanks anyway – yla Oct 03 '13 at 17:22
  • You should have told about that error instead of ignoring it. Perhaps you're using Eclipse as a tool and it was just Eclipse who pretented to be smarter than it actually is and incorrectly gave you a warning/error on the EL expression in `required` attribute and therefore you didn't even bother to actually run/test it? As stated in the answer, the code in my answer is complete as-is and no edits or additional changes/configuration needs to be done. – BalusC Oct 03 '13 at 17:24
  • Okay I see. and yes, I am coding on Eclipse. Would you suggest any other tools for web development? thanks a lot! – yla Oct 03 '13 at 17:31
  • Just finetune Eclipse as detailed in the bottom of this answer: http://stackoverflow.com/questions/17167377/jsf-checkbox-listener/17170220#17170220 – BalusC Oct 03 '13 at 17:34

0 Answers0