[JBoss Seam] - Re: Problem with injection @In
by luiz.sg
"swd847" wrote : Are you referring to the booking example?
|
| The reason why it works in the example is because of this little bit of code in the AuthenticatorBean:
|
| @Out(required=false, scope = SESSION)
| private User user;
|
| when a user logs in the user entity is outjected to session scope, allowing it be used by other beans. When you think about it it makes sense that an exception is thrown, how can you inject the current user if they have not logged in yet?
|
| @In without create=true is basically saying that you want an initialized User injected, with create=true you are saying that you do not care if it has been initialized or not, you just want a user.
Ok. It makes sense now...
Tanks for the explanation.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4091813#4091813
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4091813
18Â years, 6Â months
[JBoss Seam] - Re: Problem with injection @In
by luiz.sg
"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
18Â years, 6Â months