6 Replies Latest reply on Aug 8, 2008 2:50 PM by pmuir

    Can @DataModel be replaced with EntityQuery?

    wilczarz.wilczarz.gmail.com

      DataTable has no problem displaying elements of collection annotated with @DataModel. Populating the same table with entityQuery.dataTable isn't that simple. The scope of entityQuery component seems to be cruicial, but the best I could get was displaying the table properly with scope PAGE. It was useless to me since I wanted to inject the selection to SFSB in the next request. With more desirable scopes, like CONVERSATION the table rendered just empty..

        • 1. Re: Can @DataModel be replaced with EntityQuery?
          admin.admin.email.tld

          that's interesting.  can u post some code?


          I've never heard of not being able to use conversation scope for a Seam component...

          • 2. Re: Can @DataModel be replaced with EntityQuery?
            wilczarz.wilczarz.gmail.com

            Sure. This is my component:


            @Name( "clientList" )
            @Scope( CONVERSATION )
            public class ClientList extends EntityQuery<Client> {
                 @Override
                 public String getEjbql() {
                      return "from Client";
                 }     
            }



            the page that uses it (rendered outside any conversation):


            <rich:dataTable id="clientList" var="loopClient" value="#{clientList.dataModel}" >
              <rich:column>
                <h:form>
                  <h:commandLink value="#{loopClient.name}" action="#{sampleAction.showClient}" />
                </h:form>     
              </rich:column>
            </rich:dataTable>



            and my session bean:


            @Stateful
            @Name( "sampleAction" )
            @Scope( CONVERSATION )
            public class SampleAction implements SampleLocal {
            ...
            @In(create = true) 
            @Out 
            @DataModelSelection 
            private Client client;
            ...
            @Begin public String showClient() {
            ...
            }



            Like I said, for CONVERSATION scope in EntityQuery the table renders empty. Now, everyting works fine with


            @DataModel
            private List<Client> clients;
            
            @Factory( "clients" )
            public void findUsers() {
                 clients = entityManager.createQuery("from Client").getResultList();
            }


            and


            <rich:dataTable id="clientList" var="loopClient" value="#{clients}" >
              <rich:column>
                <h:form>
                  <h:commandLink value="#{loopClient.name}" action="#{sampleAction.showClient}" />
                </h:form>     
              </rich:column>
            </rich:dataTable>



            because If no scope is explicitly specified for @DataModel, the scope of the component with the @DataModel attribute is used. That works for the SessionBean, but not for EntityQuery.



            • 3. Re: Can @DataModel be replaced with EntityQuery?
              baz


              the page that uses it (rendered outside any conversation):

              <rich:dataTable id="clientList" var="loopClient" value="#{clientList.dataModel}" >




              try to use resultList instead of datamodel. Here is a link to the seam issue tracker.
              JBSEAM-2684


              BTW: Can anybody explain why i should use dataModel? I have ever used resultList

              • 4. Re: Can @DataModel be replaced with EntityQuery?
                wilczarz.wilczarz.gmail.com

                I've tried that but resultList seems incompatible with @DataModelSelection. Nothing gets injected.

                • 5. Re: Can @DataModel be replaced with EntityQuery?
                  wilczarz.wilczarz.gmail.com

                  Ok, I found a workaround for this problem. The DataModel needs to be created manually in EntityQuery:


                  @Name( "clientList" )
                  @Scope( CONVERSATION )
                  public class ClientList extends EntityQuery<Client> {
                       
                       @Factory( value = "clients", scope = ScopeType.CONVERSATION )
                       public ListDataModel findClients() {
                            List<Client> clients = getResultList();
                            return new ListDataModel( clients );
                       }
                  
                       @Override
                       public String getEjbql() {
                            return "from Client";
                       }
                  }



                  Generally I think it's a good idea to separate any entity's DataModel population from the SessionBean the selection goes to. I'm just not sure if this is the best way to do it.

                  • 6. Re: Can @DataModel be replaced with EntityQuery?
                    pmuir

                    Most likely the ManagedEntityIdentityInterceptor rearing its ugly head - this is turned off by default in trunk, and we are working on a replacement solution for clustering failover.