Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Raghu Sundar
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="this.form.target='_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.







 
Tim Holloway
Bartender
Posts: 18662
71
Android Eclipse IDE Linux
  • 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 workSpaceBean.target 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!