PavanSandeep
PavanSandeep

Reputation: 214

How to validate a List<Object> in a Primefaces dataTable - JSF

I have a dataTable for Phone something like :

<p:dataTable value="#{billingInfoBean.billingProfile.payer.phones}" var="phone" id="payerPhoneTable">

    <p:column>
        <f:facet name="header">
            <h:outputText value="Type" />
        </f:facet>
        <p:selectOneMenu value="#{phone.type}">
            <f:selectItem itemLabel="" itemValue="" />
            <f:selectItems value="#{backOfficeLookupClient.allPhoneTypes}" />
        </p:selectOneMenu>
    </p:column>

    <p:column>
        <f:facet name="header">
            <h:outputText value="Area Code" />
        </f:facet>
        <h:inputText value="#{phone.areaCode}" size="3" maxlength="3" />
    </p:column>

    <p:column>
        <f:facet name="header">
            <h:outputText value="Exchange" />
        </f:facet>
        <h:inputText value="#{phone.exchange}" size="3" maxlength="3" />
    </p:column>

    <p:column>
        <f:facet name="header">
            <h:outputText value="Local" />
        </f:facet>
        <h:inputText value="#{phone.local}" size="4" maxlength="4" />
    </p:column>

    <p:column>
        <f:facet name="header">
            <h:outputText value="Extension" />
        </f:facet>
        <h:inputText value="#{phone.extension}" size="5" maxlength="5" />
    </p:column>
</p:dataTable>

I am trying to use custom validation using the object Phone. I need to call a Phone Validation service which takes these column values as inputs. Can I make use of <f:validator> here in this case?, If yes, how ?

Upvotes: 2

Views: 6212

Answers (2)

PavanSandeep
PavanSandeep

Reputation: 214

This omnifaces tag solved my problem :

http://showcase.omnifaces.org/validators/validateMultiple

Upvotes: 2

StarsSky
StarsSky

Reputation: 6711

You could attach to the dataTable a validator listener

<f:event type="postValidate" listener="#{bean.customValidation}"/>

And validate the phone object in your bean

public void customValidation(ComponentSystemEvent event) {
    ...
}

Then iterate through all dataTable childrens and validate each one.

Here ther's a good tutorial to start with.

Upvotes: 2

Related Questions