6 Replies Latest reply on Apr 3, 2007 2:35 AM by laksu

    @DataModel does not create a component

    laksu

      Hi,
      I have a SFSB:

      /*
      package datassist.gop.action;
      
      import datassist.gop.domain.Istek;
      import datassist.gop.domain.Uzman;
      import java.io.Serializable;
      import java.util.List;
      import javax.ejb.Remove;
      import javax.ejb.Stateful;
      import javax.persistence.EntityManager;
      import javax.persistence.PersistenceContext;
      import javax.persistence.PersistenceContextType;
      import org.jboss.seam.ScopeType;
      import org.jboss.seam.annotations.Begin;
      import org.jboss.seam.annotations.Create;
      import org.jboss.seam.annotations.Destroy;
      import org.jboss.seam.annotations.End;
      import org.jboss.seam.annotations.Logger;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.Scope;
      import org.jboss.seam.annotations.datamodel.DataModel;
      import org.jboss.seam.annotations.datamodel.DataModelSelection;
      import org.jboss.seam.log.Log;
      
      @Stateful
      @Name("isteklerAction")
      @Scope(ScopeType.SESSION)
      public class IsteklerAction implements Serializable, IsteklerActionLocal {
      
       @PersistenceContext(type=PersistenceContextType.EXTENDED)
       private EntityManager entityManager;
      
       public IsteklerAction() {
       }
      
       @Create
       public void init(){
       System.out.println("initing istekler. logger is "+((logger==null)?"null":"not null"));
       refresh();
       }
      
       @DataModel
       private List<Istek> isteklerList;
      
       public void refreshIstekler(){
       System.out.println("refreshing istekler");
       isteklerList=entityManager.createQuery("from Istek i").getResultList();
       for(Istek i:isteklerList){
       System.out.println("Istek: id="+i.getId()+" konu="+i.getKonu()+" acan="+i.getAcan().getAdSoyad());
       }
       }
      
       private List<Uzman> uzmanlar;
      
       private void refreshUzmanlar(){
       System.out.println("refreshing kullanicilar");
       uzmanlar=entityManager.createQuery("from Uzman u").getResultList();
       for(Uzman u:uzmanlar){
       System.out.println("Uzman: id="+u.getId()+" ad="+u.getAd());
       }
       }
      
       public void refresh() {
       refreshIstekler();
       refreshUzmanlar();
       }
      
       @DataModelSelection()
       private Istek istek;
      
       @Begin
       public void setIstek(Istek istek){
       System.out.println("Istek=");
       System.out.println("Istek: id="+istek.getId());
       System.out.println(" konu="+istek.getKonu());
       System.out.println(" acan="+istek.getAcan().getAdSoyad());
      
       this.istek=istek;
       entityManager.refresh(istek);
       }
      
       @Begin
       public void select(){
       System.out.println("Istek=");
       System.out.println("Istek: id="+istek.getId());
       System.out.println(" konu="+istek.getKonu());
       System.out.println(" acan="+istek.getAcan().getAdSoyad());
       }
      
       @End
       public void clear() {
       istek=null;
       }
      
       public List<Istek> getIsteklerList() {
       return isteklerList;
       }
      
       public void setIsteklerList(List<Istek> istekler) {
       this.isteklerList = istekler;
       }
      
       public List<Uzman> getUzmanlar() {
       return uzmanlar;
       }
      
       public void setUzmanlar(List<Uzman> uzmanlar) {
       this.uzmanlar = uzmanlar;
       }
      
       public void logSomething(){
       System.out.println("Trying to log something dummy and the logger is "+((logger==null)?"null":"not null"));
       }
      
       @Logger
       private Log logger;
      
       @Remove @Destroy
       public void destroy(){}
      
      }
      


      and I have the following in my page:
      
       <h:dataTable var="istek" value="#{isteklerlist}">
       <h:column>
       <f:facet name="header">No</f:facet>
       <s:link value="#{istek.id}" action="#{isteklerAction.setIstek(istek)}"/>
       </h:column>
       <h:column>
       <f:facet name="header">Tarih</f:facet>
       #{istek.acilis}
       </h:column>
       <h:column>
       <f:facet name="header">Konu</f:facet>
       #{istek.konu}
       </h:column>
       </h:dataTable>
      

      I cannot make the table to display the isteklerList. The table's header shows up but no data. I have verified to print that the data exists. I have a similar page in another app working but this one does not. In fact the DataModel component is not even created. I checked with the debug page to see that no component named "isteklerList" exists.
      What am I missing?


        • 1. Re: @DataModel does not create a component
          gmanwani

          Seems like a minor typo..

          your variable name is ->isteklerList

          while on the page u use <h:dataTable var="istek" value="#{isteklerlist}">

          notice that the 'L' should be uppercase

          • 2. Re: @DataModel does not create a component
            laksu

            I wish it was a typo. The typo must have slipped in while suspecting everything and trying alternatives wildly. I have corrected the typo but the situation is same.

            • 3. Re: @DataModel does not create a component
              stu2

              Hmm. If the data is there but not showing up in the table, I wonder if there's a timing problem. That is, is the data populated after the JSF components are attempting to retrieve it. What about putting some debug output in getIsteklerList() and making sure this is being called AFTER your population methods?

              • 4. Re: @DataModel does not create a component
                laksu

                Nothing, the getter is not even gets called.
                Whatever i write as the table's var (i.e. as i did with the typo and i also tried a weird string like "qwerty") it does not complain about it; no exceptions or messages. It is like it just does not care about it.
                The interesting part is that when I check with seam-debug isteklerList does not exist in any context.

                • 5. Re: @DataModel does not create a component
                  gmanwani

                  aha.. I think I know the problem. You are missing the @Factory annotation to initialize the datamodel


                  @Factory("isteklerList ")
                  public void loadIsteklerList() {
                  logger.debug("loadIsteklerList ");
                  if (isteklerList == null) {
                  isteklerList = populateList();
                  }

                  • 6. Re: @DataModel does not create a component
                    laksu

                    Nope
                    I have tried that already and tried once again to make sure.
                    Also, I don't think I must have a @Factory method. I already have a @Create and I initialize the list there. I dump the contents of the List and I am certain it is initialized. Problem is just that it is not recognized by Seam as a component. For that reason, even the @Factory method does not get called.
                    It must have something to do with the configuration