Hello All:
I have a requirement, I need to close the browser tab upon action on the button. But before close the tab it should save the updated values.
I tried with below ways, but none of them worked.
1)using Java script
--Java script
funtion closeWindow(){
window.close();
}
--Button
<af:commandButton
text="Save"
id="cb5" action="#{MyBean.onSave}">
<af:clientListener method="closeWindow" type="action"/>
</af:commandButton>
--Bean
public String onSave() {
DCBindingContainer bindings = (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
OperationBinding operationBinding = bindings.getOperationBinding("Commit");
operationBinding.execute();
return null;
}
In this way its closing the window, but it is unable to save the data.
2)calling java script programmatically
--Java Script
funtion closeWindow(){
window.close();
}
--Button
<af:commandButton
text="Save"
id="cb5" action="#{MyBean.onSave}">
</af:commandButton>
--Bean
public String onSave() {
DCBindingContainer bindings = (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
OperationBinding operationBinding = bindings.getOperationBinding("Commit");
operationBinding.execute();
FacesContext facesContext = FacesContext.getCurrentInstance();
org.apache.myfaces.trinidad.render.ExtendedRenderKitService service = org.apache.myfaces.trinidad.util.Service.getRenderKitService(facesContext, ExtendedRenderKitService.class);
service.addScript(facesContext,closeWindow(); );
return null;
}
Please suggest me how this can be achieved..
Thanks in advance.