Thursday, November 17, 2011

Resetting values in popup ADF 11g

If you are using ADF11g version 11.1.1.3 and want to reset the values in the popup, you are not provided with the resetEditableValues option. But you can accomplish this using a custom javascript that i have made.

All you have to do is set clientComponent="true" for all the components that you want to reset and pass the client id of the root component to use this.

resetAction=function(clientId){
var component= AdfPage.PAGE.findComponentByAbsoluteId(clientId);
console.log(component);
var components=component.getDescendantComponents();
this.resetFunction(components);
}
resetFunction=function(components){
for (var i=0;i<components.length;i++){
if(components[i] instanceof AdfRichInputText){
if(components[i].getVisible()&&!components[i].getDisabled()&&!components[i].getReadOnly()){
components[i].setValue("");
}
}
if(components[i] instanceof AdfRichSelectOneChoice){
if(components[i].getVisible()&&!components[i].getDisabled()&&!components[i].getReadOnly()){
components[i].resetValue();
}
}
}
}


Save the contents of this file to a JS file and then import it in your fragment or a jsf page.

Now you have to bind the parent container like panelFormLayout and then on action of the command button use ExtendedRenderKitService to pass the client id of the root component dynamically to resetAction Method so that this script always works. The snippet is shown below.

/**
* Resets the popup
* @return null
*/
public String resetPopupAction() {
FacesContext context = FacesContext.getCurrentInstance();
ExtendedRenderKitService erks =
Service.getRenderKitService(context, ExtendedRenderKitService.class);
erks.addScript(context,"resetAction('"+formBinding.getClientId(context) +"')");

return null;
}


Hope this will be helpful :D