[
https://issues.jboss.org/browse/AS7-5310?page=com.atlassian.jira.plugin.s...
]
Stan Silvert commented on AS7-5310:
-----------------------------------
javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL actually is honored and is
working as per the spec. I can't get into the support system, so I can't see the
comments you are referring to.
Here is a long explanation. Section 11.1.3 of the JSF spec says:
If the javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL context parameter value
is true (ignoring case), and UIInput.getSubmittedValue() returns a zero-length String
call
UIInput.setSubmittedValue(null) and continue processing using null as the current
submitted value.
This is indeed being done. However, when UIInput.updateModel() is called, that triggers
the EL Evaluation, which will coerce the value based on its expected type. If it sees
that the expected type is a String then it will convert a null to empty string. So
eventually, your managed bean will be set with empty string instead of null. That
behavior is governed by the EL spec.
I assume that your managed bean is expecting an attribute of type String. So the solution
is to change the expected type of your managed bean from String to Object. I have a
managed bean that demonstrates this:
{code:xml}
<f:view>
<h:form id="myform">
<h3><h:inputText id="myvalue"
value="#{myBean.value}"/></h3>
<h:commandButton value="Submit"/>
</h:form>
</f:view>
{code}
{code}
@ManagedBean
public class MyBean {
private static final String EMPTY_STRING_AS_NULL =
"javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL";
private Object value;
public void setValue(Object value) {
System.out.println("MyBean value=" + value);
System.out.println("MyBean value==null? " + (value == null));
if (value != null) System.out.println("MyBean value==''? " +
value.equals(""));
String val =
FacesContext.getCurrentInstance().getExternalContext().getInitParameter(EMPTY_STRING_AS_NULL);
System.out.println("MyBean context param=" + val);
System.out.println("MyBean value from component=" +
getValueFromComponent());
this.value = value;
}
private Object getValueFromComponent() {
FacesContext ctx = FacesContext.getCurrentInstance();
UIInput input =
(UIInput)ctx.getViewRoot().findComponent("myform:myvalue");
return input.getValue();
}
public Object getValue() {
return this.value;
}
}
{code}
Output:
{noformat}
11:24:04,790 INFO [stdout] (http-/127.0.0.1:8080-1) MyBean value=null
11:24:04,792 INFO [stdout] (http-/127.0.0.1:8080-1) MyBean value==null? true
11:24:04,794 INFO [stdout] (http-/127.0.0.1:8080-1) MyBean context param=true
11:24:04,797 INFO [stdout] (http-/127.0.0.1:8080-1) MyBean value from component=null
{noformat}
Now, in the code above change the type of the attribute from Object to String. Even
though JSF correctly set the value of the component to null, EL will coerce the value to
empty string before calling the setter on the managed bean:
{noformat}
11:44:47,476 INFO [stdout] (http-/127.0.0.1:8080-1) MyBean value=
11:44:47,478 INFO [stdout] (http-/127.0.0.1:8080-1) MyBean value==null? false
11:44:47,481 INFO [stdout] (http-/127.0.0.1:8080-1) MyBean value==''? true
11:44:47,483 INFO [stdout] (http-/127.0.0.1:8080-1) MyBean context param=true
11:44:47,486 INFO [stdout] (http-/127.0.0.1:8080-1) MyBean value from component=null
{noformat}
javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL not
honored
-----------------------------------------------------------------------
Key: AS7-5310
URL:
https://issues.jboss.org/browse/AS7-5310
Project: Application Server 7
Issue Type: Bug
Components: JSF
Affects Versions: 7.1.2.Final (EAP)
Reporter: Michael Locher
Assignee: Stan Silvert
The javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL params seems not to be
working on EAP 6:
<context-param>
<param-name>javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL</param-name>
<param-value>true</param-value>
</context-param>
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:
https://issues.jboss.org/secure/ContactAdministrators!default.jspa
For more information on JIRA, see:
http://www.atlassian.com/software/jira