Javascript 在a4j:commandButton中打开一个新窗口

Javascript 在a4j:commandButton中打开一个新窗口,javascript,ajax,richfaces,ajax4jsf,Javascript,Ajax,Richfaces,Ajax4jsf,在web应用程序中使用A4J、Richfaces,当用户单击时,我需要打开一个新的浏览器窗口 我想我必须使用window.open(URL,…)。我应该把它放在哪里 我的如下所示: <a4j:commandButton id="elementDetailsButton" onclick="if (!confirm('Are you sure? Unsaved data will be lost')) { return false; }" action="#{myBean.e

在web应用程序中使用A4J、Richfaces,当用户单击
时,我需要打开一个新的浏览器窗口

我想我必须使用
window.open(URL,…)
。我应该把它放在哪里

我的
如下所示:

<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>

您可以确认
窗口。打开
而不是
返回false

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

“Else”是可选的,可能不是必需的

或者您可以更改表单目标。。我记不太清楚它的语法是否正确

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

…或者类似的东西

更改表单目标会给您带来一个很好的问题。应用程序的其余部分将以新窗口为目标。。为了解决这个问题,我做了一个
来关闭窗口(modalPanel)并重置表单目标

我使用这个(目标技巧)打开
中的.pdf报告


但是我不确定更改表单目标是否对您的问题有用。

我可以从您的命令按钮中看到,您想要请求确认,执行一个操作并打开一个新窗口,对吗?我不完全确定一个按钮是否可以处理这么多操作,但您可以尝试使用onload配置,将一个操作分配给要加载的页面,并允许commanbutton按照Renan的建议处理确认和打开窗口的操作