I have three inputs which require collective validation. Consider the following fudged example:
- packCapacity: A pack of pens can have a configurable capacity, i.e. 5, 10, etc
- generalAllowedBrokenPens: This is the number of pens generally allowed to be broken in a pack of pens. This number is 0 <= generalAllowedBrokenPens <= packCapacity
- maxAllowedBrokenPens: This is the maximum number of pens allowed to be broken in a pack of pens. This number is generalAllowedBrokenPens <= maxAllowedBrokenPens <= packCapacity.
In primefaces/JSF, I have something like the following:
<h:panelGrid id="packcapacityinfo" columns="2">
<h:outputText value="Capacity:"/>
<p:spinner value="#{penPackBackingBean.packCapacity}" min="1" max="50">
<p:ajax event="change" update="@this,packcapacityinfo"/>
</p:spinner>
<h:outputText value="Allowed Broken Pens:"/>
<p:spinner value="#{penPackBackingBean.generalAllowedBrokenPens}" min="0" max="#{penPackBackingBean.packCapacity}">
<p:ajax event="change" update="@this,packcapacityinfo"/>
</p:spinner>
<h:outputText value="Maximum Allowed Broken Pens:"/>
<p:spinner value="#{penPackBackingBean.maxAllowedBrokenPens}" min="#{penPackBackingBean.generalAllowedBrokenPens}" max="#{penPackBackingBean.packCapacity}">
<p:ajax event="change" update="@this,packcapacityinfo"/>
</p:spinner>
</h:panelGrid>
This halfway works, but the spinners do not update according to inputs. For example, if I do the following:
- Set packCapacity to 20
- Set generalAllowedBrokenPens to 5
- Change packCapacity to 4
- generalAllowedBrokenPens remains at value 5 and does not auto update to 4
Here is the main question:
Is there a way to do this kind of real time validation in Primefaces/JSF? If so, could somebody please detail the steps required, i.e. XHTML changes, backing bean changes, validators, etc.
Many thanks