voyent
commandLink opening new window  XML
Forum Index -> General Help
Author Message
jmillet

Joined: 06/Jul/2009 00:00:00
Messages: 7
Offline


Hi all,

I am trying to use a commandLink to open a new window. Previously when using Woodstock components all that would have to be done is to set the target attribute correctly, but this did not work with IceFaces.

I found that the solution to this was to use a Javascript call in the backing bean of the page on the actionListener method like this.

Code:
 public void linkActionListener(ActionEvent e){
      JavascriptContext.addJavascriptCall(FacesContext.getCurrentInstance(), "window.open("NewWindow.iface");
 }
 


Obviously the name of the window is a stub. This works fine, but the problem that I am currently having is that the new window does not keep focus, and instead the old window remains at the top. I have tried using the following in my javascript...

Code:
  myWin = window.open("NewWindow.iface"); myWin.focus();
 


but this does not seem to work. Actually, it does seem to work, but something is causing the original page to regain focus.

Can anyone help with this issue?
venu_dvmr

Joined: 30/Sep/2008 00:00:00
Messages: 58
Offline


Try

Code:
 public void linkActionListener(ActionEvent e){
       JavascriptContext.addJavascriptCall(FacesContext.getCurrentInstance(), "window.open('NewWindow.iface', '_blank','')");
  }
 
jmillet

Joined: 06/Jul/2009 00:00:00
Messages: 7
Offline


Thank you for the suggestion, but unfourtunately this does not alter the behavior at all. The second window appears to have focus for a second, then loses it to the original window.

Is there anything that could be causing the IceFaces page to regain focus that I could potentially stop?
venu_dvmr

Joined: 30/Sep/2008 00:00:00
Messages: 58
Offline


Try using Action instead of ActionListiner
jmillet

Joined: 06/Jul/2009 00:00:00
Messages: 7
Offline


venu_dvmr wrote:
Try using Action instead of ActionListiner 


Thanks again for your quick reply, but nothing changes when using Action instead of ActionListener.

Just to be sure we are on the same page, this is the code...

Code:
  public String link_action(){
         JavascriptContext.addJavascriptCall(FacesContext.getCurrentInstance(), "window.open('DisplayMasterListItemDetails.faces', '_blank', '');");
         return null;
     }
 


I previously tried using the action method just as I would in Woodstock, which would be to set the target attribute to _blank and return a proper navigation rule string from the action method, but this did not work with IceFaces. Is that what you were suggesting or was I supposed to use the Javascript like I did above?

EDIT/UPDATE: I decided to try and use a standard h:commandLink and noticed something funny. While updating the navigation rules to try to use with the h:commandLink, I made a typo. When I deployed and clicked the h:commandLink with bad navigation rules, it opened a new window, which kept focus, but due to the bad navigation rule it remained on the initial page. When I fixed the navigation rule, it went to the correct page, but did not open a new window. I really hope this is one of those cases where I'm doing something very simple wrong.
venu_dvmr

Joined: 30/Sep/2008 00:00:00
Messages: 58
Offline


Last try.
Code:
 public String link_action(){
          JavascriptContext.addJavascriptCall(FacesContext.getCurrentInstance(), "window.open('DisplayMasterListItemDetails.faces', '_blank', ''); return false;");
          return null;
      }
 

jmillet

Joined: 06/Jul/2009 00:00:00
Messages: 7
Offline


venu_dvmr wrote:
Last try.
Code:
 public String link_action(){
          JavascriptContext.addJavascriptCall(FacesContext.getCurrentInstance(), "window.open('DisplayMasterListItemDetails.faces', '_blank', ''); return false;");
          return null;
      }
 

 


Thanks again for the help venu, but this doesn't do anything. Literally, adding the return false onto the end results in nothing happening when the link is clicked.

I'm not sure what could be the problem at this point. I've tried many different things and nothing works. Either a new window is opened and it loses focus or the link redirects in the current window. A co-worker with IE 8 installed said that his browser opens a new tab, and it keeps focus, so we might just have to tell our customers to upgrade their browsers.

venu_dvmr

Joined: 30/Sep/2008 00:00:00
Messages: 58
Offline


It is strange!!! it works for us in IE6 & IE7 but we use it little differently we call JS function from the JavascriptContext instead of calling window.open directly.

If your requirement is to simply open a new window then use onclick event instead of using Action or ActionListner.
dsharma

Joined: 03/Dec/2009 00:00:00
Messages: 2
Offline


Set the focus explicitly to newly opened window using the window.focus(
) method.

String propertiesURL = "window.open('" + request.getContextPath() + appResourceBundle.getString("CPPropertiesURL") + "','cpProperties');cpProperties.focus();";
JavascriptContext.addJavascriptCall(FacesContext.getCurrentInstance(),propertiesURL);
 
Forum Index -> General Help
Go to:   
Powered by JForum 2.1.7ice © JForum Team