0
votes

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.

1
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
@EJP: actually, they will be, but only when loaded via <h:outputStylesheet> (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
@BalusC How so? When it generates an HTML link element? - user207421
@EJP: primarily to support #{resource} in URL selectors for e.g. background images and fonts. See also a.o. stackoverflow.com/questions/6925733/… - BalusC

1 Answers

1
votes

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?