lundi 4 mai 2015

JSF Form Validation getting stuck

I have two fields on a form that are cross validated. Initially the user see this:

enter image description here

<p:inputText size="5" 
  value="#{bean.maximum_hole_diameter}">
  <f:validator validatorId="doubleNotLessThanSecondDouble" />
  <f:attribute name="secondDouble" 
    value="#{bean.minimum_hole_diameter}" />
  <p:ajax event="change" update="@this" />
</p:inputText>

<p:inputText size="5" 
  value="#{bean.minimum_hole_diameter}">
  <f:validator validatorId="doubleNotGreaterThanSecondDouble" />
  <f:attribute name="secondDouble"
    value="#{bean.maximum_hole_diameter}" />
  <p:ajax event="change" update="@this" />
</p:inputText>

Everything works as expected IF the user enters a positive value for the maximum first and then a lesser value for the minimum.

If they enter the minimum first that gets flagged as invalid:

enter image description here

So far so good - 2 is larger than 0.0. Intuitively, the user would then put in a maximum hole diameter, which is larger than the minimum. But the form get's stuck. The minimum is still invalid because technically in the model it is still 0.0. Ajax never stored the value 2 in the model but the browser still shows the value 2. How can I get the 2 to get revalidated and stored in my bean??

enter image description here

I could do a update="@form" to clear the 2 value back to zero but this would frustrate the user. And if the user retypes 2, the form doesn't get submitted, because the it hasn't "changed". The user has to change to another number then go back to 2. Doing "onblur" has its issues too.

How can I get the value 2 to get resubmitted and revalidated when the user enters the 3?

Aucun commentaire:

Enregistrer un commentaire