Parameter is not coming as null

Asked

Viewed 66 times

0

I am working on the internationalization of my messages and their centralization. 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 repurpose code I’m trying to pass as null my object array. However in the method addMessage is coming an object referring to my class that calls the addInfoMessage. Does anyone know why and how I solve?

  • If you put a new Exception("Teste").printStackTrace(); in his method addMessage, what appears?

  • Using cast making addMessage(Facesmessage.SEVERITY_INFO, key, (Object[]) null);

1 answer

1


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

Do so if you want to pass null:

addMessage(FacesMessage.SEVERITY_INFO, chave, null);

But beyond that, as the method addMessage has a vargars in the last parameter, you do not need to pass anything and can do so:

addMessage(FacesMessage.SEVERITY_INFO, chave);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.