6 Replies Latest reply on Sep 17, 2006 6:05 PM by Pete Muir

    validation not performed after submit

    Kurt Edegger Newbie


      I do have an entity bean named user, which I do access directly from a xhtml page. On some properties of the bean are validator tags and all input fields in the xhtml page are surrounded by a <s:validateAll> tag.
      When the page is rendered and the input fields are left untouched, the action method is called after a submit without getting any validation errors.
      If some data is entered in the input fileds, but validation still fails (e.g. username too short) validation errors are displayed and the action method won't be called.
      The latter behaviour is the expected one, but why won't the validation fail, if the input fields are left blank? Each property of the entity bean is tagged with a @NotNull and @Length(min= 2).

      To examplify the code of the entity bean:

      public class User1A6 implements Serializable {
       private static final long serialVersionUID = 871185599785223310L;
       private String username;
       private String password;
       private Log log = LogFactory.getLog(User1A6.class);
       public User1A6() {
       log.debug("===== User1A6 constructor");
       @Length(min = 3, max = 15)
       public String getPassword() {
       log.info("===== User1A6.getPassword called");
       return password;
       public void setPassword(String password) {
       log.info("===== User1A6.setPassword called: " + password);
       this.password = password;
       @Length(min = 2, max = 100)
       @Pattern(regex = "^\\w*$", message = "not a valid username")
       public String getUsername() {
       log.info("===== User1A6.getUsername called");
       return username;
       public void setUsername(String username) {
       log.info("===== User1A6.setUsername called: " + username);
       this.username = username;

      and the interesting part of the xhtml page:

       <h:outputText value="#{messages['home.LoginUsername.Label']}"/>
       <h:inputText id="username" value="#{user.username}"/>
       <h:message for="username" />
       <h:outputText value="#{messages['home.LoginPassword.Label']}"/>
       <h:inputSecret id="password" value="#{user.password}"/>
       <h:message for="password" />
       <div align="center">
       <h:commandButton styleClass="formButton" action="#{portal.login}" value="Enter portal"/>
       <s:link action="#{user.frontendLog}" value="Frontend Log" linkStyle="button"/>
       <h:messages showDetails="true" showSummary="true" />

      Do I miss something here? Thanks for the answers in advance,