1
votes

I have a dataTable and when i edit it i want it to validate if assignedQuota >= usedQuota. How can i do that?

<p:dataTable id="vessels" var="ves" value="#{assignedVessels}" editable="true">
  <p:column>
        <p:cellEditor>  
            <f:facet name="output">
               <p:outputLabel value="#{ves.assignedQuota}"/>
            </f:facet>
            <f:facet name="input">
               <p:inputText value="#{ves.assignedQuota}" />
            </f:facet>
        </p:cellEditor>    
    </p:column>
    <p:column>
        <p:cellEditor>
            <f:facet name="output">
               <p:outputLabel value="#{ves.usedQuota}"/>
            </f:facet>
            <f:facet name="input">
               <p:inputText value="#{ves.usedQuota}" />
             </f:facet>
        </p:cellEditor>
   </p:column>
   <p:column>
      <p:rowEditor/> 
   </p:column>
2

2 Answers

3
votes

You can use ajax event, for example put:

<p:ajax event="rowEdit" listener="#{bean.onRowEdit}"/>

Into p:dataTable and in bean create follow method:

public void onRowEdit(RowEditEvent event) {
    // add you check here (assignedQuota >= usedQuota)
}

see also datatable edit example

0
votes

For a simple solution you could just check this condition in your controller. A more elegant way would be a custom constraint validator for your vessel bean. See hibernat doc for example.

The only trick here is that you have to create a validator for the bean (@Target({TYPE})), not for a single quota-value. Validators on members can't reference other members.