Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to Open JSF Page in Separate Browser Window

 
Avi Abrami
Ranch Hand
Posts: 1141
1
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 820
IntelliJ IDE Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1141
1
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 90
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Avi

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


Regards
Cesar
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18094
48
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Avi Abrami
Ranch Hand
Posts: 1141
1
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 18094
48
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic