0

I have three inputs which require collective validation. Consider the following fudged example:

  1. packCapacity: A pack of pens can have a configurable capacity, i.e. 5, 10, etc
  2. generalAllowedBrokenPens: This is the number of pens generally allowed to be broken in a pack of pens. This number is 0 <= generalAllowedBrokenPens <= packCapacity
  3. 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:

  1. Set packCapacity to 20
  2. Set generalAllowedBrokenPens to 5
  3. Change packCapacity to 4
  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

user1638152
  • 577
  • 11
  • 23
  • Sure these basic things can work otherwise jsf in general would be useless. Start by removing `@this` in all the updates since it is superfluous ast is embeded in packcapacityinfo – Kukeltje May 16 '19 at 17:44
  • But if you expect the 5 to be automatically reduced to the new value of the max (4) no, that is afaik not happening. It might become invalid or it might not. I'd expect it to be and if that does not happen in the latest PF version it might be a valid improvement. You could try to add a `process` attribute to the first spinner to also process the second one (e.g. by giving it an id or doing a process of the packcapacityinfo , see https://stackoverflow.com/questions/25339056/understanding-primefaces-process-update-and-jsf-fajax-execute-render-attributes – Kukeltje May 16 '19 at 18:14

0 Answers0