0 Replies Latest reply on Dec 4, 2008 5:28 AM by Ingo Jobling

    Including JavaScript variables in s:link URL

    Ingo Jobling Master

      Here is how I used jQuery to include a Javascript variable in the url generated for <s:link>, maybe someone else will find this useful ...


      This reminded me how powerful Seam, Richfaces, and jQuery are!  With these tools in your shop, you can do some pretty cool stuff!  J


      Setting it up with jQuery:


      <script type="text/javascript" >
      function interpolateJsVar(target, search, replacement){
              return target.replace('='+search, '='+replacement);
      }
      </script>
      <rich:jQuery selector=".interpolateSplitterPosition" query="bind('click', function() { this.href=interpolateJsVar( this.href,'splitterPosition',splitterPosition
       ); });" timing="onload"/>   



      Calling it:


      <rich:treeNode>
              <s:link view="/intranet/premises/PremisesIdentification.xhtml" value="Premises: #{premises.number}" styleClass="interpolateSplitterPosition">
                      <f:param name="premisesId" value="#{premises.id}" />
                      <a4j:actionparam name="splitterPosition" value="splitterPosition" />
              </s:link>
      </rich:treeNode>