11 Replies Latest reply on Apr 16, 2006 8:18 PM by trippccn

    URL Friendly Links

    trippccn

      I'm trying to use GET request variables instead of the POST method that commandLink uses. I have the following code:

      <h:commandLink value="#{user.name}" action="#{UserSelect.select}">
      <f:param name="id" value="#{user.id}"/>
      </h:commandLink>


      Which outputs a javascript enabled link with # at the end. But I want links with ?id=1 or ?id=2, etc.

      Is there any way to use GET links (without the javascript) that still call the UserSelect.select() method?

      Thanks,
      Chad



        • 1. Re: URL Friendly Links
          trippccn


          My bad I jumped the gun... can someone just point me to the FAQ on this subject? I couldn't find it in the Wiki.

          chad

          • 2. Re: URL Friendly Links
            mirko27

            <h:outputlink>
            <f:param../>
            </h:outputlink/> ?

            • 3. Re: URL Friendly Links
              gavin.king

              Or, with Seam CVS, try:

              <s:link value="#{user.name}" action="#{UserSelect.select}">
               <f:param name="id" value="#{user.id}"/>
              </s:link>


              I plan to add a whole new page to the Seam refdoc about this....

              • 4. Re: URL Friendly Links
                trippccn


                Ok so I got it to work with @Factory, but I can only link back to the same page. Is there a way to link to another JSP page and still access the outjected variable?

                • 5. Re: URL Friendly Links
                  mirko27

                  s:link element has parameters. It seems to me that default just creates new conversation. You can use
                  <s:link propgragation="join"/>.
                  I think this should work.

                  • 6. Re: URL Friendly Links
                    gavin.king

                     

                    "TrippCCN" wrote:

                    Ok so I got it to work with @Factory, but I can only link back to the same page. Is there a way to link to another JSP page and still access the outjected variable?


                    <s:link view-id="/nextPage.xhtml"
                     action="#{myAction.method}"
                     value="Button Label"
                     propagation="true"/>


                    Note that you have a choice:


                    * specify view-id, and write a void action method
                    * don't specify view-id and return an outcome from the action method
                    * specify view-id, and return null from the action method if you want that view-id to be rendered, or some other outcome if you want a different view-id


                    Pretty flexible :-)

                    • 7. Re: URL Friendly Links

                      Hi. This new Seam link tag solves a few problems I had. Thanks! There is one thing missing from my point of view though. I would like to specify custom urls with this tag.

                      I have been using url rewriting (in and out) to make make friendly URLs for our Seam based application. E.g /myfolder/something/ gets rewritten to /thing.seam?a=myfolder&b=something.

                      Would it be possible to add a new attribute to the link tag that enables me to override the detected URL? How about 'link' as the attribute. Here is an example:

                      <s:link value="view" link="#{mycomponent.niceUrl}"/>


                      We would still be able to use all the other attributes. To prove that this works I coded a change to your HtmlLink class. Here is the segment prior to my change:

                       String url = context.getApplication().getViewHandler().getActionURL(context, viewId);
                       String encodedUrl = context.getExternalContext().encodeActionURL(url)
                      


                      And this is my version:

                      String encodedUrl = null;
                       ValueBinding linkValueBinding = getValueBinding("link");
                       if (linkValueBinding != null) {
                       // link from expression
                       encodedUrl = linkValueBinding.getValue(context).toString();
                       }
                       if ((encodedUrl == null) && (link != null)) {
                       // plain text links
                       encodedUrl = link;
                       }
                       if (encodedUrl == null) {
                       // just get url from context
                       String url = context.getApplication().getViewHandler().getActionURL(context, viewId);
                       encodedUrl = context.getExternalContext().encodeActionURL(url);
                       }


                      Clearly I had to do all the extra stuff to add in the 'link' attribute to the tag.

                      This change works perfectly for me. There may be a better way to do this and I'm not fully up-to-speed on the JSF API. I should probably have encoded the URL and there may be other problems...

                      Anyway, over to you. Is it possible to add in this functionality? Many thanks.

                      • 8. Re: URL Friendly Links
                        gavin.king

                        Add a feature request to JIRA, with a bit more details about how I should go about implementing this.

                        • 9. Re: URL Friendly Links
                          trippccn

                          How do I get the s:link tag to work? I downloaded the nightly build, copied over jboss-seam.jar, and added

                          <%@ taglib uri="http://jboss.com/products/seam/taglib" prefix="s" %>


                          But I'm sure I'm missing something... i get the error:

                          taglib cannot be resolved in either web.xml or the jar files deployed with this application
                          


                          I've never used a nightly build, what am I missing?

                          Thanks, Chad

                          • 10. Re: URL Friendly Links
                            lcoetzee

                            You also need the jboss-seam-ui.jar (which also gets compiled when you build seam from CVS). This jar needs to be packaged in you WAR.

                            L

                            • 11. Re: URL Friendly Links
                              trippccn

                              I compiled from CVS and overwrote the old jboss-seam-ui.jar and still the same error.

                              17:16:09,328 ERROR [[jsp]] Servlet.service() for servlet jsp threw exception
                              org.apache.jasper.JasperException: /charities/find.jsp(1,1) The absolute uri: http://jboss.com/products/seam/taglib cannot be resolved in either web.xml or the jar files deployed with this application