[英]p:datatable not refreshed correctly after data modification in p:dialog
Ok, tried to shorten a bit and put the code at the end of the post. 好的,尝试缩短一点并将代码放在帖子的末尾。 Thank you for your answers. 谢谢您的回答。
After reading quite a few questions/answers on the subject and not finding any solution, here is my issue. 在阅读了有关该主题的许多问题/答案并没有找到任何解决方案之后,这是我的问题。 I tried to be as concise as possible so I might have truncated some code, feel free to ask for details. 我试图尽可能简洁,所以我可能已经截断了一些代码,可以随时询问详细信息。 I am also quite new to the JSF, primefaces world. 对于JSF,primefaces世界,我也很陌生。
I develop evolutions/fixes on an existing web application based on Spring/Hibernate/Primefaces. 我在基于Spring / Hibernate / Primefaces的现有Web应用程序上开发了开发版本/修复程序。 The user interface contains a tabview with some p:datatable : companies, users in my case. 用户界面包含一个带有一些p:datatable的tabview:公司,在我的情况下是用户。
So here is my use case: 所以这是我的用例:
In 'formCompany', a button displays the dialog 'createCompany'. 在“ formCompany”中,按钮显示对话框“ createCompany”。
I create a company 'aaaa/aaaa' (name and code are mandatory for societeEntity) -> the company is added in 'CompaniesTable' 我创建一个公司'aaaa / aaaa'(名称和代码对于societeEntity是必需的)->该公司已添加到'CompaniesTable'中
I create a user associated to this company 'john'/'aaaa' (name and company are mandatory fields for utilisateurEntity) -> the user is created and displayed in 'userTable' with the company name 'aaaa' 我创建与此公司“ john” /“ aaaa”关联的用户(名称和公司是utilisateurEntity的必填字段)->创建该用户并将其显示在“ userTable”中,公司名称为“ aaaa”
I modify the name to 'bbbb' of the company and save it -> the company name is not updated in 'userTable' 我将公司名称修改为“ bbbb”并保存->公司名称未在“ userTable”中更新
What I suspect is that userTable is not refreshed from the database with the 'update' attribute of the commandButton. 我怀疑的是,userTable没有通过commandButton的'update'属性从数据库中刷新。 I guess that the 'update' attribute on ":panelBas:formUser:userTable" works fine but only on client side. 我猜想“:panelBas:formUser:userTable”的'update'属性可以正常工作,但只能在客户端使用。
What I expect is that the datatable containing the users will be refreshed with the new company name 'bbbb'. 我期望的是包含用户的数据表将被新的公司名称“ bbbb”刷新。
The tricks I tried : 我尝试过的技巧:
Here is the code of the button that saves the company : 这是保存公司的按钮的代码:
<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 && !args.validationFailed) { PF('createCompany').hide(); }"** />
The component p:datatable does not seem to have a method to reload data from the server. 组件p:datatable似乎没有从服务器重新加载数据的方法。 So the question is how can I update my user datatable after saving a company in a backing bean ? 因此,问题是将公司保存到备用Bean中后如何更新用户数据表?
The code below shows the xhtml page containing the tabview, dialogs, datatables, ... 下面的代码显示了xhtml页面,其中包含tabview,对话框,数据表,...
main.xhtml 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 && !args.validationFailed) { PF('createCompany').hide(); }"** />
</h:form>
</p:dialog>
Here is the code of the beans: 这是bean的代码:
CompanyDialog.java 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 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)
...
}
}
Thank you in advance and have a nice day. 在此先感谢您,祝您度过愉快的一天。
Your question is: "how can I update my user datatable after saving a company ?" 您的问题是: “保存公司后如何更新用户数据表?”
In button in your dialog in jsf try this: 在jsf对话框中的按钮中,尝试以下操作:
<h:commandButton id="ok" value="OK">
<p:ajax click="messagesDialog.hide()"
update="@all"/>
</h:commandButton>
in update target first all, try use @form, if doesnt work, use @all 首先在更新目标中,尝试使用@form,如果不起作用,请使用@all
If doesnt work try use imediate="true", imatiate true, this will change order lifecycle, maybe solve your problem if before sugestions doesnt worked. 如果不起作用,请尝试使用imediate =“ true”,将其表示为true,这将更改订单的生命周期,如果未解决建议,可能会解决您的问题。 I think your are question is simple, you don't should write many text. 我认为您的问题很简单,您不应写很多文字。
So I digged the solution with injected beans and made it work. 因此,我用注入的豆子挖掘了解决方案并使之起作用。
The idea is in that link : Can I call multiple methods from <p:ajax event=select listner=method1, metho2>? 这个想法在那个链接中: 我可以从<p:ajax event = select listner = method1,metho2>调用多个方法吗? . 。
I am not sure if this method is very clean regarding the annotations... 我不确定此方法在注释方面是否很干净...
I injected UserDialog bean in CompanyDialog bean like this : 我像这样在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() {
// ...
}
}
If any improvement can be made, feel free to give any advice. 如果可以进行任何改进,请随时提出任何建议。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.