• Post Reply Bookmark Topic Watch Topic
  • New Topic

Mandatory check for select boolean check box  RSS feed

 
prasad kolla
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

we are using trinidad tags in our application. I have a requirement where i need to do a requiredness validation if the user does not check a check box.

Normally when we specify required="true" for a input text or combobox. it shows a validatation message if the user does not enter a valid text or does not select any thing from the drop down.

Please find the below code snippet:

<tr:selectBooleanCheckbox id="offsiteInterview" required="true" selected="false"
label="#{msgs.input_label_checkBox}" autoSubmit="true"
value="#{captureBusinessEvidenceStep.isOffsiteInterview}"
requiredMessageDetail="option must be selected." />

Please suggest.
 
Bindesh Nair
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tried the same code, yes, required= true does not help, the form gets posted.

Consider using a java script instead.
 
prasad kolla
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I cannot use java script in my application. I have tried assigining a null value and check for required ness even then no luck. I need it this asap.
 
Bindesh Nair
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried the following with JSF1.2 Mojarra build and it worked for me.

The JSF code looks like this



And in the backing bean, I had the following code


[ September 19, 2008: Message edited by: Bindesh Nair ]
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The 'required' attribute of the selectBooleanCheckbox is indeed a bit ambiguous and non-intuitive.

It will only check if the checkbox has sent any value or not. It would only display the required message if the value is null. But an unchecked checkbox by default already sends 'false' to the server and not null. With other words, the 'required' attribute is fairly useless in case of a selectBooleanCheckbox.

If you want to display the required message when the user sends the value 'false', then you indeed need to create a validator yourself.

A more clean solution than the above proposed validator is this one. It handles validation as it should be and, above all, it makes use of the default required message:

Use it as follows:
You can of course also define it as a standalone Validator implementation with a validatorId in the faces-config.xml, so that you can reuse it on other pages which uses another backing beans.
[ September 19, 2008: Message edited by: Bauke Scholtz ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!