1

I'm trying to use to output a stylesheet link for every element of an ArrayList. This code produces no result:

<ui:repeat value="#{includer.css}" var="ss">
  <h:outputStylesheet name="#{ss}" library="css" />
</ui:repeat> 

However, if i change the Strings in the ArrayList to be full paths and replace h:outputStylesheet with plain html like :

<ui:repeat value="#{includer.css}" var="ss">
  <link type="text/css" rel="stylesheet" href="${ss}" />
</ui:repeat> 

then it works as expected. The problem with this is i have some EL expressions in some css files and it seems they are not being evaluated, I assume because i'm referencing them directly like that.

Thanks for any insight.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
lmerry213
  • 409
  • 6
  • 16
  • EL expressions in stylesheets won't be evaluated regardless of how you generate the HTML. Stylesheetsare loaded direct by the browser, without going through anything that will evaluate EL. – user207421 Jun 09 '15 at 01:36
  • @EJP: actually, they will be, but only when loaded via `` (and you've restarted the webapp after adding an EL expression to an already-loaded stylesheet; this is namely remembered applicationwide on a per-stylesheet basis). – BalusC Jun 09 '15 at 04:36
  • @BalusC How so? When it generates an HTML link element? – user207421 Jun 09 '15 at 04:59
  • @EJP: primarily to support `#{resource}` in URL selectors for e.g. background images and fonts. See also a.o. http://stackoverflow.com/questions/6925733/how-to-reference-jsf-image-resource-as-css-background-image-url/6926193#6926193 – BalusC Jun 09 '15 at 05:01

1 Answers1

2

The <h:outputStylesheet> (and <h:outputScript>) needs to be present during view build time in order to let the JSF resource management to properly pickup them. The <ui:repeat>, however, runs during view render time only, it would be too late for JSF to perform relocation actions (moving to bottom of head or body, etc).

Replace it by <c:forEach>.

<c:forEach items="#{includer.css}" var="ss">
    <h:outputStylesheet name="#{ss}" library="css" />
</c:forEach> 

See also:


Unrelated to the concrete problem, a library name of css is wrong. Carefully read What is the JSF resource library for and how should it be used?

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555