Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSF h:outputStylesheet converter - dynamic css?

Tags:

java

css

jsf-2

I just noticed <h:outputStylesheet/> has a converter attribute. After attaching a dummy (pass-through) converter to it, nothing happened. On closer inspection, it seems the converter isn't even called despite hitting the browser refresh button.

Is this attribute good for anything? Is it just there as a side effect of various design decisions?

The reason I ask is that it would be nice to perform some client- or server-side css processing with less or similar and I thought this attribute might help.

like image 319
Steve Avatar asked Jan 05 '12 11:01

Steve


1 Answers

Is this attribute good for anything? Is it just there as a side effect of various design decisions?

That's indeed "by design" since the component extends UIOutput. It does indeed not use the converter for anything.


The reason I ask is that it would be nice to perform some client- or server-side css processing with less or similar and I thought this attribute might help.

You can just use EL the usual way in CSS resources loaded by <h:outputStylesheet>. This was initially implemented in order to resolve background image resources properly.

.some {
    background-image: url(#{resource[images/some.png]});
}

The above example assumes the image to be in /resources/images/some.png. If you're using a library, you need to prefix the resource name with libraryname:.

.some {
    background-image: url(#{resource[somelibrary:images/some.png]});
}

Which assumes the image to be in /resources/somelibrary/images/some.png.

But other than that, you could basically use EL in the CSS resource for anything else. E.g. dynamically resolving colors, fonts and so on.

.some {
    color: #{theme.color};
    font: #{theme.font};
}

Where #{theme} can be a session or maybe application scoped managed bean.

like image 83
BalusC Avatar answered Nov 18 '22 17:11

BalusC