2 Replies Latest reply on Sep 27, 2009 9:10 AM by Pieter Martin

    JSF and JPA

    Pieter Martin Novice

      Hi,


      I am using Web Beans 1.0.0 preview1 and JSF2.


      Following on from the login example I am trying to expose the user JPA entity directly to a jsf page.
      i.e. I do not want to reference the entity via some other WebBean.


      Previously in Seam all that was required was an @Out and voila the entity was available on a jsf page with el.


      I am struggling now to get the same right with @Produces.



      @SessionScoped
      @Named
      public class LoginController implements Serializable {
          private User user;
          public void login() {
           List<User> results = em
                     .createQuery(
                          "select u from User u where u.username=:username and u.password=:password")
                     .setParameter("username", credentials.getUsername())
                     .setParameter("password", credentials.getPassword())
                     .getResultList();
           if (!results.isEmpty()) {
               conversation.begin();
               user = results.get(0);
               FacesContext.getCurrentInstance().addMessage(null,
               new FacesMessage("Welcome, " + user.getName()));
           }
          }
          ...
          @Produces
          @NakedUser
          public User getUser() {
              return user;
          }
          public void setUser(User user) {
              this.user = user;
          }
      }
      


      On the jsf page then


      <h:outputText value="#{user.username}"/>



      The User class has a


      @Named("user") @ConversationScoped



      Somehow I think I am misunderstanding how this is suppose to work.


      Any help appreciated


      Thanks


      Pieter