Toskan
Toskan

Reputation: 14931

Migration JSF 1.2 to JSF 2 <c:set> var set with null or empty value

I'm getting a

10:55:06,770 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/Lisa].[Faces Servlet]] Servlet.service() for servlet Faces Servlet threw exception: javax.faces.view.facelets.TagException: //somewhere/mytag.xhtml @22,37 <c:set> var set with null or empty value
at com.sun.faces.facelets.tag.jstl.core.SetHandler.apply(SetHandler.java:118) [:2.0.3-]
at com.sun.faces.facelets.tag.jstl.core.IfHandler.apply(IfHandler.java:93) [:2.0.3-]
at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:94) [:2.0.3-]
at com.sun.faces.facelets.tag.ui.CompositionHandler.apply(CompositionHandler.java:162) [:2.0.3-]
at com.sun.faces.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:89) [:2.0.3-]
at com.sun.faces.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:79) [:2.0.3-]

What is the desired workaround? I'm trying to avoid jstl functions, but c:set is unavoidable it seems.

In the tag I'm basically using

    <c:set var="longLabel" value="#{labelBundle[longLabelKey]}" />
<c:if test="#{hv:startsWith(longLabel, '???')}">
    <c:set var="longLabel" value="" />
</c:if>

the problem is a general one: say I have <c:set var="x" value="#{bean.value}"/> where bean.value can be null or empty string. What now?

I read about replacing ui:param with c:set - i'll try out this one

Upvotes: 1

Views: 1719

Answers (1)

mrembisz
mrembisz

Reputation: 12880

Can you use EL 2.2? You could use something like #{labels.getLabel(longLabelKey)} where labels.getLabel contains the required logic including default value. That instead of using c:set/c:if which isn't really recommended here.

Otherwise I would go with defined static function in my own namespace, doing the same as proposed labels.getLabel.

Upvotes: 2

Related Questions