The best place to ask programming/development questions, imo. UPDATE: stackoverflow is the *worst* place to *ask* questions (if your first question/comment doesn't get any up-rating/response, then u can't ask anymore questions--ridiculously unrealistic), but a great reference for finding answers.

My Music (Nickleus)

20140304

web.xml jsf setting to treat empty string values in form submit as null so they're not saved in the database, but also comply with notnull constraints

the following setting in web.xml is quite useful:

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

...

which means that when a user submits a form then no empty fields of type string will get saved in the database. having it set to true will also force compliance with @NotNull constraints, with regards to validation.

on a related note, there's a jboss startup setting called org.apache.el.parser.COERCE_TO_ZERO, which when set to true (default) will turn number field form values of "" (empty string) and null into the number 0 (zero) before the form is submitted, e.g.:

-Dorg.apache.el.parser.COERCE_TO_ZERO=true

setting it to false would mean that empty strings and null values for number fields in forms will be submitted "as is" and NOT get converted to the number 0.

No comments:

Post a Comment