2 Replies Latest reply on Jul 13, 2008 3:45 PM by Dean Hiller

    outputLink vs. s:link output different results?

    Dean Hiller Expert

      Here is my xhtml code inside a dataTable....

      well, I would show you the code, but after I put it in a code block, I got a parsing error....these DAMN forums.  I wish they would fix that.  putting it in a quote block worked though ....

      <s:link id="userlogin" view="/secure/company.xhtml" value="http://hosteditinabox.com/#{comp.alias}">
         <f:param name="alias" value="#{comp.alias}"/>
      <h:outputLink  value="/secure/company.xhtml" >
         <f:param name="alias" value="#{comp.alias}"/>                                             

      This results in two different urls http://localhost/mainapp/secure/company.xhtml?dataModelSelection=... and http://localhost/secure/company.xhtml - notice the second one is WRONG because of the mainapp is missing.  The first one, I don't want to use because I don't want the dataModelSelection thing there since I am not using it in this special case(I don't need to know what is selected).

      Lastly, my template has this line of code as well so I can always type everything in every page in from the context root of the webapp(is this the best way to do it...I think relative urls are a pain as with absolute at least you can do a complete find and replace if you move the file...with relative urls you can't)....

      <base href="#{facesContext.externalContext.request.scheme}://#{facesContext.externalContext.request.serverName}:

      Any help on this would be really great

        • 1. Re: outputLink vs. s:link output different results?
          Pete Muir Master

          I fixed your code blocks for you (by adding back ticks)

          Anyway, yes, <h:outputLink /> isn't very useful (actually, that reminded me to add it to the agenda for JSF 2, thanks!). I don't see why you need quite that amount of code, doing

          <h:outputLink value="/#{facesContext.externalContext.requestContextPath}/foo.xhtml" />

          is enough as http recognises that as a link relative to the server root.

          As a short cut, define <factory name="requestContextPath" value="#{facesContext.externalContext.requestContextPath}" /> in components.xml.

          • 2. Re: outputLink vs. s:link output different results?
            Dean Hiller Expert

            never mind, I got it figured out.  outputlink is just a relative OR absolute URL while s:link is only the absolute from the servlet context root!!!  Then, with base path, I just have to change the output link to value="secure/company.xhtml" and thanks to the base I set in the template, it will all work just fine, and s:link never fools around with the base because it is sooo cool that it doesn't have to.  These details kill people though...ugh... oh well, won't forget this next time and I hope this helps someone else out.