syntax_highlight

вторник, 5 июня 2012 г.

JSF open in other browser window

There are situations when there is a demand to open the link in another browser window.
How can we do this in HTML is simple:
<a href="http://mysite.com/page?id=442" target="_blank">Open post</a>
in JSF the analog code will be:
<h:outputLink value="http://mysite.com/page" target="about:blank">
  <f:param name="id" value="#{bbean.pageid}"/>
  <h:outputText value="Open post" />
</h:outputLink>
where <param> elements are used to produce request parameters.

Ok, now lets consider that you want to open a new browser window just after submitting and navigating to other JSF page. For example to open generated PDF in this page. What can be done here? Something shoud perform HTTP request. JavaScript to the rescue!
<h:outputScript>
  window.open('about:blank', 'PDF');
  window.open('/pdf?#{bbean.pdfId}=31&amp;type=#{bbean.pdfType}', 'PDF');
</h:outputScript>
put this script on the navigating page. As JSF will render this page, the script will be executed and popup page will appear.
If you wish to use parameters, don't forget to escape HTML special characters. ( & --> &amp; )

Just remember that popups are very NOT user-friendly, try to avoid them.

Комментариев нет:

Отправить комментарий