Pages

Wednesday, July 27, 2016

Add/Remove af:messages on a component using javascript

In one of my project, I had a requirement to add & remove af:messages from input components. In this post, I will show the javascript code used to achieve it.
 

For adding af:message to an input component using java script, use the following code.

function customJSMethod(evt){
       var source = evt.getSource();
       var inputComponent = source.findComponent('inputcompId’);
       var message = “Valiation Failing…”;...//Custom message to be added on component.
       AdfPage.PAGE.addMessage(inputComponent.getClientId(), new AdfFacesMessage(AdfFacesMessage.TYPE_ERROR, null, message));
       AdfPage.PAGE.showMessages(inputComponent.getClientId());
}

For removing af:message from an input component using java script, use the following code.

function customJSMethod(evt){
    var source = evt.getSource();
    var inputComponent = source.findComponent('inputcompId’);....
    AdfPage.PAGE. clearMessages (inputComponent.getClientId());
    AdfPage.PAGE.showMessages(null);
}