0 Replies Latest reply on Apr 24, 2008 12:52 AM by darthmaul

    Simultaneous Ajax Hibernate Validation And Rerendering

    darthmaul

      I have a class called OrderItem which is annotated on its units property with Hibernate Validator as follows:



      @Entity
      @Table(name = "ORDER_ITEM")
      public class OrderItem {
      .
      .
      .
      
         @Column(name = "UNITS", nullable = false)
         @NotNull
         @Min(value=1, message = "Need 1 or more units for each item.")
         public BigInteger getUnits() {
            return units;
         }
      .
      .
      .
      }
      



      Meanwhile, on the front end I have a table of these OrderItems, and the units property is editable in a text box.  When the text box is updated, I want either of the following to happen:




      1. Make sure the value in the text box is greater than 1 and if not display a faces message

      2. If the value is valid, then update two other parts of the table that contain totals.



      Here is the portion of my facelet that describes this:



      <rich:column>
                  <th type="text" jsfc="h:inputText" value="#{orderItem.units}" id="unitsBox">
                     <s:validate/>
                     <a4j:support event="onblur" reRender="unitsBox,orderItemTotal,orderTotal" />
                  </th>
      </rich:column>
      



      The totals get updated just fine with a valid value.  However, when the value is invalid, nothing happens.  Not until I do a conventional submit and return immediately to this page do I see the faces message specified in Hibernate Validator on the OrderItem entity.


      How can I get the validation done Ajax-ly along with the totals?


      Thanks.