2 Replies Latest reply on Aug 19, 2006 12:09 PM by Joe DeStefano

    Please help me understand DataModelSelection

    Joe DeStefano Newbie

      I'm having a problem with DataModelSelection in my application. I managed to create the same situation in the example "issues" application, so you don't need to wade through all the other crap in my real application.

      My app works like the issues app, except that there is an intervening page between the editProject page and the editIssue page. I simulated this in the issues app by changing the editProject page from this:

      <h:commandButton action="#{issueEditor.selectIssue}" value="#{messages.View} #{messages.Issue}"/>

      To this:

      <h:commandButton action="funky" value="#{messages.View} #{messages.Issue}"/>

      I put an entry in faces-config so that "funky" would go to funky.jsp, which contains only:

      <h:commandButton action="#{issueEditor.selectIssue}" value="#{messages.View} #{messages.Issue}"/>

      (i.e., the original button from the editProject page), surrounded by the necessary other HTML.

      With that change, the application no longer works correctly. Clicking on the View button in the editProject page brings up the funky page, and clicking that button takes me to editIssue, but it always edits the first issue.

      Could someone explain to me the life of the DataModelSelection? Why isn't it preserved through the intervening page?


        • 1. Re: Please help me understand DataModelSelection
          Joe DeStefano Newbie

          It turns out that the selection isn't even correct on the funky.jsp page. I added an outputText to the page:

          <h:outputText value="#{projectEditor.selectedIssue.shortDescription}"/>
          <h:commandButton action="#{issueEditor.selectIssue}" value="#{messages.View} #{messages.Issue}"/>

          and it always displays the description of the first issue, regardless of which button is pressed.

          What am I doing wrong?

          • 2. Re: Please help me understand DataModelSelection
            Joe DeStefano Newbie

            For those of you folowing this saga, I have a hypothesis to explain the problem (take it with a grain of salt, though, since I'm a JSF/Seam newbie). In the original issues app, the injection of the data model selection is being done from within an Action event, during a phase in which the view containing the datamodel is active, and so the selection exists. In the modified app, any injection that happens is being done in the render phase of the new view, and the data model (and its selection) is long gone. The value returned by getSelectedIssue is whatever was last injected.

            So the moral of my story (if I'm not completely wrong in the above analysis) is that if I want the data model selection from a view, I must call an action that either a) is in the component containing the @DataModelSelection annotation, or b) makes a call to a method in that component.

            It seems clear that it must be that way, now that I know the answer. Sigh. Eventually I'll understand this enough to stop hurting myself.