2
votes

I want to use custom attributes in standard JSF-components. Using or rather introducing a ResponseWriterWrapper as described here: Adding custom attribute (HTML5) support to JSF 2.0 UIInput component, doesn't work when the custom attribute's value is an EL expression.

I introduced a custom renderer class for the component t:div and use my ResponseWriterWrapper to render custom attributes. So when writing

<t:div data-role="collapsible" data-collapsed="false">
    ...
</t:div>

everything works fine!

But the following code doesn't work:

<t:div data-role="collapsible" data-collapsed="#{false}">
    ...
</t:div>

To be more detailed the attribute "data-collapsed" is not rendered because it is not part of the component's attribute list. I can see this when the component is passed to encodeBegin method.

Does somebody has an idea what's the reason for this and how I can solve this with a workaround or something?

Thanks in advance!

1
Can you tell us what data-collapsed will be used for? There may be a workaround of some sort.Jonathan S. Fisher
Thanks for replying. The example is just intended to show the problem in a simple way. In this specific case the workaround is <div data-collapsed="#{false}>..</div>. The main problem remains, though: I want to use custom attributes on JSF-components in combination with EL-expressions. (BTW: "data-collapsed" is a jQuery Mobile attribute, and "data-*" is the preferred way in HTML5 for custom attributes.)asotbb
I've read lots of JSF component documentations and I've read a lot about "EL expression that must parse to <datatype>". I'm not very knowledgeable about this, but, what's supposedly the way to do an EL expression that parses to a certain datatype?Carlos Vergara
The datatype is defined by the getter/setter method in the component class. Check this example: blog.evolutionarydawn.com/2009/06/11/custom-jsf-component-12 But I don't see your point here, could you explain?asotbb

1 Answers

-1
votes

For custom attributes to be rendered in JSF they should be passed as Passthrough attributes which is possible in JSF2.2, not in 2.0 according to my knowledge.

If you include following namespace (jsf 2.2):

      xmlns:pt="http://xmlns.jcp.org/jsf/passthrough"

and define <t:div data-role="collapsible" data-collapsed="#{false}">it will render the data-collapsed attributes in you JSF component.

Its an option for you if upgrading jsf is possible.