Reputation: 4093
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>
borderColor
is null I display an "Initialize" button. borderColor
is not null I display a text field where the user can type in a CSS color and a "Reset" button. When the reset button is pressed I want to set the borderColor back to null (I'm actually using the PrimeFaces p:colorPicker rather than a text field but the problem is the same).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
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
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