2 Replies Latest reply on Sep 4, 2009 10:48 PM by asookazian

    DataModelSelection not injected

    salski22

      I'm new with seam :)


      I can list objects with @DataModel when search method is called. I have edit button next to each object returned in dataTable


      list.xhtml


      <ui:define name="body">
          
          <h:messages styleClass="message"/>
          
          <h:form id="edit">
          
              <rich:panel>
                  <f:facet name="header">Edit</f:facet>
               <h:dataTable value="#{eventSearchMatches}" var="e">
                  
                  <h:column>
                      <p><h:outputText value="#{e.startDate}" /></p>
                      <p><h:outputText value="#{e.description}" /></p>
                  </h:column>
                  <h:column>
                  <s:button value="Edit" action="#{eventList.editEvent}" />
                  </h:column>
                  
              </h:dataTable>
            
              </rich:panel>
               
          </h:form>
      
       </ui:define> 
      </ui:composition>



      and my class


      @Stateful
      @Name("eventList")
      public class EventBean implements IEventBean {
          @PersistenceContext(unitName="polskirajweb")
              private EntityManager em;
          
          
          @In(value="event", create=true)
          @Out(value="event", required=false)
          private EventEntity mActiveEvent;
          
           private String searchField;
          
          @DataModel(value ="eventSearchMatches")
          List<EventEntity> mEventMatches; 
          
          @DataModelSelection(value ="eventSearchMatches")
          private EventEntity mSelEvents;
          
          public EventEntity getMActiveEvent() {
                return mActiveEvent;
           }
      
           public void setMActiveEvent(EventEntity activeEvent) {
                mActiveEvent = activeEvent;
           }
      
           
          
          public String newEvent() {
               newEvent(getMActiveEvent());
               return "success";
          }
          
          public void newEvent(EventEntity g) {
              try {
                   if(em.find(EventEntity.class, new Long(g.getEventId())) != null)
                   {
                        em.merge(g);
                   }
                   else
                        em.persist(g);
              }
              catch (Exception e) {
                  e.printStackTrace();
              }
          }
      
           public String getSearchField() {
                return searchField;
           }
      
           public void setSearchField(String searchField) {
                this.searchField = searchField;
           }
      
           public String search()
           {
                
                String sField = "%" + getSearchField().toUpperCase() + "%";
                try 
                {
                     Query q = em.createQuery("select e from EventEntity e where upper(e.city) like :searchField" +
                                " or upper(e.sidecity) like :searchField or upper(e.place) like :searchField" +
                                " or upper(e.description) like :searchField").setParameter("searchField", sField);
                     
                     mEventMatches = q.getResultList();
                }
                catch (Exception e)
                {
                     e.printStackTrace();
                }
                
                mSelEvents = null;
                
                return "success";
           }
      
           public String editEvent() {
                setMActiveEvent(mSelEvents);
                return "success";
           }
           
           
           @Remove
           @Destroy
           public void destroy() {}
      
      
           
      } 


      I tried to debug and I see that mSelEvents i null all the time, so it looks like selected object from @DataModel is not injected into @DataModelSelection, am I right??


      I want to edit variables from list.xhtml but when I enter new variables it will persist new object, it will not be updated.


      Why this is not working, what I'm doing wrong???
      Please help

        • 1. Re: DataModelSelection not injected
          salski22

          I have added scope


          @DataModel(value ="eventSearchMatches", scope=ScopeType.PAGE)
              List<EventEntity> mEventMatches; 



          and now it appears to work :-)

          • 2. Re: DataModelSelection not injected
            asookazian

            When you specify scope, it instructs Seam to outject the variable to the specified scope.


            If there is no scope specified, it will outject to the scope of the component, which in the case of a SFSB it's conversation-scope.


            The possible reason it wasn't working previously is b/c you did not have a LRC running.  Seam destroys components that use temporary conversations (which is the default for SFSBs).