title: Work around for faulty INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL in Mojarra JSF 2.1
body: <p>I know there are a number of posts about converting empty string to null in JSF2. The usual prescription is to add the following to web.xml.</p>
  
  <pre><code>&lt;context-param&gt;
    &lt;description&gt;Does not appear to work&lt;/description&gt;
    &lt;param-name&gt;javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL&lt;/param-name&gt;
    &lt;param-value&gt;true&lt;/param-value&gt;
  &lt;/context-param&gt;
  </code></pre>
  
  <p>This just does not seem to work - at all. I then created a custom string converter to test if that would work. I explicitly added it as a converter to my inputText (otherwise it does not fire when blank). </p>
  
  <p>When INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL is set to true the converter receives null and the setter for the input text still receives "". </p>
  
  <p>When INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL is set to false (or commented out) the converter receives "" and the setter for the input text receives "" (even after the converter returns null).</p>
  
  <pre><code>@FacesConverter(forClass=java.lang.String.class, value="emptyStringToNull")
  public class StringConverter implements Converter, Serializable {
      private static final long serialVersionUID = -1121162636180944948L;
      public Object getAsObject(FacesContext context, UIComponent component, String value) {
          if (value == null || value.trim().isEmpty()) {
              return null;
          }
          return value;
      }
  
      public String getAsString(FacesContext context, UIComponent component, Object object) {
      if (object == null)
          return null;
  
      return object.toString();
      }
  }
  </code></pre>
  
  <p>I've event tried (to no avail) to explicitly set the component submitted value in getAsObject:</p>
  
  <pre><code>if (component instanceof EditableValueHolder)
      ((EditableValueHolder) component).setSubmittedValue(null);
  </code></pre>
  
  <p>I'm using JBoss6 (a snapshot of 6.1 really) and JSF 2.1.1.</p>