按下PrimeFaces p:commandButton时事件的执行顺序

我试图执行JSF2 bean方法,并在单击PrimeFaces时完成该方法后显示一个对话框<p:commandButton>。


<p:commandButton id="viewButton" value="View"

    actionlistener="#{userBean.setResultsForSelectedRow}" ajax="false"

    update=":selectedRowValues"

    oncomplete="PF('selectedRowValuesDlg').show()">

</p:commandButton>

<p:dialog id="selectedRowValues" widgetVar="selectedRowValuesDlg" dynamic="true">

    <h:outputText value="#{userBean.selectedGroupName}" />

</p:dialog>

当我单击命令按钮时,bean动作侦听器方法setResultsForSelectedRow正确执行,但是在该方法完成时它不会显示对话框。如果删除actionlistener,则会显示对话框。我不知道出了什么问题。


事件的执行顺序是什么?是否有可能执行actionlistener和oncomplete同步?


白衣染霜花
浏览 737回答 2
2回答

湖上湖

我只是喜欢获得BalusC在这里提供的信息-而且他很乐于帮助如此多的人获得如此好的信息,我以他的话语为福音,但是我无法利用事件的顺序来解决这种相同的时机在我的项目中。由于BalusC在这里甚至给我添加了书签,因此我想在同一地方捐赠一些高级时序问题的解决方案,因为它也解决了原始海报的时序问题。我希望这段代码可以帮助某人:&nbsp; &nbsp; &nbsp; &nbsp; <p:pickList id="formPickList"&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; value="#{mediaDetail.availableMedia}"&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; converter="MediaPicklistConverter"&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; widgetVar="formsPicklistWidget"&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var="mediaFiles"&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; itemLabel="#{mediaFiles.mediaTitle}"&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; itemValue="#{mediaFiles}" >&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <f:facet name="sourceCaption">Available Media</f:facet>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <f:facet name="targetCaption">Chosen Media</f:facet>&nbsp; &nbsp; &nbsp; &nbsp; </p:pickList>&nbsp; &nbsp; &nbsp; &nbsp; <p:commandButton id="viewStream_btn"&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;value="Stream chosen media"&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;icon="fa fa-download"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ajax="true"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;action="#{mediaDetail.prepareStreams}"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;update=":streamDialogPanel"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;oncomplete="PF('streamingDialog').show()"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;styleClass="ui-priority-primary"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;style="margin-top:5px" >&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <p:ajax process="formPickList"&nbsp; />&nbsp; &nbsp; &nbsp; &nbsp; </p:commandButton>该对话框位于此表单之外XHTML的顶部,并且在对话框中嵌入了自己的表单以及一个数据表,该数据表包含用于流式传输媒体的其他命令,这些命令在初始化对话框时都需要准备好并准备就绪呈现。您也可以使用相同的技术来执行一些操作,例如下载需要准备的自定义文档,然后再通过对话框中的fileDownload按钮将它们准备流式传输到用户的计算机上。如我所说,这是一个更复杂的示例,但它触及了您的问题和我的所有要点。单击命令按钮时,结果是首先确保用pickList的结果更新了后备bean,然后告诉后备bean根据用户在选择列表中的选择为用户准备流,然后在其中更新控件。动态对话框并进行更新,然后显示该对话框供用户开始流式传输其内容。它的窍门是对主要的CommandButton使用BalusC的事件顺序,然后添加该<p:ajax process="formPickList" />位以确保它首先被执行-因为除非pickList首先更新了后备bean,否则什么都不会正确发生(这在我之前是没有发生的添加)。所以,是的,那个CommandButton摇摆不定,是因为您可以影响以前的,待处理的和当前的组件以及后备Bean-但是将所有这些组件相互关联的时机有时很难掌握。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript