Call custom JavaScript method during component initialization

If you need to invoke custom Java Script method during some specific UI(ADF Faces) component initialization, then this post is for you. Idea is to use ClientListenerSet::addBehavior(javax.el.ValueExpression) to associate a deferred value expression (referring a JavaScript method) with the UI component, which will be evaluated later when DOM is rendered on the page. Thanks to Gary Van Matre who shared this idea in an internal discussion forum

public void setSomeInputField(RichInputText inpField) {
this.inputField = inpField;
ClientListenerSet clientListenerSet = inputField.getClientListeners();
if (clientListenerSet == null) {
clientListenerSet = new ClientListenerSet();
clientListenerSet.addBehavior("new CustomCompBehavior()");
inputField.setClientListeners(clientListenerSet);
}
}

Download

You can download the sample workspace from here.
[Runs with Oracle JDeveloper 11g R1 PS4(11.1.1.5.0)]

Comments