Sharing Controller Context with a Visualforce Popup

June 17th, 2010

“How do I popup a dialog in Visualforce”.

I’m not sure what the deal is but this week I’ve received 3 emails asking me how to open a Visualforce popop window from a Visualforce page but both running in the same session. The question is asked fairly often on the message boards but there isn’t a native solution.

The use case is that you have a Visualforce page with a commandbutton that launches a Visualforce popup. You want the popup to be able to access the controller’s context so you can share state. Unfortunately this is not currently possible with Visualforce and Apex. Opening a new window will start a new request which initializes a new instance of the controller. You could pass some variables to the new controller via Javascript but making a callback to the opening Visualforce is tedious as best.

Depending on what your popup needs to do, the best solution might be to create a modal instead of a new Visualforce page. Dave Carroll has a great article titled, “Modal Dialogs in Visualforce using the Yahoo! User Interface Library“, that shows how to use an In-Page DIV or Hidden DIV to create the modal. You can probably accomplish the same effect with other libraries but Dave’s solution with YUI! is straight-forward, simple and well documented.


VN:F [1.9.3_1094]
Rating: 8.0/10 (1 vote cast)
VN:F [1.9.3_1094]
Rating: 0 (from 0 votes)
Sharing Controller Context with a Visualforce Popup, 8.0 out of 10 based on 1 rating
Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay

Categories: Salesforce, Visualforce

Leave a comment

Leave a comment

Feed

http://blog.jeffdouglas.com / Sharing Controller Context with a Visualforce Popup

WordPress Appliance - Powered by TurnKey Linux