3

我在下面的代码中需要一些帮助

                <h:commandButton  id="WhatifButtonID" value="#{demandBean.dmdReviewScreenLabelVO.whatIf}" style="width:60px; height:22px;"  actionListener="#{demandBean.whatif}"  onclick="window.open('DemandTargetList.xhtml','whatif','width=460,height=280,top=150,left=350,resizable=no,scrollbars=no')" >
                    <f:ajax execute="@this" ></f:ajax>
                </h:commandButton>

在上述情况下,首先执行 onclick 属性,然后执行 actionlistener 属性。我希望先执行 actionListener 属性,然后执行 onclick 函数,因为加载 onclick 的页面需要从 actionListener 获取某些值。请让我知道如何实现同样的目标。提前致谢。

4

2 回答 2

4

只需让<f:ajax>脚本完成即可。

<h:commandButton value="#{demandBean.dmdReviewScreenLabelVO.whatIf}" actionListener="#{demandBean.whatif}">
    <f:ajax execute="@this" render="popupScript" />
</h:commandButton>
<h:panelGroup id="popupScript">
    <h:outputScript rendered="#{demandBean.whatifPressed}">
        window.open('DemandTargetList.xhtml','whatif','width=460,height=280,top=150,left=350,resizable=no,scrollbars=no');
    </h:outputScript>
</h:panelGroup>

其中你whatifPressed在方法true中设置。whatif()

于 2012-07-27T12:46:31.013 回答
0

PrimeFaces 可以通过使用<p:remoteCommand/>标签来帮助解决这个问题。然后,您可以只使用一个普通的旧按钮来调用 remoteCommand,然后只需执行 window.open()。

<p:remoteCommand name="viewSomething" actionListener="#{someActionIWantToExecuteBeforeOpeningWindow}" update="@this" process="@this"/>
<button onclick="viewSomething(); window.open('http://somewhere.com', 'windowName', 'height=924,width=723');">Click me!</button>

You can use it over lists of items if you call the javascript function it creates something unique.

于 2015-03-24T09:57:30.423 回答