[jboss-user] [JBoss Seam] - Re: Seam form submission errors

jbrosan do-not-reply at jboss.com
Fri Jul 13 18:02:42 EDT 2007


It seems that I have all of the data from the form and that its crashing on the em.persist(user) line. I'm not sure why though.

UserModifyActionImpl.java


  | package org.bigbadwolf.core.component;
  | 
  | import java.util.List;
  | 
  | import javax.ejb.Stateless;
  | import javax.persistence.EntityManager;
  | import javax.persistence.PersistenceContext;
  | 
  | import org.jboss.seam.annotations.In;
  | import org.jboss.seam.faces.FacesMessages;
  | import org.jboss.seam.annotations.Name;
  | 
  | import org.bigbadwolf.core.model.security.UserImpl;
  | 
  | @Stateless
  | @Name("usermodifyaction")
  | public class UserModifyActionImpl implements UserModifyAction {
  | 
  | 	@In(create=true)
  | 	private UserImpl user;
  | 	
  | 	@PersistenceContext
  | 	private EntityManager em;
  | 	
  | 	
  | 	public String addUser()
  | 	{
  | 	      List existing = em.createQuery("select userName from UserImpl u where userName=:userName").setParameter("userName", user.getUserName()).getResultList();
  | 	      
  | 	      if (existing.size()==0)
  | 	      {
  | 	
  | 	        em.persist(this.user);
  | 	        //log.info("Registered new user #{user.username}");                               
  | 	         return "/admin/user/userlist.xhtml";                                                       
  | 	      }
  |         else
  | 	      {
  | 	         FacesMessages.instance().add("User #{user.userName} already exists");          
  | 	         return null;
  | 	      }
  | 	}
  | }
  | 
  | 

