【问题标题】:open a new window in a4j:commandButton在 a4j 中打开一个新窗口:commandButton
【发布时间】:2011-06-14 15:23:26
【问题描述】:

在Web应用程序中使用A4J,Richfaces,当用户点击<a4j:commandButton>时,我需要打开一个新的浏览器窗口。

我想我将不得不使用window.open(URL, ...)。我应该把它放在哪里?

我的<a4j:commandButton> 看起来像这样:

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

【问题讨论】:

    标签: javascript ajax richfaces ajax4jsf


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      您可以确认window.open 而不是return 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'" (...) />
      

      ...或类似的东西。

      改变表单目标会给你一个很好的问题。其余的应用程序将以新窗口为目标。为了解决这个问题,我创建了一个&lt;h:commandLink/&gt; 来关闭窗口(modalPanel)并重置表单目标。

      我正在使用这个(目标技巧)使用&lt;iframe/&gt; 打开&lt;rich:modalPanel/&gt; 内的.pdf 报告。

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2022-06-15
        • 2014-03-24
        • 2020-03-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-09-29
        相关资源
        最近更新 更多