Requirement description:
- In JSPX page we have a table or form where parameters can be entered
- On the same page we have a button. When it is pressed, entered parameters are passed to backing bean method, where based on provided parameters URL string is generated
- Generated URL is opened in Web Browser new tab or window
I have found another solution, it is quite simple and is implemented in my sample - ReportWindow.zip. af:commandButton doesn't have Target property, but h:form does. Submit action of af:commandButton component, placed into h:form with Target property set to _blank, is always executed in new tab or window (depends on Web Browser).
Developed sample implements two h:form components - one is used for parameters and second for button:
Second h:form component property Target is set to _blank:
JSPX page backing bean contains some dummy code for URL generating. URL is opened using ExternalContext obtained from FacesContext:
This code is executed when Open Report button is pressed, URL is generated according to submited parameters. Data available in parameters form should be auto submited, in order to be available from second form where Open Report button is implemented:
Generated URL is opened in new tab:
When running sample application, don't forget to add adf-faces-impl.jar and jsf-impl.jar to application's WEB-INF\lib directory.
12 comments:
it works !
Thank you. You saved so much of my time. I just want to add that it works with trinidad using .
Regards,
Marek
Hi Andrejus,
Consider this case, that I am creating buttons dynamically and adding them as child to the form that you mentioned to create.
Only one of the button has to open up a new browser` window, and rest of them have to give something back to the server.
If I am doing it in this way then for all of them they are opening up a new browser.
I got the issue that for all of them the action on the parent form is to open a new window.
But how to avoid this.
Only one of the button should open the new browser window.
Can you please tell something more on this.
Thanks
Andrejus, good stuff. Do you know how to retrieve host and port of the current web app within backing bean? I'm trying to avoid hardcoding the URL "http://soadev:7301/ ..."
Steve
Thanks Andre...
But somewhere you are setting Target property to _blank..
If one dont want even to do that ...
here is the solution ..
FacesContext fctx = FacesContext.getCurrentInstance();
//String taskflowURL = fctx.getExternalContext().getRequestContextPath() + ProxyPage.PROXY_URL + label;
String taskflowURL = "http://www.google.com";
ExtendedRenderKitService erks = Service.getRenderKitService(fctx, ExtendedRenderKitService.class);
StringBuilder script = new StringBuilder();
script.append("window.open(\"" + taskflowURL + "\");");
erks.addScript(fctx, script.toString());
Hi,
Thanks for update. But its using JavaScript and may not work on all browsers.
Another solution is to use af:goLink component and specify target=_blank
Andrejus
Andrejus,
Is it possible to pass parameters between two different pages for Eg in this case between the report window and the page that has opened the report window when I click some thing on the report window.
Andrejus,
Please let me know one thing,i taken one table and i make first column of entire table is commandLink,so on like each row of command link column i have open new tab with same row parameters as a form..
Many thanks Andrejus
Raja Mallela
Great Stuff.
thanks.
hey andejus thank you for the post, but how to redirect to a webpage on selection of a tab in PanelTabbed-->showdetailitem-->webpage. please help thanks.
sample app is showing blank.
You can download all old samples (prior to 2014) from here - https://code.google.com/archive/p/jdevsamples/downloads
Andrejus
Post a Comment