aspose file tools*
The moose likes JSF and the fly likes How to Open JSF Page in Separate Browser Window Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "How to Open JSF Page in Separate Browser Window" Watch "How to Open JSF Page in Separate Browser Window" New topic
Author

How to Open JSF Page in Separate Browser Window

Avi Abrami
Ranch Hand

Joined: Oct 11, 2000
Posts: 1135

In one JSF page I have a command button (h:commandButton).
I would like to open a different JSF page in a separate browser window when clicking on the button.
How do I accomplish this?

Thank you.
Tim McGuire
Ranch Hand

Joined: Apr 30, 2003
Posts: 820

If it is submitting a form, make the form target = "_blank"
Or... put an attribute that calls javascript to open a new window.
Avi Abrami
Ranch Hand

Joined: Oct 11, 2000
Posts: 1135

Thank you Tim.
I tried javascript but it didn't work.
My guess to why it didn't work is because javascript runs in the Web browser only and hence the JSF lifecycle was not invoked.
I will try your other suggestion, but actually I have several buttons on the JSF page and I would like to open different windows depending on the button pushed. I will test whether your other suggestion can handle this situation.

Cheers,
Avi.
Cesar Loachamin
Ranch Hand

Joined: Dec 25, 2010
Posts: 90

Hi Avi

You can use javascript to open a new window, I give a example:


Regards
Cesar


When a dream is ending because to come true - OCPJP 6,7. OCE JPA EE6. MCTS
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16250
    
  21

I don't think commandButton supports the "target" attribute, but you can code a commandLink and wrap it with graphics that make it look like a button.

However, before you go crazy with pop-up windows, I feel obliged to point out that some of us user-types absolutely HATE pop-up windows, and not only do we not pop up (my browser is set to ipen a new tab, instead), but we have been known to take extreme measures to avoid pop-ups. Like take our business elsewhere.

Everything has its place, of course, including pop-ups, and even Flash. However, there are alternatives that are often as good or better. I've got an app that uses a lot of pop-up dialogs, for example. They appear within their parent windows as overlays instead of opening a new frame/tab. They're very easy to do using RichFaces JSF.


Customer surveys are for companies who didn't pay proper attention to begin with.
Avi Abrami
Ranch Hand

Joined: Oct 11, 2000
Posts: 1135

Cesar,
Thank you for your sample code.
As I stated in my reply to Tim McGuire, I tried using javascript but it didn't work for me because javascript executes on the client side.
In your example, does TestBean.xhtml contain JSF code?
If so is the JSF code executed before the window is displayed?

Tim (Holloway),
Thank you for the advice.
Could you direct me to some sample code detailing how to open a popup dialog that appears within the parent window as an overlay?

Cheers,
Avi.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16250
    
  21

Avi Abrami wrote:Cesar,
Thank you for your sample code.
As I stated in my reply to Tim McGuire, I tried using javascript but it didn't work for me because javascript executes on the client side.
In your example, does TestBean.xhtml contain JSF code?
If so is the JSF code executed before the window is displayed?

Tim (Holloway),
Thank you for the advice.
Could you direct me to some sample code detailing how to open a popup dialog that appears within the parent window as an overlay?

Cheers,
Avi.


http://livedemo.exadel.com/richfaces-demo/richfaces/modalPanel.jsf?c=modalPanel&tab=usage

Also check out the IceFaces and PrimeFaces extension tagsets. I think both of them have something similar.
 
 
subject: How to Open JSF Page in Separate Browser Window