2 Replies Latest reply on Apr 7, 2009 9:31 AM by sandman202

    Bypassing validation on h:inputText

    sandman202

      I have a uzerList.xhtml which performs a search. The h:inputText search fields are performing validations defined on the properties from the uzer entity. Is there a way to bypass the validation?

      uzerList.xhtml

      <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:f="http://java.sun.com/jsf/core"
       xmlns:h="http://java.sun.com/jsf/html"
       xmlns:rich="http://richfaces.org/rich"
       template="/layout/template.xhtml">
      
      <ui:define name="body">
      
       <h:form id="uzerSearch" styleClass="edit">
      
       <rich:simpleTogglePanel label="User Search Parameters" switchType="ajax">
      
       ...
      
       <s:decorate template="/layout/display.xhtml">
       <ui:define name="label">Name</ui:define>
       <h:inputText id="name" value="#{uzerList.uzer.name}"/>
       </s:decorate>
      
       <s:decorate template="/layout/display.xhtml">
       <ui:define name="label">Email</ui:define>
       <h:inputText id="email" value="#{uzerList.uzer.email}" immediate="true" required="false"/>
       </s:decorate>
      
       ...
      
      
       </rich:simpleTogglePanel>
      
       <div class="actionButtons">
       <h:commandButton id="search" value="Search" action="/role/admin/UzerList.xhtml" />
       </div>
      
       </h:form>
       <rich:panel>
      
      ...
      
      
      </ui:define>
      
      </ui:composition>
      


      uzer.java
      @Entity
      public class Uzer implements Serializable
      {
      
      ...
       // seam-gen attributes (you should probably edit these)
       private Long id;
       private Integer version;
      
       // add additional entity attributes
       private String name;
       private String email;
      ...
      
       // seam-gen attribute getters/setters with annotations (you probably should
       // edit)
      
       @Id
       @GeneratedValue
       @Column(name = FIELD_ID)
       public Long getId() {
       return id;
       }
      
       public void setId(Long id) {
       this.id = id;
       }
      
       @Version
       @Column(name = FIELD_VERSION)
       public Integer getVersion() {
       return version;
       }
      
       @SuppressWarnings("unused")
       private void setVersion(Integer version) {
       this.version = version;
       }
      
      ...
      
       @Length(min=1, max = 40)
       @NotNull
       // @Pattern(regex = "[a-zA-Z]+", message =
       // "Last name must only contain letters")
       @Column(name = FIELD_NAME, nullable = false, length = 40)
       public String getName() {
       return name;
       }
      
       public void setName(String name) {
       this.name = name;
       }
      
       @Email
       //@NotNull
       @Column(name = FIELD_EMAIL)
       public String getEmail() {
       return email;
       }
      
       public void setEmail(String email) {
       this.email = email;
       }
      
      ...
      
      }
      


      When I press the search button on the xhtml, messages appear. One for the name field something like: "must be between 1 and 40" and one for the email with something like: "not a well formed email address". I do not want to validate on search parameters.

      How do I bypass this?


        • 1. Re: Bypassing validation on h:inputText
          ilya_shaikovsky

          remove immediate = true from inputs and add to button.

          • 2. Re: Bypassing validation on h:inputText
            sandman202

            Tried that. The messages are no longer showing, but when I try to search on email or name, the fields clear out and the search list does not change.

            I am using the searches similar to those described in "Seam in Action".

            uzerList.page.xml

             <param name="from"/>
             <param name="company" value="#{uzerList.uzer.company}"/>
             <param name="name" value="#{uzerList.uzer.name}"/>
             <param name="email" value="#{uzerList.uzer.email}"/>
             <param name="phone" value="#{uzerList.phone.phoneNumber}"/>
            


            uzerList.java
            @Name("uzerList")
            public class UzerList extends EntityQuery<Uzer>
            {
             private static final long serialVersionUID = -7220659451427306516L;
            
             private static final String[] RESTRICTIONS = {
             "lower(uzer.company) like concat('%',lower(#{uzerList.uzer.company}),'%')",
             "lower(uzer.name) like concat('%',lower(#{uzerList.uzer.name}),'%')",
             "lower(uzer.email) like concat('%',lower(#{uzerList.uzer.email}),'%')",
             "lower(phone.phoneNumber) like concat('%',lower(#{uzerList.phone.phoneNumber}),'%')",
             };
            
             private Uzer uzer = new Uzer();
             private Phone phone = new Phone();
            
             public UzerList() {
             this.setMaxResults(25);
             this.setEjbql("select uzer, phone from Uzer uzer join uzer.phones phone");
             this.setOrderColumn("uzer.name");
             this.setOrderDirection("asc");
             this.setRestrictionExpressionStrings(Arrays.asList(RESTRICTIONS));
             }
            
             public Uzer getUzer() {
             return uzer;
             }
            
             public Phone getPhone() {
             return phone;
             }
            
            }