UserImpl.java


  | package org.bigbadwolf.core.model.security;
  | 
  | import java.util.ArrayList;
  | import java.util.Date;
  | import java.util.HashSet;
  | import java.util.List;
  | import java.util.Set;
  | 
  | import javax.annotation.security.RolesAllowed;
  | import javax.persistence.CascadeType;
  | import javax.persistence.Column;
  | import javax.persistence.Entity;
  | import javax.persistence.FetchType;
  | import javax.persistence.GeneratedValue;
  | import javax.persistence.GenerationType;
  | import javax.persistence.Id;
  | import javax.persistence.JoinColumn;
  | import javax.persistence.JoinTable;
  | import javax.persistence.ManyToMany;
  | import javax.persistence.OrderBy;
  | import javax.persistence.Table;
  | 
  | import org.apache.commons.lang.RandomStringUtils;
  | import org.bigbadwolf.core.Globals;
  | import org.hibernate.validator.Email;
  | import org.hibernate.validator.Length;
  | import org.hibernate.validator.NotNull;
  | import org.jboss.seam.ScopeType;
  | import org.jboss.seam.annotations.Name;
  | import org.jboss.seam.annotations.Scope;
  | 
  | @Entity
  | @Table(name = "Users")
  | @Name("user")
  | @Scope(ScopeType.SESSION)
  | public class UserImpl implements User
  | {
  | 
  | 	private static final long serialVersionUID = 5927788462600388688L;
  | 
  |     
  |     @ManyToMany(fetch = FetchType.LAZY, cascade = { CascadeType.MERGE })
  |     @JoinTable(name = "UsersToRoles", inverseJoinColumns = { @JoinColumn(name = "role_id", referencedColumnName = "id") }, joinColumns = { @JoinColumn(name = "user_id", referencedColumnName = "id") })
  |     @OrderBy("name")
  | 	protected List<RoleImpl> roles;
  |     
  | 	@Id
  | 	@Column(name = "id", columnDefinition = "bigint")	
  | 	@GeneratedValue(strategy=GenerationType.AUTO)
  |     protected Integer id;
  | 	
  | 	@Column(name = "first_name")
  |     protected String firstName;
  | 	
  |     @Column(name = "last_name")
  |     protected String lastName;
  |     
  | 	@Column(name = "password")
  |     protected String password;
  | 	
  |     @Column(name = "email")
  |     @Email
  |     protected String email;
  |     
  |     @Column(name = "username")
  |     protected String userName;
  |     
  |     @Column(name = "last_visit")
  |     protected Date lastVisit;   
  | 
  |     
  |     public UserImpl()
  |     {
  |     }    
  |     public UserImpl(String firstName, String lastName, String password, String email, String userName)
  |     {
  |        this.firstName = firstName;
  |        this.lastName = lastName;
  |        this.password = password;
  |        this.email = email;
  |        this.userName = userName;
  |     }
  |     
  |     @RolesAllowed("administrator")
  |     public String getPassword()
  |     {
  |         return password;
  |     }
  |     
  |     @NotNull
  |     @Length(min=3, max=15)    
  |     public void setPassword(String password)
  |     {
  |         this.password = password;
  |     }
  |     
  | 
  |     public Set<String> getRoleNames()
  |     {
  |         Set<String> roleNames = new HashSet<String>();
  |         List<RoleImpl> roles = getRoles();
  |         for (RoleImpl role : roles)
  |         {
  |             roleNames.add(role.getName());
  |         }
  |         return roleNames;
  |     }    
  |     
  |     public boolean addRoles(List<Role> roles)
  |     {
  |         if (addRoles(roles))
  |         {
  |             return true;
  |         }
  |         return false;
  |     }
  |     public boolean removeRoles(List<Role> roles)
  |     {
  |         if (removeRoles(roles))
  |         {
  |             return true;
  |         }
  |         return false;
  |     }
  | 
  |     @RolesAllowed("administrator")
  |     public void setEmail(String email)
  |     {
  |      
  |             if (!email.matches(Globals.EMAIL_PATTERN))
  |             {
  |                 //throw new ValidationException("Invalid email.", Severity.ERROR);
  |             }
  | 
  |         this.email = email;
  |     }
  |     
  |     @RolesAllowed("administrator")
  |     @Length(min=5, max=15)
  |     public void setFirstName(String firstName)
  |     {
  |         this.firstName = firstName;
  |     }
  |     @RolesAllowed("administrator")
  |     @Length(min=3, max=20)
  |     public void setLastName(String lastName)
  |     {
  |        this.lastName = lastName;
  |     }
  |     
  |     @RolesAllowed("administrator")
  |     @NotNull
  |     @Length(min=5, max=15)
  |     public void setUserName(String userName)
  |     {
  |       this.userName = userName;
  |     }
  |     public boolean isInRole(String roleName)
  |     {
  | //        Map<String, Object> parameters = new HashMap<String, Object>();
  | //        parameters.put("id", getId());
  | //        parameters.put("roleName", roleName);
  | //        String returnedRoleName = (String) getQueryService().singleResultNamedQuery(new StringBuffer(PersonImpl.class.getName())
  | //                .append(".isInRole").toString(), parameters);
  | //        if (returnedRoleName != null && returnedRoleName.equals(roleName))
  | //        {
  | //            return true;
  | //        }
  |         return false;
  |     }
  | //    public static UserImpl createNew()
  | //    {
  | //        UserImpl user = new UserImpl();
  | //        user.setPassword(RandomStringUtils.randomAlphanumeric(6).toLowerCase());
  | //        return user;
  | //    }
  |     public String getName()
  |     {
  |         return userName;
  |     } 
  |     public List<RoleImpl> getRoles()
  |     {
  |         if (roles == null)
  |         {
  |             roles = new ArrayList<RoleImpl>();
  |         }
  |         return roles;
  |     }
  | 
  | 
  | 	public String getEmail() {
  | 		return email;
  | 	}
  | 
  | 	public String getFirstName() {
  | 		return firstName;
  | 	}
  | 
  | 	public String getLastName() {
  | 		return lastName;
  | 	}
  | 
  | 	public String getUserName() {
  | 		return userName;
  | 	}   
  |     public void generateNewPassword(Integer size)
  |     {
  |         setPassword(RandomStringUtils.randomAlphanumeric(size).toLowerCase());
  |     }
  |     public Date getLastVisit()
  |     {
  |         return lastVisit;
  |     }
  |     public void setLastVisit(Date lastVisit)
  |     {
  |         this.lastVisit = lastVisit;
  |     }
  | 	public String getCreationId() {
  | 		// TODO Auto-generated method stub
  | 		return null;
  | 	}
  | 	public Integer getId() {
  | 		// TODO Auto-generated method stub
  | 		return null;
  | 	}
  | 
  | }
  | 

Any suggestions on what is could be causing this and/or suggested fix would be most welcome.

Thanks,
John

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

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



More information about the jboss-user mailing list