jsr372-experts@javaserverfaces-spec-public.java.net

[jsr372-experts] Re: [jsr372-experts mirror] Null safe converters/validators?

From: Kito Mann <kito.mann_at_virtua.com>
Date: Fri, 13 May 2016 09:09:39 -0400

+1

___

Kito D. Mann | @kito99 | Author, JSF in Action
Web Components, Polymer, JSF, PrimeFaces, Java EE, and Liferay training and
consulting
Virtua, Inc. | virtua.tech
JSFCentral.com | @jsfcentral | knowesis.io
<http://knowesis.io/web/webcomponents> - fresh Web Components info
+1 203-998-0403

* Listen to the Enterprise Java Newscast: *http://
<http://blogs.jsfcentral.com/JSFNewscast/>enterprisejavanews.com
<http://ww.enterprisejavanews.com>*


On Fri, May 13, 2016 at 7:06 AM, arjan tijms <arjan.tijms_at_gmail.com> wrote:

> Hi,
>
> In practice, what we often do in Converters and Validators is something
> like the following:
>
> @FacesConverter("toLowerCaseConverter")
> public class ToLowerCaseConverter implements Converter<String> {
>
> @Override
> public String getAsObject(FacesContext context, UIComponent component,
> String value) {
> if (value == null) {
> return null;
> }
>
> return value.toLowerCase(getLocale());
> }
>
> @Override
> public String getAsString(FacesContext context, UIComponent component,
> String value) {
> return value;
> }
>
> }
>
> The null check is pretty repetitive.
>
> What about:
>
> @FacesConverter("toLowerCaseConverter", nullSafe= true)
> public class ToLowerCaseConverter implements Converter<String> {
>
> @Override
> public String getAsObject(FacesContext context, UIComponent component,
> String value) {
> return value.toLowerCase(getLocale());
> }
>
> @Override
> public String getAsString(FacesContext context, UIComponent component,
> String value) {
> return value;
> }
>
> }
>
> The nullSafe=true would let the runtime do the == null return null thing
> (for both methods, the example only shows one).
>
> Thoughts?
>
> Kind regards,
> Arjan Tijms
>
>
>
>
>