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

    DataModelSelection not injected

    Piotr Salski Newbie

      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


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

      and my class

      public class EventBean implements IEventBean {
              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() {
               return "success";
          public void newEvent(EventEntity g) {
              try {
                   if(em.find(EventEntity.class, new Long(g.getEventId())) != null)
              catch (Exception e) {
           public String getSearchField() {
                return searchField;
           public void setSearchField(String searchField) {
                this.searchField = searchField;
           public String search()
                String sField = "%" + getSearchField().toUpperCase() + "%";
                     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)
                mSelEvents = null;
                return "success";
           public String editEvent() {
                return "success";
           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