【问题标题】:PrimeFaces: which ajax event do I need?PrimeFaces:我需要哪个 ajax 事件?
【发布时间】:2011-11-02 11:41:36
【问题描述】:

我有这个commandButton

<p:commandButton value="View/Edit" onclick="bar.show()"
                 oncomplete="bar.hide(); dataSetUserDialog.show();"
                 actionListener="#{dataStoreBean.initUserLists}">
    <p:ajax event="?" update="userSelect" ></p:ajax>
    <f:param name="checkSum" value="#{dataSet.checkSum}" />
</p:commandButton>

还有这个dialog,里面有一个selectManyMenu

<p:dialog header="View or Edit #{dataStoreBean.currentDataSetName} users"
          widgetVar="dataSetUserDialog" modal="true" width="500" height="200">
    <h:form>
        <p:selectManyMenu id="userSelect" value="#{dataStoreBean.selectedUsers}" style="width: 475px;">
            <f:selectItems value="#{dataStoreBean.users}"
                           var="user" itemValue="#{user.email}"
                           itemLabel="#{user.email} | #{user.groupName}" />
        </p:selectManyMenu>

        <p:commandButton value="Done"
                         actionListener="#{dataStoreBean.updateDataSetsUsers}"            
                         onclick="dataSetUserDialog.hide()" type="submit" />
    </h:form>

</p:dialog>

我想要实现的是在我想要显示的对话框中更新信息。 userSelect 在该对话框中。所以首先我要执行#{dataStoreBean.initUserLists},然后更新(重新渲染)userSelect,然后显示dataSetUserDialog。我该怎么做?

【问题讨论】:

  • 我不确定你们都已经尝试过什么以及为什么它们还不够,但是默认事件action 有什么问题? IE。只需完全删除 event 属性即可。
  • @BalusC 谢谢,有时我真的应该学习/记住 JSF 生命周期。

标签: java ajax jsf primefaces


【解决方案1】:

正如 BalusC 所建议的,我应该使用 action 而不是 actionListener

<p:commandButton value="View/Edit users" onclick="loadNotification.show()"
                 oncomplete="loadNotification.hide(); dataSetUserDialog.show();"
                 action="#{dataStoreBean.initUserLists}" update="userSelect">
    <f:param name="checkSum" value="#{dataSet.checkSum}" />
    <f:param name="fullFileName" value="#{dataSet.fileName}.#{dataSet.fileType}" />
</p:commandButton>

<p:dialog id="userSelect" draggable="false" resizable="false"
          header="View or Edit #{dataStoreBean.currentDataSetName} users"
          widgetVar="dataSetUserDialog" modal="true" width="500" height="200">
    <h:form>
        <p:selectManyMenu value="#{dataStoreBean.selectedUsers}">
            <f:selectItems value="#{dataStoreBean.users}" var="user"
                           itemValue="#{user.email}"
                           itemLabel="#{user.email} | #{user.groupName}" />
        </p:selectManyMenu>

        <p:commandButton value="Done"
                         actionListener="#{dataStoreBean.updateDataSetsUsers}" 
                         update="dataSetMessages"
                         onclick="dataSetUserDialog.hide()" type="submit" />
    </h:form>
</p:dialog>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-10-27
    • 1970-01-01
    • 2018-11-26
    • 1970-01-01
    • 1970-01-01
    • 2014-01-21
    • 1970-01-01
    相关资源
    最近更新 更多