11 Replies Latest reply on Feb 29, 2008 11:46 AM by pmuir

    AJAX support for <s:link>

    bogdanminciu.bogdan.minciu.yahoo.com

      I was wondering if there is any AJAX support for the <s:link> tag in seam. I want to reRender the list of clients in an application when the user clicks on the next page... link, and this kind of code came first in mind:


      <s:link rendered="#{clientSearch.nextPageAvailable}" value=" next page... ">
       <a:support event="onclick" actionListener="#{clientSearch.nextPage}" reRender="searchResults" />
      </s:link>
      



      But this code results just in a page refresh, and the nextPage() method is not called.


      I tried passing the 'action=""' parameter to the <s:link> tag, with no success.


      I heard a rumor that the <s:link> does not accept AJAX support. Is that right? Or what am I missing? Can anyone suggest a better approach to this issue?


      Thanks in advance,
      Bogdan.

        • 1. Re: AJAX support for <s:link>
          pmuir

          I think you are better off just using something like a commandLink - s:link doesn't support ajax4jsf, you are right.

          • 2. Re: AJAX support for <s:link>
            bogdanminciu.bogdan.minciu.yahoo.com

            Thanks for the reply Pete.


            The thing that I don't like about h:commandLink is that it does not preserve the conversation context. I think my scenario is simple enough to be solved with a simple h:commandLink, but for more complex situations it would be nice to use ajax with s:link.


            Have you planed this improvement for future seam releases? (currently using SEAM 2.0.1)

            • 3. Re: AJAX support for <s:link>
              pmuir

              Huh? h:commandLink definitely propagates the conversation.

              • 4. Re: AJAX support for <s:link>
                bogdanminciu.bogdan.minciu.yahoo.com

                Pete, thanks for clearing that out. I started using SEAM for a week, so I'm not very comfortable with this new terms, but reading the seam tutorial http://docs.jboss.com/seam/2.0.1.GA/reference/en/html/tutorial.html I understood that h:commandLink does not propagate the conversation. Here is the quote:




                The Seam <s:link> tag lets us attach a JSF action listener to an ordinary (non-JavaScript) HTML link. The advantage of this over the standard JSF <h:commandLink> is that it preserves the operation of open in new window and open in new tab.


                Can you please make more clear what does it mean that the h:commandLink does not preserve the operation of open in new window and open in new tab? I was thinking that these operations are similar to the conversations opened when you display hotels in different tabs in the booking example. Thanks!

                • 5. Re: AJAX support for <s:link>
                  tomstrummer.tomstrummer.gmail.com

                  I agree, this is very annoying.  It seems like JSF wants everything to be a POST operation, which is not REST-ful at all.  I've outlined my thoughts in a post on the old forum here


                  The problem is really that the A4J JavaScript lib tries to do a form POST when you click the link.  Since <s:link> uses a GET with the parameters in the URL, this is not going to work.  It's frustrating though, since in MVC-style frameworks an AJAX GET is even easier than a POST. 

                  • 6. Re: AJAX support for <s:link>
                    jimk1723

                    Bogdan,


                    You may be looking for the a4j:commandLink.


                    I've also used the a4j:jsFunction to add a client-side Javascript Ajax function to the page; you can then call the function from, say, the onclick of a vanilla anchor tag. The href of the anchor tag would be your bookmark-able URL and your onclick handler would drive the Ajax update returning false so the link isn't actually followed.


                    The a4j:jsFunction lets you fetch JSON data from the server, but I've found invoking an action and reRendering elements to be sufficient in most cases.


                    Tom,


                    Why you would care if the Ajax call is a POST or a GET? I mean, you're not updating the address bar which is ostensibly the main use of s:link - to create a bookmark-able URL that represents the state of the view.

                    • 7. Re: AJAX support for <s:link>
                      bogdanminciu.bogdan.minciu.yahoo.com

                      Thanks James for pointing me to the a4j:commandLink tag.


                      This is how I managed the problem:


                      <a:commandLink rendered="#{clientSearch.nextPageAvailable}" reRender="searchResults" action="#{clientSearch.nextPage}" value="next..."/>
                      



                      • 8. Re: AJAX support for <s:link>
                        pmuir

                        Bogdan Minciu wrote on Feb 20, 2008 06:22 PM:


                        Can you please make more clear what does it mean that the h:commandLink does not preserve the operation of open in new window and open in new tab? I was thinking that these operations are similar to the conversations opened when you display hotels in different tabs in the booking example. Thanks!


                        As another poster <h:commandLink /> do a post so you can't right click->open in new tab with it.

                        • 9. Re: AJAX support for <s:link>
                          tomstrummer.tomstrummer.gmail.com

                          James Kelly wrote on Feb 20, 2008 11:50 PM:

                          Why you would care if the Ajax call is a POST or a GET? I mean, you're not updating the address bar which is ostensibly the main use of s:link - to create a bookmark-able URL that represents the state of the view.


                          For one, it means every AJAX link needs to be inside an <h:form> tag.  Also if there is a URL still in the 'href' attribute it means that the request can still be made w/o JavaScript.  And it's a little more REST-ful that way. 


                          The last two reasons don't matter so much I suppose; but having to pepper form tags around where there are only links seems silly, and if you can call a JSF action using a GET request (i.e. using s:link) it would seem there is no technical reason why you couldn't do this via AJAX. 


                          Thanks

                          • 10. Re: AJAX support for <s:link>
                            pmuir

                            Ok, maybe we can support this. File a feature request in JIRA.

                            • 11. Re: AJAX support for <s:link>
                              pmuir

                              Of course, the AJAX request won't be sent using a GET request ;-)