You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Dario <ja...@yahoo.it> on 2008/03/14 16:58:56 UTC

Howto validate t:dataTable input fields

Hi all,
I'm quite new to this discussion list, and I found it very interesting. 
I'm sorry if the problem has been already discussed.

I have a dataTable with a checkbox on each row (an extract is below).
I'd like to create a custom validator that verifies that at least a 
checkbox in the list has been selected.
However, I cannot apply it directly on the h:selectBooleanCheckbox 
component, since it a "relationship validator". It seems it cannot be 
applied to t:dataTable, since it isn't an UIInput component (I'm not 
really sure about this).
I can perform the check directly in the action and generate a 
FacesMessage object, but this means that the check is after the Update 
Model Values phase, where I prefer it would be in the Process 
Validations phase.

Is there a correct way to approach this problem?
I'm using JSF 1.1.

Regards,
Dario

<t:dataTable value="#{lab.datas}" var="varData">
                <h:column id="sel">
                    <h:selectBooleanCheckbox id="checked1"
                        value="#{varData.checked}" />
                </h:column>
                
                <h:column id="person">
                    <h:outputLabel
                        value="#{varData.person}" for="checked1"/>
                </h:column>
</t:dataTable>
<h:commandButton type="submit" value="#{someAction}" />


Re: Howto validate t:dataTable input fields

Posted by Mike Kienenberger <mk...@gmail.com>.
Probably the way to do this is to create a custom validator, and put
it on a component (typically inputHidden) after the data table, and
have your validator iterate through the UIData components.

Here's some threads that have covered this issue to one degree or
another in the past:

http://mail-archives.apache.org/mod_mbox/myfaces-users/200608.mbox/%3c5597324.post@talk.nabble.com%3e

http://mail-archives.apache.org/mod_mbox/myfaces-users/200609.mbox/%3c6488960.post@talk.nabble.com%3e

http://markmail.org/message/beievnlwiet6lpqh


On 3/14/08, Dario <ja...@yahoo.it> wrote:
> Hi all,
>  I'm quite new to this discussion list, and I found it very interesting.
>  I'm sorry if the problem has been already discussed.
>
>  I have a dataTable with a checkbox on each row (an extract is below).
>  I'd like to create a custom validator that verifies that at least a
>  checkbox in the list has been selected.
>  However, I cannot apply it directly on the h:selectBooleanCheckbox
>  component, since it a "relationship validator". It seems it cannot be
>  applied to t:dataTable, since it isn't an UIInput component (I'm not
>  really sure about this).
>  I can perform the check directly in the action and generate a
>  FacesMessage object, but this means that the check is after the Update
>  Model Values phase, where I prefer it would be in the Process
>  Validations phase.
>
>  Is there a correct way to approach this problem?
>  I'm using JSF 1.1.
>
>  Regards,
>  Dario
>
>  <t:dataTable value="#{lab.datas}" var="varData">
>                 <h:column id="sel">
>                     <h:selectBooleanCheckbox id="checked1"
>                         value="#{varData.checked}" />
>                 </h:column>
>
>                 <h:column id="person">
>                     <h:outputLabel
>                         value="#{varData.person}" for="checked1"/>
>                 </h:column>
>  </t:dataTable>
>  <h:commandButton type="submit" value="#{someAction}" />
>
>