SkylerA
SkylerA

Reputation: 3

Can I pass an enum as an attribute for a custom JSF tag with EL?

I know that EL has built-in coercion for converting strings to enums, as described here

However, I haven't been able to make this work when the string is not a literal. So something like this works:

<p:commandButton action="#{viewBean.createType('FIRST_ENUM')}" />

But I can't do this:

<p:commandButton action="#{viewBean.createType(enumType)}" />

where enumType is, for example, an attribute of a custom tag.

This is a problem because I want to create a custom tag where the using page can invoke different behavior based on the passed enum attribute. I tried using the omnifaces importConstants utility but it didn't seem to help, the attributes were still being passed as strings and never converted to enums by EL.

One solution would be for me to include String overload converters for every enum-param method in the ViewBean, but I'd like to know if there are any cleaner solutions for conversion.

Upvotes: 0

Views: 12

Answers (0)

Related Questions