Evaluate EL in the bean validation message before it is rendered

357 Views Asked by At

I am trying to evaluate validation messages before rendered to UI. The reason for all this I am trying to do is, if i use

@NotEmpty(message="{person.lastName.notNull}")
private String lastName;

In my resource bundle the value for the key is as follows:

Please enter lastname #{account.profile.name.something}

When the input field is validated message displayed as is, i.e. the runtime expression value is not being resolved. I am trying to fill up the commented code in the if loop of the following phase listener.

public Class EvaluateMessageListener implements PhaseListener {

    public PhaseId getPhaseId() {  
        return PhaseId.RENDER_RESPONSE;  
    }

    public void beforePhase(PhaseEvent event) {   
        FacesContext facesContext = FacesContext.getCurrentInstance();  
        List<FacesMessage> messageList = facesContext.getMessageList();  
        if (messageList != null) {  
            //loop through the messagelist,evaluate message and add message to FacesContext
        }  
    }

    public void afterPhase(PhaseEvent event) {
    } 

}

How can I achieve this?

0

There are 0 best solutions below