requestContext.execute("window.open(....);"); not working

UI Components for JSF
Post Reply
tkernstock
Posts: 65
Joined: 29 Jun 2010, 14:39
Location: Vienna, Austria

18 Aug 2016, 12:44

Hi All,

I try to to open a window with context.execute.

In my viewbean I have the folloing code. When I execute this method with a commandlink action the alert shows but not the new window.

Code: Select all

<p:commandLink value="Open Window" action="#{applicationPage.openWindow()}" oncomplete="PF('dlg1').show()" immediate="true" >
</p:commandLink>

Code: Select all

	public void openWindow(){
		RequestContext context = RequestContext.getCurrentInstance();
		context.execute("window.open('http://www.orf.at');");
		context.execute("alert('http://www.orf.at');");
	}
When I do the same with onklick in the jsf file it works and the window opens:

Code: Select all

<p:commandLink value="Open Window" onclick="window.open('http://www.orf.at')"
					oncomplete="PF('dlg1').show()" immediate="true" >
</p:commandLink>
Is there a restriction for opening windows with execute?

I'm using Payara 4.1.1.162, Primefaces 6.0, Deltaspike 1.6 and Firefox 48/Chrome 52

br
Thomas
Last edited by tkernstock on 22 Aug 2016, 14:29, edited 1 time in total.
Using: Eclipse 2020-06, Java 8, Primefaces 8, Omnifaces 3.6.1, Payara Server 5.201, Deltaspike 1.8.2

smokeybandit
Posts: 277
Joined: 08 Jul 2013, 17:53

18 Aug 2016, 15:33

If all you want to do is open a new window, then I'd just use straight HTML

tkernstock
Posts: 65
Joined: 29 Jun 2010, 14:39
Location: Vienna, Austria

18 Aug 2016, 16:13

smokeybandit wrote:If all you want to do is open a new window, then I'd just use straight HTML
No, that's not all I want to do. This ist just a simple example.

I would like to open a window automatically with a mailto: link that contains emailaddress, subject and body. These values should be read by the backing bean before the context.execute.
Using: Eclipse 2020-06, Java 8, Primefaces 8, Omnifaces 3.6.1, Payara Server 5.201, Deltaspike 1.8.2

Miguel Cubells
Posts: 99
Joined: 25 Feb 2015, 11:02

30 Aug 2016, 06:42

Try using actionListener instead

Code: Select all

<p:commandLink value="Open Window" 
actionListener="#{applicationPage.openWindow()}" 
oncomplete="PF('dlg1').show()" 
immediate="true" />
PrimeFaces 6.1 / PF Extensions 6.1.1 / Atmosphere 2.4.3
Apache Mojarra 2.2.13+
WildFly 10.1.0.Final

tandraschko
PrimeFaces Core Developer
Posts: 3979
Joined: 03 Dec 2010, 14:11
Location: Bavaria, DE
Contact:

30 Aug 2016, 09:31

Could be a security thing in the browser ;)
Thomas Andraschko

PrimeFaces | PrimeFaces Extensions

Apache Member | OpenWebBeans, DeltaSpike, MyFaces, BVal, TomEE

Sponsor me: https://github.com/sponsors/tandraschko
Blog: http://tandraschko.blogspot.de/
Twitter: https://twitter.com/TAndraschko

tkernstock
Posts: 65
Joined: 29 Jun 2010, 14:39
Location: Vienna, Austria

29 Sep 2016, 12:53

Miguel Cubells wrote:Try using actionListener instead

Code: Select all

<p:commandLink value="Open Window" 
actionListener="#{applicationPage.openWindow()}" 
oncomplete="PF('dlg1').show()" 
immediate="true" />
Dear Miguel,

thank you for your answer. Unfortunately your solution doesn't work either. The alert window opens but not the dialog. :|

best regards
Thomas
Last edited by tkernstock on 29 Sep 2016, 13:33, edited 1 time in total.
Using: Eclipse 2020-06, Java 8, Primefaces 8, Omnifaces 3.6.1, Payara Server 5.201, Deltaspike 1.8.2

tkernstock
Posts: 65
Joined: 29 Jun 2010, 14:39
Location: Vienna, Austria

29 Sep 2016, 13:16

tandraschko wrote:Could be a security thing in the browser ;)
I tried also in Chrome, but didn't work.

If it was a security thing, wouldn't the pure script version with

Code: Select all

<p:commandLink value="Open Window" onclick="window.open('http://www.orf.at')"
               oncomplete="PF('dlg1').show()" immediate="true" >
</p:commandLink>
fail too? In the end both methods should do the same - open a window with Javascript. Or am I wrong?

best
Thomas
Using: Eclipse 2020-06, Java 8, Primefaces 8, Omnifaces 3.6.1, Payara Server 5.201, Deltaspike 1.8.2

tandraschko
PrimeFaces Core Developer
Posts: 3979
Joined: 03 Dec 2010, 14:11
Location: Bavaria, DE
Contact:

29 Sep 2016, 14:05

nope. Onclick mostly works as the user triggers it.
So it's probably a security thing to provent popups.
Thomas Andraschko

PrimeFaces | PrimeFaces Extensions

Apache Member | OpenWebBeans, DeltaSpike, MyFaces, BVal, TomEE

Sponsor me: https://github.com/sponsors/tandraschko
Blog: http://tandraschko.blogspot.de/
Twitter: https://twitter.com/TAndraschko

tkernstock
Posts: 65
Joined: 29 Jun 2010, 14:39
Location: Vienna, Austria

29 Sep 2016, 15:41

tandraschko wrote:nope. Onclick mostly works as the user triggers it.
So it's probably a security thing to provent popups.
Hi Tandraschko,

I think you are right. I tried calling the same scriptmethod directly with a buttonclick and with requestContext.execute. The script is executed in both cases. I guess the reason why is described here: http://stackoverflow.com/questions/9514 ... ult-is-set

I also tried in IE with a deactiavted Popupblocker and here I get a security warning. Ignoring it opens the Mailwindow.

So thank you for your tipp, you where completely right!

best
Thomas
Using: Eclipse 2020-06, Java 8, Primefaces 8, Omnifaces 3.6.1, Payara Server 5.201, Deltaspike 1.8.2

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 47 guests