1
votes

I've got a problem, concerning the "rendered" attribute of a h:outputStylesheet inside my composite component.

<h:outputStylesheet rendered="#{cc.attrs.value == 'somevalue'}" library="css" name="mainDark.css" target="head" />

does not work, even if the EL evaluates to 'true'. Whereas

<h:outputText rendered="#{cc.attrs.value == 'somevalue'}" value="rendered = true" style="color: red;" />

is getting properly rendered/not rendered.

While this is already quite confusing, it gets even worse:

  • if I replace the EL by just 'true' or 'false', the attribute works as intended.
  • if I replace the EL by some other evaluation it works too. For example #{someBean.somevalue == 'somevalue'} or just #{1 > 0}

Am I missing something, or might this just be some weird bug? I'm running on Tomcat v7.0 and JSF2.0

3
My current workaround: <h:outputStylesheet library="css" name="#{cc.attrs.enable == 'true' ? 'mainDark.css' : 'empty.css'}" target="head" /> But i'd still be interested, why this happens.Christian Voß
That's not a custom component. That's a composite component. I edited the title and tag. Interesting issue nonetheless. What JSF impl/version are you using?BalusC
Oh sorry for that :) I'm using Mojarra JSF Implementation 2.0.3Christian Voß
Just tried Mojarra 2.1.3. Still the same.Christian Voß

3 Answers

2
votes

Ok,

I think i found, why this is happening:

Instead of evaluating the EL, before passing it into the "rendered" attribute, the complete EL is passed through. As the component outputSytylesheet does not know of the cc.attrs it allways evaluates it to false.

So

<h:outputStylesheet rendered="#{someBean.somevalue == 'somevalue'}" library="css" name="mainDark.css" target="head" />

or

<h:outputStylesheet rendered="#{2 gt 1}" library="css" name="mainDark.css" target="head" />

works, because it can be evaluated. Whereas

<h:outputStylesheet rendered="#{cc.attrs.somevalue == 'somevalue'}" library="css" name="mainDark.css" target="head" />

will allway be evaluated 'false' inside the component.

If anyone else experiences this "bug", this is what i found the most convenient "solution":

<h:outputStylesheet library="css" name="#{cc.attrs.enabled ? 'mainDark.css' : 'empty.css'}" target="head" />

Should anyone know of a proper solution to this issue, please feel free to further respond :)

Best regards, Christian

EDIT: It also could be, because the css is rendered outside of the composite component, and therefore cannot evaluate the cc.attrs.

0
votes

I'm having the same problem, I want to be able to specify a theme for my component, through the attribute "theme". Unfortunately "cc.attrs" variables are not available for the "h:outputStyleSheet" component.

I opened an issue in the JSF JIRA: https://java.net/jira/browse/JAVASERVERFACES_SPEC_PUBLIC-1195

0
votes

Tried with JSF Mojarra 2.2.1 this solution without success:

<h:outputStylesheet library="css" name="#{cc.attrs.enabled ? 'mainDark.css' : 'empty.css'}" target="head" />

Now I found this workaround to handle this evaluation problem succesfully:

<link rel="stylesheet" type="text/css" href="#{request.requestURL.substring(0, request.requestURL.length() - request.requestURI.length())}#{request.contextPath}/javax.faces.resource/#{cc.attrs.includeStyle ? 'style.css' : 'empty.css'}.html?ln=libraryName" />

I hope this helps someone. I'm always open for a cleaner solution ;)