簡體   English   中英

p:對話框中的數據修改后,p:datatable沒有正確刷新

[英]p:datatable not refreshed correctly after data modification in p:dialog

好的,嘗試縮短一點並將代碼放在帖子的末尾。 謝謝您的回答。

在閱讀了有關該主題的許多問題/答案並沒有找到任何解決方案之后,這是我的問題。 我試圖盡可能簡潔,所以我可能已經截斷了一些代碼,可以隨時詢問詳細信息。 對於JSF,primefaces世界,我也很陌生。

我在基於Spring / Hibernate / Primefaces的現有Web應用程序上開發了開發版本/修復程序。 用戶界面包含一個帶有一些p:datatable的tabview:公司,在我的情況下是用戶。

所以這是我的用例:

  • 在“ formCompany”中,按鈕顯示對話框“ createCompany”。

  • 我創建一個公司'aaaa / aaaa'(名稱和代碼對於societeEntity是必需的)->該公司已添加到'CompaniesTable'中

  • 我創建與此公司“ john” /“ aaaa”關聯的用戶(名稱和公司是utilisateurEntity的必填字段)->創建該用戶並將其顯示在“ userTable”中,公司名稱為“ aaaa”

  • 我將公司名稱修改為“ bbbb”並保存->公司名稱未在“ userTable”中更新

我懷疑的是,userTable沒有通過commandButton的'update'屬性從數據庫中刷新。 我猜想“:panelBas:formUser:userTable”的'update'屬性可以正常工作,但只能在客戶端使用。

我期望的是包含用戶的數據表將被新的公司名稱“ bbbb”刷新。

我嘗試過的技巧:

  • p:commandButton =>上的update屬性失敗
  • 使用PF('userTable')=>從p:commanbButton.oncomplete通過其widgetVar id到達userTable並調用假設的“刷新/重新加載/更新”方法=>失敗(primefaces文檔並沒有真正的幫助...)

這是保存公司的按鈕的代碼:

<p:commandButton value="Save" update="companyNameMsg companyCodeMsg :panelBas:formCompany:CompaniesTable **:panelBas:formUser:userTable**" ajax="true"
    actionListener="#{companyDialog.save}" icon="ui-icon-disk"
    **oncomplete="if(args &amp;&amp; !args.validationFailed) { PF('createCompany').hide(); }"** />

組件p:datatable似乎沒有從服務器重新加載數據的方法。 因此,問題是將公司保存到備用Bean中后如何更新用戶數據表?

下面的代碼顯示了xhtml頁面,其中包含tabview,對話框,數據表,...

main.xhtml

<p:tabView id="panelBas" widgetVar="wvPanelBas" activeIndex="#{searchDialog.activeIndex}">
    <p:tab title="Companies">
        <h:form id="**formCompany**">
            <p:dataTable id="CompaniesTable" value="#{companyDialog.companyList}" var="item3" lazy="false"
                tableStyle="text-align: center;width:auto" paginator="true" rowsPerPageTemplate="5,10,15,20,30,50,100" rows="15"
                sortBy="#{item3.nom}" sortOrder="ascending" filteredValue="#{companyDialog.companyFilteredList}">
                ...
            </p:dataTable>
        </h:form>
    </p:tab>

    <p:tab title="Users">
        <h:form id="formUser">
            <p:dataTable id="userTable" widgetVar="wvUserTable" **value="#{userDialog.utilisateurList}"** var="item2" lazy="false" 
                tableStyle="text-align: center;width:auto" paginator="true" rowsPerPageTemplate="5,10,15" rows="10"
                sortBy="#{item2.nom}" sortOrder="ascending" filteredValue="#{userDialog.utilisateurFilteredList}">

                **<!-- This value is not updated when associated company's name is modified-->
                <p:column filterBy="#{item2.societe.nom}" sortBy="#{item2.societe.nom}" headerText="Company">
                    <h:outputText value="#{item2.societe.nom}" />
                </p:column>**
                ...
                <p:column filterBy="#{item2.nom}"  sortBy="#{item2.nom}" headerText="Nom" sortOrder="ascending">
                    <h:outputText value="#{item2.nom}" />
                </p:column>
            </p:dataTable>
        </h:form>
    </p:tab>
