动作事件后会触发哪个事件?

时间:2012-10-03 16:45:23

标签: jsf jsf-2 primefaces

我想显示带有值chatBean.selectedUser的模态弹出窗口的标题。发生的事情是onclick事件在action事件之前被触发,因此在onclick事件被触发时页面不会刷新。因此,我无法将模态标题弹出为chatBean.selectedUser中包含的值。无论如何我可以在提交页面之后显示模式弹出窗口的标题,其值为chatbean.selectedUser吗?

以下是该观点的相关部分:

<h:form>
    <p:selectOneMenu value="#{chatBean.selectedUser}" id="select">
        <f:selectItems value="#{chatBean.friendList}" var="users" itemLabel="#{users.firstName}" itemValue="#{users.firstName}"/>
    </p:selectOneMenu>
    <p:commandButton id="basic"  value="Basic" onclick="dlg.show()" type="button"  action="#{chatBean.refresh}"></p:commandButton>      
    <p:dialog id="modalDialog" header="#{chatBean.selectedUser}" widgetVar="dlg" modal="true" height="100">  
        <h:outputText value="This is a Modal Dialog." />  
        <h:inputText></h:inputText>
    </p:dialog>
</h:form>

1 个答案:

答案 0 :(得分:2)

您应该仅在操作完成时显示对话框,而不是之前。请改用oncomplete属性。

<p:commandButton ... oncomplete="dlg.show()" />

在打开对话框之前,不要忘记显式更新对话框的内容。我在你的代码中没有看到任何地方。也许您正在使用RequestContext#update()或其他内容,但通常您会使用update属性。

<p:commandButton ... update="modelDialog" oncomplete="dlg.show()" />

此外,type="button"很奇怪。这样就根本不会调用动作,但也许这只是一个不经意的实验遗留物。删除它。