8 Replies Latest reply on Aug 28, 2007 9:54 AM by Adrian Mitev

    DataModelSelection is null

    Ilya Doe Newbie

      I have a page that should display a list of most recent events ocured. By clicking on each event some information should be displayed about the event.

      I am using a DataModel to display the list, but the problem is that after clicking an item, the DataModelSelection is null.

      I have made a simplified example, in order to show the problem:

      @Name("eventComponent")
      @Scope(ScopeType.EVENT)
      public class MyLatestAction {
      
       @In FacesMessages facesMessages;
      
       @DataModel(value="eventList")
       private List<Integer> eventList;
      
       @DataModelSelection
       private Integer selectedEvent;
      
       @Factory("eventList")
       public void initRequestList() {
       eventList = new ArrayList<Integer>();
       eventList.add(1);
       eventList.add(2);
       eventList.add(3);
       }
       public void selectEvent() {
       facesMessages.add("selected event: "+selectedEvent);
       }
      
      }
      


      the view eventList.xhtml contains this code:
      ...
       <h:messages globalOnly="true" styleClass="message"/>
      
       <h:dataTable value="#{eventList}" var="item" >
       <h:column>
       <f:facet name="header">Event</f:facet>
       <s:link action="#{eventComponent.selectEvent}" value="#{item}"/>
       </h:column>
       </h:dataTable>
      
      ...
      



      I am accessing the page from the menu with a link like this:
       <s:link view="/eventList.xhtml" value="Event List"/>
      


      The problem is that even though the page correctly displays the list of events (1, 2, 3), when I select an event, in the bean the selection is null (it prints "selcted event: null"

      What am I doing wrong

        • 1. Re: DataModelSelection is null
          Tim Newbie

          try scope CONVERSATION or wider

          • 2. Re: DataModelSelection is null
            Ilya Doe Newbie

             

            "tim_ph" wrote:
            try scope CONVERSATION or wider

            Thanks, I have tried: It only works with session and long running conversation.
            But using such a wider scope introduces more complications, like ending the conversation, cleaning the data from the session, etc.

            I understood from the docs that Page scope was designed to do just this - persist the data to the client to be available to the next request.

            • 3. Re: DataModelSelection is null
              Pete Muir Master

              Yes, that is what PAGE scope does. So use it.

              • 4. Re: DataModelSelection is null
                Ilya Doe Newbie

                 

                "pete.muir@jboss.org" wrote:
                Yes, that is what PAGE scope does. So use it.


                But it does not work with DataModel - I've posted above the example that is not working.

                • 5. Re: DataModelSelection is null
                  Ilya Doe Newbie

                   

                  "ilya78" wrote:
                  "pete.muir@jboss.org" wrote:
                  Yes, that is what PAGE scope does. So use it.


                  But it does not work with DataModel - I've posted above the example that is not working.


                  It is a mistake in the example above, the correct is :

                  @DataModel(value="eventList", scope=ScopeType.PAGE)

                  This is what I am trying and is not working (sorry for the confusion)

                  • 6. Re: DataModelSelection is null
                    Ilya Doe Newbie

                    Can please someone help me out. Here is a simple application to reproduce just the problem:

                    @Name("eventLister")
                    @Scope(ScopeType.EVENT)
                    public class EventListerAction implements Serializable {
                    
                     @In FacesMessages facesMessages;
                    
                     @DataModel(value="eventList", scope=ScopeType.PAGE)
                     private List<Integer> eventList;
                    
                     @DataModelSelection
                     private Integer selectedEvent;
                    
                     @Factory("eventList")
                     public void initRequestList() {
                     eventList = new ArrayList<Integer>();
                     eventList.add(1);
                     eventList.add(2);
                     eventList.add(3);
                     }
                     public void selectEvent() {
                     facesMessages.add("selected event: "+selectedEvent);
                     }
                    
                    }
                    


                    and eventList.xhtml:

                    <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
                     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
                    <ui:composition xmlns="http://www.w3.org/1999/xhtml"
                     xmlns:s="http://jboss.com/products/seam/taglib"
                     xmlns:ui="http://java.sun.com/jsf/facelets"
                     xmlns:f="http://java.sun.com/jsf/core"
                     xmlns:h="http://java.sun.com/jsf/html"
                     template="layout/template.xhtml">
                    
                    <ui:define name="body">
                    
                     <h:messages globalOnly="true" styleClass="message"/>
                    
                     <h:dataTable value="#{eventList}" var="item" >
                     <h:column>
                     <f:facet name="header">Event</f:facet>
                     <s:link action="#{eventLister.selectEvent}" value="#{item}"/>
                     </h:column>
                     </h:dataTable>
                    </ui:define>
                    
                    </ui:composition>
                    



                    The problem is that when I call selectEvent, the DataModelSelection is null. Please help.

                    • 8. Re: DataModelSelection is null
                      Adrian Mitev Master

                      Btw today i had a similar issue with page scoped dataModel but i was passing the object as method param with el <s:link action="#{eventLister.selectEvent(item)}" value="#{item}"/> like this and the same issue as here occured.