This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Grokking Bitcoin and have Kalle Rosenbaum on-line!
See this thread for details.
Win a copy of Grokking Bitcoin this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Tim Cooke
  • Junilu Lacar
  • Paul Clapham
  • Devaka Cooray
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Frits Walraven
  • Carey Brown
  • salvin francis
  • Claude Moore

To open JSF web page in new window for selected options  RSS feed

Ranch Hand
Posts: 40
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am selecting different options from JSF selectonemenu and doing certain operations on click of command button.I want to open a different web page in new window for only one option and for remaining options i only do some background operation and want to stay in the same page.Here onclick="'_blank'" is getting applied to all other options and displaying same page in the new window.How can i avoid this and display new window for only one option.

My JSF page snippet

I want to display new window only for Edit Coverage.

My Managed bean snippet which is of request scope.

Saloon Keeper
Posts: 20643
Android Eclipse IDE Java Linux Redhat Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the JavaRanch, Rakshith!

Actually, as a user, I hate pop-up windows (or in my case, tabs, since I have my browser set to open new windows as tabs).

Regardless of my personal preferences, however, JSF isn't really designed to work well with multiple windows/tabs.

Nevertheless, you can do so (at your own risk!). I believe in your particular case, it's a simple matter of changing your commandButton a bit.

First, change the commandButton to a commandLink. CommandLink has support for "target", as does its corresponding HTML tag (the "a" tag). CommandButton does not, since an HTML SUBMIT button does not.

Instead of a JavaScript "onclick", code an EL expression:

Make the workSpaceBean submit() method set the property as needed for the value of workSpaceBean.selectedItem that had been set by JSF before it invoked workSpaceBean.submit

Incidentally, you may find it cleaner (and safer) to construct an array or List of SelectItems in your backing bean and using the f:selectItems element. That will simplify the View Template a bit:

Note that you can make the commandLink look like a commandButton by being creative with CSS options. That way you get the functionality of a link and the appearance of a button.
Raghu Sundar
Ranch Hand
Posts: 40
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Tim. The suggestion you gave works when i hard code target value in command link.But for my actual requirement as i mentioned before,the application is reading null first and hence opening the outcome in the same page irrespective of any of the target value i set.

i am using switch statement inside submit method to check options,which is as below

I have declared setter and getter for target variable before.The managed bean is of request scope.
I am newbie to JSF. Is there any way where i can read the selected value and set the target property at server side(preferably)or client side before submit method so that i can display the outcome accordingly.
Montana has cold dark nights. Perfect for the heat from incandescent light. Tiny ad:
Create Edit Print & Convert PDF Using Free API with Java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!