1
votes

I want to validate the below datatable only if user doesn't enter any values in the given p:inputText field

<p:dataTable id="depositDataTable" value="#{pc_intimationDeposit.pendingRep.depositeBeans}" var="deposit">
    <p:column style="text-align:right">
        <h:outputText value="#{deposit.depParticulars}" />
    </p:column>
   <p:column id="value">
        <h:inputText id="depositDetails" class="right_input" value="#{deposit.amnt}" tabindex="2"                                       converterMessage="Please Enter Numbner's Only" validatorMessage="please"> 
           <f:convertNumber  pattern="##,####,##0.00" for="depositDetails" type="currency" />
        </h:inputText>
<p:message id="errMsgDepositDetails" for="depositDetails" display="text"></p:message>   
    </p:column>
</p:dataTable>

pc_intimationDeposit.pendingRep.depositeBeans----> is a list(size 3) of depositBeans

i have used f:convertNumber for the entered values are correct to our requirements

but if user doesn't enter A SINGLE VALUE then i need validate for null check i.e., user has to enter any one field

and i need to display the error message on top of the datatable used

please help me Thank in you advance

1

1 Answers

1
votes
  • If you want to have every depositDetail inputs populated, mark them with required=true.
  • If you only want to have one of them filled, on your action method, iterate over your model to ensure there's at least one not empty (you shouldn't have null values here):

    boolean filled = false;
    for (DepositeBean dep : depositeBeans){
    if (!dep.getAmnt.equals("")){
        filled = true;
    }
    }
    if (!filled){
       FacesContext.getCurrentInstance().addMessage(null, 
         new FacesMessage(FacesMessage.SEVERITY_ERROR, "You have to fill at least one deposit detail field", null));
    }
    

For messages to be displayed, add an h:message tag and point it to your table:

<h:message for="depositDataTable" style="color:red" />