</p:tabView>

<!-- This dialog allows to modify company data -->
<p:dialog header="New Company" widgetVar="createCompany" id="createCompany" resizable="true" modal="true" width="500" showEffect="clip" hideEffect="clip">
    <h:form>
        ...
        <!-- Company modification form -->
        <p:commandButton value="Save" update="companyNameMsg companyCodeMsg :panelBas:formCompany:CompaniesTable **:panelBas:formUser:userTable**" ajax="true"
            actionListener="#{companyDialog.save}" icon="ui-icon-disk"
            **oncomplete="if(args &amp;&amp; !args.validationFailed) { PF('createCompany').hide(); }"** />
    </h:form>
</p:dialog>

這是bean的代碼:

CompanyDialog.java

@Component("companyDialog")
@Scope(value = WebApplicationContext.SCOPE_SESSION, proxyMode = ScopedProxyMode.TARGET_CLASS)
public class CompanyDialog {
    // Managed property used by datatable attribute 'value'
    @ManagedProperty("#{companyList}")
    private List<SocieteEntity> companyList;

    // Managed property used by datatable attribute 'filteredValue'
    @ManagedProperty("#{companyFilteredList}")
    private List<SocieteEntity> companyFilteredList;

    @ManagedProperty("#{societeEntity}")
    private SocieteEntity societeEntity;

    @Override
    public void save() {
        ...
    }
}

UserDialog.java

@Component("userDialog")
@Scope(value = WebApplicationContext.SCOPE_SESSION, proxyMode = ScopedProxyMode.TARGET_CLASS)
public class UserDialog {
    // Managed property used by datatable attribute 'value'
    @ManagedProperty("#{utilisateurList}")
    private List<UtilisateurEntity> utilisateurList;

    // Managed property used by datatable attribute 'filteredValue'
    @ManagedProperty("#{utilisateurFilteredList}")
    private List<UtilisateurEntity> utilisateurFilteredList;

    @ManagedProperty("#{utilisateurEntity}")
    private UtilisateurEntity utilisateurEntity;

    public void recherche() {
        // Fills the managed property utilisateurList (used by the datatable)
        ...
    }
}

在此先感謝您,祝您度過愉快的一天。

您的問題是: “保存公司后如何更新用戶數據表?”

在jsf對話框中的按鈕中,嘗試以下操作:

<h:commandButton id="ok" value="OK">
    <p:ajax click="messagesDialog.hide()" 
    update="@all"/>
</h:commandButton>

首先在更新目標中,嘗試使用@form,如果不起作用,請使用@all

如果不起作用,請嘗試使用imediate =“ true”,將其表示為true,這將更改訂單的生命周期,如果未解決建議,可能會解決您的問題。 我認為您的問題很簡單,您不應寫很多文字。

因此,我用注入的豆子挖掘了解決方案並使之起作用。

這個想法在那個鏈接中: 我可以從<p:ajax event = select listner = method1,metho2>調用多個方法嗎?

我不確定此方法在注釋方面是否很干凈...

我像這樣在CompanyDialog bean中注入了UserDialog bean:

@Component("companyDialog")
@Scope(value = WebApplicationContext.SCOPE_SESSION, proxyMode = ScopedProxyMode.TARGET_CLASS)
public class CompanyDialog {
    @Inject
    private UserDialog userDialog;

    // When I update a company, the list userDialog.utilisateurList of users is reloaded in userDialog
    public void save() {
        // ...
        userDialog.recherche();
    }
}

@Component("userDialog")
@Scope(value = WebApplicationContext.SCOPE_SESSION, proxyMode = ScopedProxyMode.TARGET_CLASS)
public class UserDialog {
    @ManagedProperty("#{utilisateurList}")
    private List<UtilisateurEntity> utilisateurList;

    // Fills the list utilisateurList
    public void recherche() {
        // ...
    }
}

如果可以進行任何改進,請隨時提出任何建議。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM