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

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

From: Michael Müller <michael.mueller_at_mueller-bruehl.de>
Date: Mon, 16 May 2016 13:58:18 +0200

+1

Herzliche Grüße - Best Regards,

Michael Müller
Brühl, Germany
blog.mueller-bruehl.de <http://blog.mueller-bruehl.de/>
it-rezension.de <http://it-rezension.de/>
@muellermi


Read my books
"Web Development with Java and JSF": https://leanpub.com/jsf
"Java Lambdas und (parallel) Streams" Deutsche Ausgabe:
https://leanpub.com/lambdas-de
"Java Lambdas and (parallel) Streams" English edition:
https://leanpub.com/lambdas

On 13.05.2016 15:09, Kito Mann wrote:
> +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 <http://virtua.tech>
> JSFCentral.com <http://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
> <mailto: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
>
>
>
>
>