开发者

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 the <a4j:commandButton>.

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

My <a4j:commandButton> looks like this:

<a4j:commandButton id="elementDetailsButton"
    onclick="if (!confirm('Are you sure? Unsaved data will be lost')) { return false; }"
    action="#{m开发者_开发百科yBean.elementDetailsAction}"
    value="Element Details">
    <a4j:actionparam name="elementDetailsString"
        value="getElementDetails()"
        assignTo="#{myBean.elementDetails}" noEscape="true">
    </a4j:actionparam>
</a4j:commandButton>


You can confirm the window.open and not the 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, maybe not necessary.

Or you can change the form target.. I dont remember very well if its the correct syntax...

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

...or something like that.

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

I was using this (the target trick) to open .pdf reports inside a <rich:modalPanel/> using a <iframe/>.

But I'm not sure if change the form target will be useful for your problem..


As I can see from your commandbutton you want to ask for confirmation, execute an action and open a new window right? I am not totally sure if a button can handle so many actions but you could always try to use onload configuration and assign an action to the page you want to load and allow the commanbutton to handle both confirmation and the action of opening the window just as Renan suggested.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