Open a new window in a4j: commandButton

Using A4J, Richfaces in a web application, I need to open a new browser window when the user clicks on <a4j:commandButton> .

I think I will have to use window.open(URL, ...) . Where should I put this?

My <a4j:commandButton> looks like this:

 <a4j:commandButton id="elementDetailsButton" onclick="if (!confirm('Are you sure? Unsaved data will be lost')) { return false; }" action="#{myBean.elementDetailsAction}" value="Element Details"> <a4j:actionparam name="elementDetailsString" value="getElementDetails()" assignTo="#{myBean.elementDetails}" noEscape="true"> </a4j:actionparam> </a4j:commandButton> 
+6
javascript ajax richfaces ajax4jsf
source share
2 answers

You can confirm window.open and not return false

 <a4j:commandButton id="elementDetailsButton" onclick="if (confirm('Are you sure? Unsaved data will be lost')) { window.open(URL, ...) } else { return false }" (...) /> 

"Else" is optional, possibly optional.

Or you can change the purpose of the form. I don’t remember very well if this is the correct syntax ...

 <a4j:commandButton id="elementDetailsButton" onclick="this.form.taget='_blank'" (...) /> 

... or something like that.

Changing the purpose of the form will give you a good problem. The rest of the application will focus on a new window. To solve this problem, I did <h:commandLink/> to close the window (modalPanel) and reset the form target.

I used this (trick) to open .pdf reports inside <rich:modalPanel/> using <iframe/> .

But I'm not sure that changing the purpose of the form will be useful for your problem.

+5
source share

As I can see from your command post, you want to ask for confirmation, perform an action and open a new window? I'm not quite sure that a button can handle so many actions, but you can always try using the onload configuration and assign an action to the page you want to load, and let commanbutton handle both the confirmation and the window open action in the same way as Renan suggested .

+2
source share

All Articles