h:outputStylesheet inside ui:repeat

295 views Asked by At

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

There are 1 answers

1
BalusC On BEST ANSWER

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?