1

我想显示带有值的模式弹出窗口的标题chatBean.selectedUser。发生的事情是onclick事件在事件之前触发,action因此在触发事件时页面不会刷新onclick。因此,我无法将 modal 的标题弹出为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>
4

1 回答 1

2

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

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

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

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

此外,这type="button"很奇怪。这种方式根本不会调用动作,但也许这只是实验的粗心剩余。去掉它。

于 2012-10-03T18:02:37.307 回答