1 Reply Latest reply on Jun 17, 2008 12:59 AM by admin.admin.email.tld

    form validation best practices in Seam

    admin.admin.email.tld

      Seam 2.0.1.GA
      RF 3.2.0.SR1


      having some issues with clearing and re-setting focus for fields after dynamic (AJAX/RF onblur) validation fails.


      generally, should we validate entries to forms dynamically, upon submit, or both?  or does it depend on the scenario/usecase?


      For example, say a user enters a serialNo (12345) and tabs out of that field.  onblur event fires for a4j:support component and a method is called on SFSB that checks for duplicates.  Validation fails b/c that serialNo already exists in the table, method sets appropriate message for facesMessages.


      Now what as far as UI is concerned?  display message, perhaps highlight field, move to the next field in the tab order?


      or clear the bad field, and set focus there again and display 12345 as part of the validation error msg so user is not confused.


      or don't do AJAX/RF validation at all, and validate all serialNo's for all rows after user clicks submit button?


      I'm actually disabling the submit button until the error is fixed, etc.  Not sure if that's too much or what.


      This is a simple example (only 1 record gets inserted I supposed):


      http://seam.demo.jboss.com/book.seam


      and seems to not validate dynamically.


      This question pertains to Hibernate Validators as well in the entity classes.  But it can involve database queries as in the duplicate example as well.


      So what to do generally???

        • 1. Re: form validation best practices in Seam
          admin.admin.email.tld

          http://demo.flamingo.exadel.com/booking/book.seam


          seems to be validating onblur event...


          so the edit.xhtml has a

          <s:validateAll>

          in it.  The hibernate validators are fired by


          <a:support event="onblur" reRender="creditCardDecorate"/>



          there is some additional validation in the SFSB method:


          public void setBookingDetails()
             {
                Calendar calendar = Calendar.getInstance();
                calendar.add(Calendar.DAY_OF_MONTH, -1);
                if ( booking.getCheckinDate().before( calendar.getTime() ) )
                {
                   facesMessages.addToControl("checkinDate", "Check in date must be a future date");
                   bookingValid=false;
                }
                else if ( !booking.getCheckinDate().before( booking.getCheckoutDate() ) )
                {
                   facesMessages.addToControl("checkoutDate", "Check out date must be later than check in date");
                   bookingValid=false;
                }
                else
                {
                   bookingValid=true;
                }
             }



          the bookingValid boolean variable is accessed in pages.xml for page navigation to the confirm page.


          So basically, this form in the booking example is using both dynamic and on submit validation.