[jboss-user] [JBoss Seam] - Validation throws an exception instead of redisplaying the p

gaboo do-not-reply at jboss.com
Thu Jun 21 10:38:42 EDT 2007


Here is the page :

<!DOCTYPE composition 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:f="http://java.sun.com/jsf/core"
  |                 xmlns:h="http://java.sun.com/jsf/html"
  |                 xmlns:rich="http://richfaces.ajax4jsf.org/rich"
  |                 template="../layout/template.xhtml">
  | 
  | <ui:define name="body">
  |     
  |     <h:messages styleClass="message"/>
  |     
  |     <ui:include src="usersMenu.xhtml"/>
  |     
  |     <h:form>
  |     
  |     	<s:validateAll>
  |     
  | 		<f:facet name="aroundInvalidField">
  |         	<s:span styleClass="errors"/>
  |         </f:facet>
  |         <f:facet name="afterInvalidField">
  |             <s:span> <s:message/></s:span>
  |         </f:facet>
  | 		
  | 		<s:decorate>#{messages['lrb.user.id']} <h:inputText id="id" value="#{user.id}"/></s:decorate><br/>
  | 		<s:decorate>#{messages['lrb.user.username']} <h:inputText id="username" value="#{user.username}"/></s:decorate><br/>
  |         <s:decorate>#{messages['lrb.user.password']} <h:inputText id="password" value="#{user.password}"/></s:decorate><br/>
  |         <s:decorate>#{messages['lrb.user.email']} <h:inputText id="email" value="#{user.email}"/></s:decorate>
  |         				
  | 		</s:validateAll>
  | 	
  | 		<!-- actions -->
  |         <div class="actionButtons">
  |         
  |           <s:link view="/admin/users.xhtml" value="#{messages['lrb.cancel']}"/>
  |           <h:outputText value=" "/>
  |           <h:commandLink action="#{userHome.update}" value="#{messages['lrb.update']}" rendered="#{userHome.managed}"/>
  |           <h:outputText value=" "/>
  |           <s:link action="#{userHome.remove}" value="#{messages['lrb.delete']}" rendered="#{userHome.managed}"/>
  |           <h:outputText value=" "/>
  |           <h:commandLink action="#{userHome.persist}" value="#{messages['lrb.create']}" rendered="#{!userHome.managed}"/>
  | 
  |         </div>
  | 	</h:form>
  | 
  |  </ui:define> 
  | </ui:composition>

the entity in components.xml :
<factory name="user" value="#{userHome.instance}"/>
  |     <fwk:entity-home name="userHome" 
  |              entity-class="com.lrb.metabook.User"
  |              new-instance="#{newUser}"/>
  |     
  |    <component name="newUser" class="com.lrb.metabook.User"/>
  |    
  |    <fwk:entity-query name="users"
  |                max-results="5">
  |         <fwk:ejbql>from User</fwk:ejbql>
  |         <fwk:order>id</fwk:order>
  |     </fwk:entity-query>

The thing is that if I add required="true" to each h:inputText, it works as expected, but do not follow annotated validation.

Here is the entity bean :

package com.lrb.metabook;
  | 
  | // Generated 10 juin 2007 20:21:17 by Hibernate Tools 3.2.0.b9
  | 
  | import java.util.Iterator;
  | 
  | /**
  |  * User generated by hbm2java
  |  */
  | @Entity
  | public class User implements java.io.Serializable {
  | 
  | 	private long id;
  | 
  | 	private String password;
  | 
  | 	private String username;
  | 
  | 	private List<Role> roles;
  | 
  | 	private String email;
  | 
  | 	public User() {
  | 	}
  | 
  | 	public User(long id, String password, String username) {
  | 		this.id = id;
  | 		this.password = password;
  | 		this.username = username;
  | 	}
  | 
  | 	@Id
  | 	@GeneratedValue
  | 	public long getId() {
  | 		return this.id;
  | 	}
  | 
  | 	public void setId(long id) {
  | 		this.id = id;
  | 	}
  | 
  | 	@NotNull
  | 	@Length(min = 1, max = 20)
  | 	public String getPassword() {
  | 		return this.password;
  | 	}
  | 
  | 	public void setPassword(String password) {
  | 		this.password = password;
  | 	}
  | 
  | 	@NotNull
  | 	@Length(min = 1, max = 20)
  | 	public String getUsername() {
  | 		return this.username;
  | 	}
  | 
  | 	public void setUsername(String username) {
  | 		this.username = username;
  | 	}
  | 
  | 	@ManyToMany
  | 	public List<Role> getRoles() {
  | 		return roles;
  | 	}
  | 
  | 	private void setRoles(List<Role> roles) {
  | 		this.roles = roles;
  | 	}
  | 
  | 	/**
  | 	 * @return roles list
  | 	 */
  | 	public String rolesList() {
  | 
  | 		if (roles != null) {
  | 			StringBuffer sb = new StringBuffer();
  | 			for (Iterator iter = roles.iterator(); iter.hasNext();) {
  | 				Role role = (Role) iter.next();
  | 				sb.append(role.getName() + " ");
  | 			}
  | 			return sb.toString();
  | 		}
  | 		return "";
  | 	}
  | 
  | 	@NotNull
  | 	@Email
  | 	public String getEmail() {
  | 		return email;
  | 	}
  | 
  | 	public void setEmail(String email) {
  | 		this.email = email;
  | 	}
  | 
  | }
  | 

I'm using seam 1.3.0ALPHA

Any idea ?

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4056532#4056532

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4056532



More information about the jboss-user mailing list