Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Is possible to open a popup JSF from a Managed Bean?

 
Edson Cezar
Ranch Hand
Posts: 119
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I use this code for open a popup in JavaScript:



But, I want to do it from a Managed Bean, is it possible ?

Example, I have the following condition, from a p:dataTable:



I want to call a Managed Bean and open a popup through it, is it possible ?



Thanks in advance !
 
Tim Holloway
Bartender
Posts: 18422
60
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please don't.

If I visit your website and it starts popping up new windows (or, on my browser, tabs), I will immediately leave it. The only way to chase me away faster is to put self-playing multimedia on it.

JSF is not particularly friendly to working with multiple windows in any event.

Some of the JSF tags do support a "target" attribute that can be used to target a new (or alternative) window/tab just like in regular HTML, but since HTTP doesn't support automated co-ordination of their contents, neither does JSF. And since a lot of JSF is involved with extended editing of forms, that can lead to complications.
 
Jason Jia
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. Use requestContext to execute client side javascript from managedBean, e.g.

RequestContext requestContext = RequestContext.getCurrentInstance();
requestContext.execute("showMyPage()");

2. Somehow I feel you are looking at a wrong direction. If the dialog's content are related to the parent window, then you should use dialog framework of PrimeFaces which could open a pre-defined JSF page as dialog window, also could pass object between them. Show case has good example : http://www.primefaces.org/showcase/ui/df/basic.xhtml
 
Tim Holloway
Bartender
Posts: 18422
60
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jason Jia wrote:
1. Use requestContext to execute client side javascript from managedBean, e.g.


I don't think so. ManagedBeans are on the server. Javascript is on the client. HTTP (not JSF) does not support a server initiating action on a client. Only clients doing request/response cycles against the server.

On the other hand, I also vote for dialogs over popups.
 
Jason Jia
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Holloway wrote:
I don't think so. ManagedBeans are on the server. Javascript is on the client. HTTP (not JSF) does not support a server initiating action on a client. Only clients doing request/response cycles against the server.

On the other hand, I also vote for dialogs over popups.


Hi Tim,

Your are right, they won't initiate request/response cycle on server side. But this RequestContext are implemented by PrimeFaces and I think it's probably executed through some kinds of ajax call. So the managebean could call javascripts on client side. (Yes, should use action listener instead of action ).

see the demo here: http://www.primefaces.org/showcase/ui/misc/requestContext.xhtml

I also have a demo for how to pop up a dialog and return value see here: http://showcase-tiefaces.rhcloud.com/showcase/common/TableLookup.xhtml at popup window with lookup part.

Thanks
Jason
 
Edson Cezar
Ranch Hand
Posts: 119
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot for all, it was really helpful !
 
Won't you be my neighbor? - Fred Rogers. tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!