Saturday, July 14, 2007

Opening Report Window in ADF Faces

Such requirement as opening report window can be assumed as easy one. But, when I have received request for solution, it was not so easy to find it :). On OTN Discussion Forum there are questions on this topic, but no clear answers. Opening report window in ADF Faces is important requirement, because quite often Oracle Reports are needed to be opened from Web application.

Requirement description:
  1. In JSPX page we have a table or form where parameters can be entered
  2. 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
  3. Generated URL is opened in Web Browser new tab or window
Main question here - how to open new tab or window when button is pressed. To implement solution for this requirement, at first I have tried to use JavaScript with binded dynamic parameter for URL generated in backing bean. This solution wasn't suitable, because JavaScript is always executed one step forward comparing to backing bean Java code.

I have found another solution, it is quite simple and is implemented in my sample - 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.


Anonymous said...

it works !

Unknown said...

Thank you. You saved so much of my time. I just want to add that it works with trinidad using .

Anonymous said...

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.


Steve said...

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/ ..."


EMPORiO said...

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 = "";
ExtendedRenderKitService erks = Service.getRenderKitService(fctx, ExtendedRenderKitService.class);
StringBuilder script = new StringBuilder();
script.append("\"" + taskflowURL + "\");");
erks.addScript(fctx, script.toString());

Andrej Baranovskij said...


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


Venkatesh said...


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.

Raja Mallela said...


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

Adosinda said...

Great Stuff.

Anonymous said...

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.

Pankaj said...

sample app is showing blank.

Andrej Baranovskij said...

You can download all old samples (prior to 2014) from here -