primefaces, default loading, and jsf @conversation scope bean

advertisements

I am using primefaces 3.2 and mojarra 2.1.7 with jboss 6.1. I am trying to build a lazy loading datatable. In one of the datatable columns I have a commandlink to call a edit method. If my bean is conversation scoped, the edit method is not called. If it is view scoped then it gets called. I cant have a conversation scoped bean to work with a lazy loading datatable?

@Named("userBean")
@Stateful
@ConversationScoped
@LoggedIn
public class UserBean implements Serializable, UserBeanLocal {

   private static final long serialVersionUID = 1L;

   @Inject
   private Conversation conversation;
   @EJB
   private UserManagerBeanLocal userController;
   @Inject
   private transient FacesContext context;

   private User user;

   private LazyUserDataModel lazyModel;

   public UserBean() {
      user = new User();
   }

   @Override
   @PostConstruct
   public void createLazyDataModel() {
      setLazyModel(new LazyUserDataModel(userController));
   }

   @Override
   @PrePassivate
   public void ejbPassivate(){
      context = null;
   }

   @Override
   @PostActivate
   public void ejbActivate() {
   }

   @Override
   public String create() {
      this.conversation.begin();
      return "create";
   }

   @Override
   public String edit()
   {
      System.out.println("editing user");
      return "create";
   }

}

and

<h:form>
....
<p:dataTable id="userTable" var="usr" value="#{userBean.lazyModel}"
            paginator="true"
            paginatorTemplate="{FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
            rowsPerPageTemplate="5,10,15" paginatorPosition="bottom" rows="10"
            currentPageReportTemplate="{currentPage} de {totalPages}">
            <p:column headerText="Username">
               <h:outputText value="#{usr.name}" />
            </p:column>
            <p:column>
               <p:commandLink value="Edit" action="#{userBean.edit}" actionListener="#{userBean.update}" update="userTable" />
            </p:column>

         </p:dataTable>
</h:form>

Can anybody help?

Thanks

Kelly


Well, it certainly should work. There is nothing obviously wrong with your code, but I suspect from the snippet you are providing that you have some "try and error" history...;-)

Try to debug the conversation and see which conversation is addressed (and when). Are you propagating the conversation-id correctly?

When you write ViewScoped works - did you include Seam 3 for bridging JSF-scopes to CDI, or can it be that you are mixing JSF and CDI scopes?

And: Don't put any EJB code in the constructor as you don't have any guarantee when (and how often) this will be called. Better to use @PostConstruct instead.