2017-10-09 73 views
0

好吧,试图缩短一点,并将代码放在帖子的末尾。谢谢您的回答。p:datatable在p:对话框中的数据修改后没有正确刷新

在阅读了很多关于这个主题的问题/答案后,没有找到任何解决方案,这是我的问题。 我试图尽可能简洁,所以我可能会截断一些代码,请随时查询详细信息。 我对JSF,primefaces世界也很陌生。

我在基于Spring/Hibernate/Primefaces的现有Web应用程序上开发了进化/修复。 用户界面包含一个带有p:datatable:公司,用户的tabview。

因此,这里是我的使用情况:

  • 在 'formCompany',一个按钮显示的对话框 'createCompany'。

  • 我公司创建“AAAA/AAAA”(名称和代码是强制性的societeEntity) - >公司是在加入“CompaniesTable”

  • 创建关联到这个公司“约翰”用户/“AAAA”(姓名和公司是强制性字段utilisateurEntity) - >被创建并在“用户表”显示在用户的公司名称“AAAA”

  • 我修改名称的公司的“BBBB”并保存它 - >公司名称不更新'userTable'

我怀疑userTable没有使用commandButton的'update'属性从数据库中刷新。 我想“:panelBas:formUser:userTable”上的'更新'属性工作正常,但只在客户端。

我期望的是,包含用户的数据表将使用新公司名称'bbbb'刷新。

的招数我尝试:在页码

  • 更新属性:的commandButton =>失败
  • 从对到达用户表:commanbButton.oncomplete以其widgetVar ID和调用一个假设的 '刷新/重载/更新'方法,使用PF( '用户表')=>失败(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似乎没有从服务器重新加载数据的方法。 所以问题是我怎样才能更新我的用户datatable保存后台bean中的公司后?

下面的代码显示了包含TabView的,对话框,数据表,...

主要XHTML页面。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> 

这里是豆代码:

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) 
     ... 
    } 
} 

预先感谢您,并有一个愉快的一天。

+1

太多了,请阅读[如何提出一个好问题](https://stackoverflow.com/help/how-to-ask) –

回答

0

您的问题是:“如何在保存公司后更新我的用户数据表?”

在对话框中的按钮,在JSF试试这个:

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

首先,尝试使用@form,如果不工作,使用@all

如果不工作尝试使用imediate =“真”,想象真实,这将改变订单生命周期,也许解决您的问题,如果在sugestions没有奏效。我认为你的问题很简单,你不应该写很多文字。

+1

'@ all'只能在极少数情况下使用。由于有'process \ execute'属性,所以在现代基于jsf/ajax的应用程序中很少需要'immediate =“true”'。 – Kukeltje

+0

是的。我的意思是,尝试增加范围。他应该首先使用初始范围。如果不行的话。在最终情况下使用“@all”或“@form”。谢谢你的回答 –

0

因此,我用注入的bean挖掘了解决方案并使其工作。

这个想法是在那个链接:Can I call multiple methods from <p:ajax event=select listner=method1, metho2>?

我不知道,如果这个方法是非常干净的有关注解:

我注入UserDialog豆在CompanyDialog豆这样的:

@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() { 
     // ... 
    } 
} 

如果有任何改进就无法进行,随意给任何建议。

相关问题