Background url path in a jsf template

后端 未结 2 1739
北恋
北恋 2021-01-06 15:41

i\'m in trouble here. I have a JSF application that has a template file called baseTemplate.xhtml. This file is located in /resources/template folder. Follo

2条回答
  •  [愿得一人]
    2021-01-06 16:34

    CSS background images are loaded relative to the request URL of the CSS file (and thus not immediately relative to its physical location in the web content). If you explore the generated HTML output of the , then you'll see that the request URL has become different. Assuming a context path of /somecontext and a FacesServlet mapping of *.xhtml, it'll look like this:

    
    

    Note that your (improper btw) usage of the library has moved the /css to ?ln=css. You'd need to fix the background image url() accordingly so that it's properly relative to the real request URL of the CSS. E.g.

    background-image: url("../resources/css/imgSite/sisLogo.png");
    

    A more reliable way, which takes JSF resource identifier rules and FacesServlet mapping into account, is to use #{resource} in EL:

    background-image: url("#{resource['css:imgSite/sisLogo.png']}");
    

    See also:

    • Changing JSF prefix to suffix mapping forces me to reapply the mapping on CSS background images
    • What is the JSF resource library for and how should it be used?

提交回复
热议问题