[jboss-user] [JBoss Seam] - Re: Problem with injection @In

luiz.sg do-not-reply at jboss.com
Fri Oct 5 00:48:10 EDT 2007


"matt.drees" wrote : Which part of the hibernate example are you referring to? 

This one:


  | @Entity
  | @Name("user")
  | @Scope(SESSION)
  | @Table(name="Users")
  | public class User implements Serializable
  | {
  |    private String username;
  |    private String password;
  |    private String name;
  |    
  |    public User(String name, String password, String username)
  |    {
  |       this.name = name;
  |       this.password = password;
  |       this.username = username;
  |    }
  |    
  |    public User() {}
  | 
  |    @NotNull
  |    @Length(max=100)
  |    public String getName()
  |    {
  |       return name;
  |    }
  |    public void setName(String name)
  |    {
  |       this.name = name;
  |    }
  |    
  |    @NotNull
  |    @Length(min=5, max=15)
  |    public String getPassword()
  |    {
  |       return password;
  |    }
  |    public void setPassword(String password)
  |    {
  |       this.password = password;
  |    }
  |    
  |    @Id
  |    @Length(min=5, max=15)
  |    public String getUsername()
  |    {
  |       return username;
  |    }
  |    public void setUsername(String username)
  |    {
  |       this.username = username;
  |    }
  |    
  |    @Override
  |    public String toString() 
  |    {
  |       return "User(" + username + ")";
  |    }
  | }
  | 

The POJO:


  | @Scope(SESSION)
  | @Name("bookingList")
  | public class BookingListAction implements Serializable
  | {
  |    @In
  |    private Session bookingDatabase;
  |    
  |    @In
  |    private User user;
  |    
  |    @DataModel
  |    private List<Booking> bookings;
  |    
  |    @DataModelSelection 
  |    private Booking booking;
  |    
  |    @Factory("bookings")
  |    public void find()
  |    {
  |       bookings = bookingDatabase.createQuery("from Booking b where b.user = :user order by b.checkinDate")
  |             .setParameter("user", user)
  |             .list();
  |    }
  |    
  |    public String cancel()
  |    {
  |       Booking cancelled = (Booking) bookingDatabase.get(Booking.class, booking.getId());
  |       if (cancelled!=null) bookingDatabase.delete( cancelled );
  |       refresh();
  |       return "cancelled";
  |    }
  |    
  |    public void refresh()
  |    {
  |       booking = null;
  |       find();
  |    }
  |       
  | }

Another one:

  | @Scope(EVENT)
  | @Name("register")
  | public class RegisterAction
  | {
  | 
  |    @In
  |    private User user;
  |    
  |    @In
  |    private Session bookingDatabase;
  |    
  |    @In
  |    private FacesMessages facesMessages;
  |    
  |    private String verify;
  |    
  |    public String register()
  |    {
  |       if ( user.getPassword().equals(verify) )
  |       {
  |          List existing = bookingDatabase.createQuery("select username from User where username=:username")
  |             .setParameter("username", user.getUsername())
  |             .list();
  |          if (existing.size()==0)
  |          {
  |             bookingDatabase.persist(user);
  |             return "login";
  |          }
  |          else
  |          {
  |             facesMessages.add("username already exists");
  |             return null;
  |          }
  |       }
  |       else 
  |       {
  |          facesMessages.add("re-enter your password");
  |          verify=null;
  |          return null;
  |       }
  |    }
  | 
  |    public String getVerify()
  |    {
  |       return verify;
  |    }
  | 
  |    public void setVerify(String verify)
  |    {
  |       this.verify = verify;
  |    }
  |    
  | }
  | 


I tried to put my components in the SESSION scope, lilke in the example, but still don't work.

Am I missing some configuration?

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

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



More information about the jboss-user mailing list