This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes JSF and the fly likes Opening Multiple Windows from a Single JSF CommandButton click  Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Opening Multiple Windows from a Single JSF CommandButton click  " Watch "Opening Multiple Windows from a Single JSF CommandButton click  " New topic
Author

Opening Multiple Windows from a Single JSF CommandButton click

Mike Brubaker
Greenhorn

Joined: May 24, 2006
Posts: 4
Hi, all,

I have a situation, that I'm not sure is possible and I wanted feedback on. I have a JSF page with a commandButton on it. When the user clicks that button, they want code to execute in the eventhandler class that will generate a PDF file and display that PDF in a new window. They also want a Crystal Report to be run via the Crystal JRC API and have that displayed in a second window. So, in the requirements, on clicking this one button, they expect to have three browser windows open up(one with the original screen, one with a PDF, and one with a Crystal Report viewer). Plus, though, I need to update the main screen to notify the user in the application that some database processing was successful. Is this AT ALL possible or should I tell them to go ride a bike?

Mike Brubaker
leo donahue
Ranch Hand

Joined: Apr 17, 2003
Posts: 327
Hi Mike,

It's possible.

What have you tried so far?

What h:commandButton attributes would help you acheive this? JSF 1.2 tlddocs


Thanks, leo
Mike Brubaker
Greenhorn

Joined: May 24, 2006
Posts: 4
Well, I haven't tried anything yet, because I can't see how it would be done in my mind. What properties of the h:commandButton tag are you referring to?
leo donahue
Ranch Hand

Joined: Apr 17, 2003
Posts: 327
For example, when you click on any HTML anchor element <a>, you can code it to open the link in the same window, or have it open in a separate window using the HTML attribute: target="_blank"

Does h:commandButton have this kind of attribute? No.

What else does it have? It has an "action" attribute. Would that work? Possibly. What about the HTML attributes "onclick" ?

Assuming you already know how to work with the PDF and Crystal Reports APIs, there are several ways to go about opening new browser windows. They either require Javascript or your PDF/Crystal pages to be Servlets accessible via a URL.

My opinion is this sounds like poor design, having one button open two other windows, but, everyone has different opinions.

Recall that when you use the action attribute of a h:commandButton in JSF, you are setting a string value explicitly, or returning a string value from a method binding, used for page navigation.
Mike Brubaker
Greenhorn

Joined: May 24, 2006
Posts: 4
What would be a better design, if you don't mind? It would be a lot easier to have three separate buttons, one to do the DB update, one to generate the PDF and one to run the report, but I'm not sure my users will want to make three mouse clicks. Is that what you are referring to about the poor design? I'm open for any suggestions, believe me.

leo donahue
Ranch Hand

Joined: Apr 17, 2003
Posts: 327
Like I said, that was my opinion.

I'm not a big fan of popping open multiple windows because then your users can leave them open all day. What happens when they leave them open and click that DB update button again for the same record? Now you have 5 windows open? Which window is the now current PDF/Crystal report?

I don't know your requirements and I don't need to, I was just giving my opinion based on what I read.
leo donahue
Ranch Hand

Joined: Apr 17, 2003
Posts: 327
You could have an "onclick" function, in addition to your action, for your command button that uses Javascript to open the other two windows.

I've also read where the navigation action of the button opens a page that has Javascript in the body onload() event that opens the other two windows and closes itself.

Or, your button could navigate to the PDF page, which has Javascript in it's body onload() event to open the Crystal page, vice versa.

Or, your button could navigate to a page that contains two frames, one frame has the PDF the other frame has the Crystal report. That's not 3 pages though, maybe your users will complain about efficiency?

All of these seem like they would do the same thing.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15629
    
  15

HTTP is based on the Request/Response paradigm. One request results in one response.

To open multiple windows (which won't work on my browser because I have it set to open tabs instead), you'd need multiple requests in order to get the different responses, one per window.

To do that you'll need to do it at the client side via a JavaScript function, since - like I said, one request, one response. HTTP doesn't permit a server to "volunteer" output, whether you're using JSF or not.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Opening Multiple Windows from a Single JSF CommandButton click
 
Similar Threads
Printing Crystal Rpt on client side in ASP pg
information required JSP page integration
crystal report and java
Java & Crystal report
Creating the crystal reports from Java