JSF Mini Book – Tips, concepts and good practices

How to receive null value from the view

Good development practices say: “avoid passing null values inside your application”; following this good practice we will be reducing the possibility of the famous NullPointerException. By default the JSF will handle all requests parameters to be not null. An integer will be equals to zero, a Boolean to false and a String will be “” (empty but not null).

If the business rule is to receive null instead some default value, there is a way to notify the JSF to do not provide the default values. The first step is to add the configuration below to the web.xml file.

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

If the application is running in the Glassfish container just the configuration above will complete the task. If the application is running in the Tomcat/JBoss, this configuration alone will not be enough to bring the value as null. This happens because the Tomcat/JBoss will ignore the configuration. To force the container to “respect” the configuration add the following configuration to the container JVM: -Dorg.apache.el.parser.COERCE_TO_ZERO=”false”. The Tomcat/JBoss will keep the empty value as null and will not provide the default JSF values.

12 Thoughts on “JSF Mini Book – Tips, concepts and good practices

  1. Really good material. Thanks very much…

  2. Thank you very much !!!

  3. This Post is Awesome. Followed every things and applied on my project.

  4. very usefull material, Keep up the good work

  5. Really cool material! I agree with Tim. If this could be distributed in pdf format, you will become a little more famous. :) Thanks, good job!

  6. This is awesome! Could you post the entire article as a PDF for download??

Leave a Reply

Post Navigation