Is there something like for JSF?

前端 未结 1 857
时光取名叫无心
时光取名叫无心 2021-01-21 23:33

Is there a taglib in JSF for inserting the proper application context root in any URL I want, just like the tag in JSP does?

相关标签:
1条回答
  • 2021-01-22 00:00

    Not exactly that, but all JSF components which refer to an URL resource will already automatically include the proper context path and eventually also the FacesServlet mapping. For example the <h:link>:

    <h:link value="Link to other page" outcome="otherpage" />
    

    which renders something like (assuming that your context path is /contextname and your FacesServlet is mapped on *.xhtml):

    <a href="/contextname/otherpage.xhtml">Link to other page</a>
    

    You can include request parameters by <f:param>:

    <h:link value="Link to other page" outcome="otherpage">
        <f:param name="foo" value="#{bean.foo}" />
    </h:link>
    

    which renders something like:

    <a href="/contextname/otherpage.xhtml?foo=bar">Link to other page</a>
    

    Other link components which also do that are the <h:outputStylesheet>, <h:outputScript> and <h:graphicImage> for CSS, JS and images respectively:

    <h:outputStylesheet library="default" name="css/foo.css" />
    <h:outputScript library="default" name="js/foo.js" />
    <h:graphicImage library="default" name="images/foo.png" />
    

    which renders something like:

    <link rel="stylesheet" type="text/css" href="/contextname/javax.faces.resource/css/foo.css.xhtml?ln=default" />
    <script type="text/javascript" src="/contextname/javax.faces.resource/js/foo.js.xhtml?ln=default"></script>
    <img src="/contextname/javax.faces.resource/images/foo.png.xhtml?ln=default" />
    
    0 讨论(0)
提交回复
热议问题