0

i have a little problem with the code below. We have to use booleancheckboxes and we have 12 of them as you can see it in the code. I would like to make a validator so the user has to select one of them atleast but it is not so easy because all of the checkboxes are individual and i also can't give them ID-s because of loop. What would be the proper way to validate it, or how is it even possible.

<rich:dataGrid id="checkboxes" value="#{MonitorBean.signalingOptions}" var="Signal" columns="3" elements="12" first="0">
                        <f:facet name="header">
                            <h:outputText value="Signaling options"></h:outputText>
                        </f:facet>

                        <rich:panel bodyClass="pbody">
                            <h:panelGrid columns="2">
                                <h:selectBooleanCheckbox value="#{Signal.toMonitor}"  required="true" disabled="enabled">
                                <!--<f:validator validatorId="util.CheckboxValidator" />-->
                                    <h:message for="checkboxes" styleClass="errors"/>
                                </h:selectBooleanCheckbox>

                                <h:outputText value="#{Signal.signalName}"></h:outputText>                        
                         </h:panelGrid>                    
                        </rich:panel>                  
                    </rich:dataGrid>  

Thanks for the help!

erik.c
  • 1,342
  • 2
  • 15
  • 27

1 Answers1

0

You need a validator which checks all the fields (which again are mapped to some field in your handler code). Maybe this answer helps.

Community
  • 1
  • 1
Alexander Rühl
  • 6,769
  • 9
  • 53
  • 96
  • I dont think that works because i cant give my checkboxes name and attribute one by one because they are generated by a loop or not? – erik.c Jun 03 '13 at 11:29
  • @enricko You don't need to specify ids, but of course you need to map the components to a member in Java code (which you for sure have done already, if you use the user input). See [this](http://www.andygibson.net/blog/tutorial/binding-dynamic-multi-select-checkboxes-with-jsf/) for example. – Alexander Rühl Jun 03 '13 at 12:35
  • Yeah but the jsf validation part happens before the component would be written to the map so i can't use the handler code or i just don't get it by the examples how would it be possible with a validator class. – erik.c Jun 04 '13 at 07:23
  • @enricko I see, well then you may be able to assign ids to your dynamically created components and validate them like shown [here](http://stackoverflow.com/questions/16776668/omnifaces-ovalidateallornone-in-uirepeat-or-hdatatable) – Alexander Rühl Jun 04 '13 at 09:00