5 Replies Latest reply on Feb 18, 2008 3:42 PM by Gavin King

    DataModelSelection not getting populated

    Jakob Dam Newbie

      Why does DataModelSelection only get updated when I have an action in the s:link? When I redirect via a view attribute it doesn't get populated, however when I redirect via an action i does.


      When having the following in my view, DataModelSelection is not populated


      <h:dataTable value="#{aChildList}" var="c">
        <h:column>
          <s:link value="#{c.firstname} #{c.lastname}"
              view="/childHome.xhtml" />
        </h:column>
      </h:dataTable>
      



      However, now it is.


      <h:dataTable value="#{aChildList}" var="c">
        <h:column>
          <s:link value="#{c.firstname} #{c.lastname}"
              action="#{childManager.select}" />
        </h:column>
      </h:dataTable>
      



      This is the select method


      public String select() {
          return "/childHome.xhtml"; }
      


        • 1. Re: DataModelSelection not getting populated
          Gavin King Master

          That's just the normal behavior. <s:link view=... is intended to give nice, elegant URLs. <s:link action=... is intended as an alternative to a <h:commandLink/>, that handles Open in new window correctly.


          Personally, I don't really much like <s:link action=... anymore.

          • 2. Re: DataModelSelection not getting populated
            Clint Popetz Apprentice

            Gavin King wrote on Feb 18, 2008 02:04 PM:


            Personally, I don't really much like <s:link action=... anymore.


            Really?  Could you elaborate?  How do you recommend handling the situation where one wants a link that (a) executes something before rendering a new view and (b) supports open-in-new-window?   I realize the target page can have a <page> action, but I occasionally need to trigger behavior based on where I am, i.e. the transition from page A to page B needs to do something, and page B doesn't really know about it, so I'd rather not stick it in its action, and putting a <navigation-case> to fire an event is kind of overkill in that case.  (At that point, I've also just traded polluting B with knowledge of A for polluting B's <page> entry with knowledge of A.)  Using s:link with action= also gives me the ability to choose the target view with some action logic based on the row of the data table I'm in, which is really nice.


            I suppose one should argue that links in web pages shouldn't do something like this, because users don't expect links to trigger behavior.  But I work with people that mock up web pages to do things like that all the time.


            Thanks for any guidance you can give on this topic.  Seam is a great framework, but it has a lot of ways to accomplish the same thing (which I enjoy, but then, I'm also a perl programmer), and I'm still trying to grasp its best practices.

            • 3. Re: DataModelSelection not getting populated
              Jakob Dam Newbie

              May I ask why you don't like them?

              • 4. Re: DataModelSelection not getting populated
                Christian Bauer Master

                The s:link action="foo" is evil because it encourages that you modify state on the server with a GET request. Such a request is supposed to be repeatable (bookmarkable), and POST/PUT/DELETE are correct requests for modifying resource state on the server.


                The only situation in which I think s:link action="foo" might be OK is when foo actually is a simple outcome (not a Java method that modifies state) that is mapped to a redirect response (which triggers another, repeatable GET request) in pages.xml.

                • 5. Re: DataModelSelection not getting populated
                  Gavin King Master

                  How do you recommend handling the situation where one wants a link that (a) executes something before rendering a new view and (b) supports open-in-new-window?

                  Use a page action.



                  I realize the target page can have a <page> action, but I occasionally need to trigger behavior based on where I am, i.e. the transition from page A to page B needs to do something, and page B doesn't really know about it, so I'd rather not stick it in its action

                  That sounds like really, really non-semantic use of HTTP. Don't do this.



                  Seam is a great framework, but it has a lot of ways to accomplish the same thing (which I enjoy, but then, I'm also a perl programmer)

                  Yes, this is a fair criticism of Seam. I regret adding certain features, because of this.