Open public URL programatically using javascript in ADF
Scenario: Suppose you want to open some public URL like www.google.com programatically from you ADF application.
Write the following code in bean on Action event.
public void openURL(ActionEvent actionEvent) {
openUrlInNewWindow("http://www.google.com");
}
private void openUrlInNewWindow(String url) {
if (url != null) {
String javaScriptText =
"window.open('" + url + "', 'Window', 'menubar=yes,location=yes,resizable=yes,scrollbars=yes,status=yes');";
writeJavaScriptToClient(javaScriptText);
}
}
public static void writeJavaScriptToClient(String script) {
FacesContext fctx = FacesContext.getCurrentInstance();
ExtendedRenderKitService erks = Service.getRenderKitService(fctx, ExtendedRenderKitService.class);
erks.addScript(fctx, script);
}
Write the following code in bean on Action event.
public void openURL(ActionEvent actionEvent) {
openUrlInNewWindow("http://www.google.com");
}
private void openUrlInNewWindow(String url) {
if (url != null) {
String javaScriptText =
"window.open('" + url + "', 'Window', 'menubar=yes,location=yes,resizable=yes,scrollbars=yes,status=yes');";
writeJavaScriptToClient(javaScriptText);
}
}
public static void writeJavaScriptToClient(String script) {
FacesContext fctx = FacesContext.getCurrentInstance();
ExtendedRenderKitService erks = Service.getRenderKitService(fctx, ExtendedRenderKitService.class);
erks.addScript(fctx, script);
}
Comments
Post a Comment