Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jsf 如何在onclick之前执行h:commandButton actionListener?_Jsf_Jsf 2 - Fatal编程技术网

Jsf 如何在onclick之前执行h:commandButton actionListener?

Jsf 如何在onclick之前执行h:commandButton actionListener?,jsf,jsf-2,Jsf,Jsf 2,我需要一些帮助在下面的代码 <h:commandButton id="WhatifButtonID" value="#{demandBean.dmdReviewScreenLabelVO.whatIf}" style="width:60px; height:22px;" actionListener="#{demandBean.whatif}" onclick="window.open('DemandTargetList.xhtml','whatif'

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

                <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获取某些值。请让我知道如何做到这一点。提前谢谢

只需让
在完成后渲染脚本即可

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

open('DemandTargetList.xhtml','whatif','width=460,height=280,top=150,left=350,resizeable=no,scrollbars=no');

您可以在
whatif()
方法中将
whatifspressed
设置为
true

PrimeFaces可以通过使用
标记来帮助实现这一点。然后,只需使用一个普通的旧按钮调用remoteCommand,然后简单地执行window.open()


点击我!

如果调用javascript函数,您可以在项目列表上使用它,因为它创建了一些独特的东西。

非常感谢BalusC的快速响应。这真的很有帮助。但加载弹出窗口所需的时间似乎要多一些。您还可以让我知道属性执行的顺序吗。如果您了解HTML/JS是如何工作的(这基本上就是JSF生成的所有内容),那么就很容易了。因此,阅读一个像样的HTML/JS教程,然后查看JSF生成的HTML/JS代码(在浏览器中右键单击页面并查看源代码)应该足够清晰。
<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>