3 Replies Latest reply on Apr 18, 2011 4:31 PM by Hai-Yun Du

    Validation for inplaceInput

    Hai-Yun Du Newbie

      What is the proper way to validate an inplaceInput using Hibernate validation on the bound entity bean. I tried to use Seam's s:validateAll on it but it does not seem to work: the error message does not display after clicking save (the green check mark icon); instead the incorrect value is displayed in view mode (in this case the input exceeds 40 characters), but is not actually updated to the database.

       

      <s:validateAll>
          <rich:inplaceInput id="inplaceInput" value="#{person.name}"/>
          <s:span rendered="#{invalid}">
              <h:message for="inplaceInput" styleClass="errors" />
          </s:span>
      </s:validateAll>
      
      @Entity
      @Table(name="PERSON")
      class Person {
           private String name;
      
           @Column(name="NAME", length=40)
           @Length(max=40)
           public String getName() {
                return name;
           }
           ...
      }
      
        • 1. Validation for inplaceInput
          Ilya Shaikovsky Master

          change h: to rich:message

          if not helps try rich:beanValidator in inplace.

           

          and if will not resolve please show complete form code inclusing controls.

          • 2. Validation for inplaceInput
            Hai-Yun Du Newbie

            Thanks for your reply, Ilya.

             

            Actually, the problem was that I needed to reRender the region around the inplaceInput upon clicking save. That redisplayed the h:message with the error.

            • 3. Re: Validation for inplaceInput
              Hai-Yun Du Newbie

              I have a similar problem with an inplaceInput inside a dataTable. It seems to skip the PROCESS_VALIDATIONS phase and fails on the INVOKE_APPLICATION phase when performing the action personPage.save which calls personHome.update to update the person.contacts collection. The validation works fine on a non-collection field outside a dataTable, i.e. person.name

               

              contact.xhtml

               

              <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
              
              "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
              <ui:composition xmlns="http://www.w3.org/1999/xhtml"
                              xmlns:s="http://jboss.com/products/seam/taglib"
                              xmlns:ui="http://java.sun.com/jsf/facelets"
                              xmlns:h="http://java.sun.com/jsf/html"
                              xmlns:rich="http://richfaces.org/rich"
                              xmlns:a4j="http://richfaces.org/a4j"
                              template="/layout/template.xhtml">
              
              <ui:define name="body">
              
              <a4j:form>
              
                  <s:validateAll>
              
                  <s:decorate id="name" template="/layout/display.xhtml">
                      <ui:define name="label">Name</ui:define>
                      <s:span styleClass="#{invalid ? 'errors' : ''}">
                          <rich:inplaceInput id="commonNameInput"
                              value="#{personHome.instance.name}"
                              showControls="true"
                              reRender="name"
                              minInputWidth="180px">
                              <a4j:support event="onviewactivated"
                                  reRender="name"
                                  action="#{personPage.save}"/>
                          </rich:inplaceInput>
                      </s:span>
                      <s:span rendered="#{invalid}" styleClass="error">
                          <h:message for="nameInput" styleClass="errors" />
                      </s:span>
                  </s:decorate>
              
                  <rich:dataTable id="contacts" var="_contact" value="#{personPage.contacts}" 
                        rendered="#{personPage.contacts.size > 0}">
                      <h:column>
                          <s:decorate id="contactName" template="/layout/display.xhtml">
                              <ui:define name="label">Contact name</ui:define>
                              <rich:inplaceInput id="contactNameInput"
                                  value="#{_contact.name}"
                                  showControls="true"
                                  reRender="contactName"
                                  minInputWidth="180px">
                                  <a4j:support event="onviewactivated"
                                      reRender="contactName"
                                      action="#{personPage.save}"/>
                              </rich:inplaceInput>
                              <s:span rendered="#{invalid}" styleClass="error">
                                  <h:message for="contactNameInput" styleClass="errors" />
                              </s:span>
                          </s:decorate>
                      </h:column>
                  </rich:dataTable>
              
                  </s:validateAll>
              
              </a4j:form>
              </ui:define>
              
              </ui:composition>
              
              
              

               

              display.xhtml

               

              <ui:composition  xmlns="http://www.w3.org/1999/xhtml"
                               xmlns:ui="http://java.sun.com/jsf/facelets"
                               xmlns:h="http://java.sun.com/jsf/html"
                               xmlns:f="http://java.sun.com/jsf/core"
                               xmlns:s="http://jboss.com/products/seam/taglib">
              
                  <div class="prop">
                      <span class="name#{invalid ? ' errors' : ''}">
                          <ui:insert name="label"/>
                      </span>        <span class="value">
                          <ui:insert/>
                      </span>
                  </div>
              
              </ui:composition>
              

               

              Person.java

               

              @Entity
              @Table(name = "PERSON")
              public class Person {
                   private String name; 
                   private Set<Contact> contacts = new LinkedHashSet<Contact>(0);
              
                  @Column(name = "NAME", length = 32)
                  @Length(max = 32)
                  public String getName() {
                      return this.name;
                  }
              
                  @OneToMany(fetch = FetchType.LAZY, mappedBy = "person")
                  public Set<Contact> getContacts() {
                      return this.contacts;
                  }
                   ...
              }
              

               

              Contact.java

               

              @Entity
              @Table(name = "CONTACT")
              public class Contact {
                   private String name; 
              
                  @Column(name = "NAME", length = 32)
                  @Length(max = 32)
                  public String getName() {
                      return this.name;
                  }
               }
              

               

              Error:

              15:43:44,769 SEVERE [application] hdu org.hibernate.validator.InvalidStateException: validation failed for: ca.theCompany.model.Contact
              javax.faces.el.EvaluationException: org.hibernate.validator.InvalidStateException: validation failed for: ca.theCompany.model.Contact
                  at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:102)
                  at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
                  at javax.faces.component.UICommand.broadcast(UICommand.java:387)
                  etc...