Parameter is not arriving as null

0

I'm working on internationalizing my messages and centralizing them. I have the following methods:

private static void addMessage(Severity severity, String mensagem, Object...args){
        FacesContext context = FacesContext.getCurrentInstance();
        FacesMessage facesMessage = new FacesMessage(severity, String.format(get(mensagem, args)), "");
        context.addMessage(null, facesMessage);
    }

    public static void addInfoMessage(String chave, Object...args){
        addMessage(FacesMessage.SEVERITY_INFO, chave, args);
    }

    public static void addInfoMessage(String chave){
        addMessage(FacesMessage.SEVERITY_INFO, chave, new Object[]{null});
    }

To try to reuse code I'm trying to pass as null my array of objects. However in the addMessage method an object for my class that is calling addInfoMessage is arriving. Does anyone know why and how do I resolve it?

    
asked by anonymous 18.01.2017 / 17:29

1 answer

1

You are not passing null on method addInfoMessage . You are passing an array of size 1 where the first object is null.

Do this if you want to pass null:

addMessage(FacesMessage.SEVERITY_INFO, chave, null);

But in addition, because the addMessage method has a vargars in the last parameter, you do not need to pass anything and you can do this:

addMessage(FacesMessage.SEVERITY_INFO, chave);
    
23.01.2017 / 06:47