wobblycogs
wobblycogs

Reputation: 4093

JSF EL set string property to null

I have a string field borderColor in a bean that I wan't to set to null using EL but it is always being coerced to an empty string.

<p:inputText value="#{axis.borderColor}" rendered="#{axis.borderColor != null}">
    <p:ajax update=":form:plot"/>
</p:inputText>

<p:commandButton value="#{msg.initialize}" action="#{axis.setBorderColor( 'cccccc' )}" rendered="#{axis.borderColor == null}" update=":form:mainTabs:axesSettings :form:plot"/>
<p:commandButton value="#{msg.reset}" rendered="#{axis.borderColor != null}" update=":form:mainTabs:axesSettings :form:plot">
    <f:setPropertyActionListener target="#{axis.borderColor}" value="#{null}" />
</p:commandButton>

I've read all about javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL and I thought adding that context parameter would fix the problem but it didn't have any effect. It seems the null value being supplied by the setPropertyActionListener is being converted to an empty string for some reason.

I'm using GlassFish 4.0 and PrimeFaces 4.0-SNAPSHOT

Upvotes: 1

Views: 5083

Answers (2)

Luis Rivera
Luis Rivera

Reputation: 68

You don't need pass null value to a property. You can use eq to validate an empty or null string

<p:inputText value="#{axis.borderColor}" rendered="#{not empty axis.borderColor}">
    <p:ajax update=":form:plot"/>
</p:inputText>

Upvotes: 2

Pradeep Pati
Pradeep Pati

Reputation: 5919

You have to do the following setting in your web.xml to force setting null, which doesn't happen by default in JSF2.

<context-param>
    <param-name>javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL</param-name>
    <param-value>true</param-value>
</context-param>

Upvotes: 1

Related Questions