简体   繁体   English

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

[英]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> . 在Web应用程序中使用A4J,Richfaces,当用户单击<a4j:commandButton>时,我需要打开一个新的浏览器窗口。

I think I will have to use window.open(URL, ...) . 我想我将不得不使用window.open(URL, ...) Where should I put it? 我应该把它放在哪里?

My <a4j:commandButton> looks like this: 我的<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>

You can confirm the window.open and not the return false 您可以确认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" is optional, maybe not necessary. “Else”是可选的,可能不是必需的。

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. 你应用程序的其余部分将以新窗口为目标。为了解决这个问题,我创建了一个<h:commandLink/>来关闭窗口(modalPanel)并重置表单目标。

I was using this (the target trick) to open .pdf reports inside a <rich:modalPanel/> using a <iframe/> . 我正在使用这个(目标技巧)使用<iframe/><rich:modalPanel/>打开.pdf报告。

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. 我不完全确定按钮是否可以处理如此多的操作,但您可以始终尝试使用onload配置并为要加载的页面分配操作,并允许commanbutton同时处理打开窗口的确认和操作Renan建议。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM