在我的项目中,我将 2 个数据表交织在一起。我想在第一个数据表的行扩展时更新第二个数据表。
<h:form id="form2">
<p:dataTable var="modules" value="#{EVMView.allModules}" id="mydatatable">
<f:facet name="header">
Modules
</f:facet>
<p:column style="width:2rem">
<p:rowToggler/>
</p:column>
<p:column headerText="Module">
<h:outputText value="#{modules}"/>
</p:column>
<p:rowExpansion>
<div class="product">
<p:dataTable var="questions" value="#{EVMView.allQuestions}" id="mydatatable2">
<p:column style="width:2rem">
<p:rowToggler/>
</p:column>
<p:column headerText="Question">
<h:outputText value="#{questions}"/>
</p:column>
<p:rowExpansion>
</p:rowExpansion>
</p:dataTable>
</div>
</p:rowExpansion>
</p:dataTable>
</h:form>
当我展开 mydatatable 的行时,我看不到 mydatatable2 中的值。
所以我知道我也必须更新 mydatatable2,但我找不到如何去做。
编辑
根据@Jasper 的回答,我ViewScoped
在我的 bean 中添加了这个 ajax,并在我的第一个数据表中添加了这个 ajax。
<p:ajax event="rowToggle" listener="#{EVMView.updateTable2()}"/>
我的豆子是这样的
package com.utc.pw.ui;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import org.primefaces.PrimeFaces;
import com.utc.pw.domain.EVMOptions;
import com.utc.pw.domain.EVMQuestions;
import com.utc.pw.domain.SalesOrder;
import com.utc.pw.service.EVMService;
import com.utc.pw.service.PublicService;
@ManagedBean(name="EVMView")
@ViewScoped
public class EVMView {
@EJB
private PublicService publicService;
@EJB
private EVMService evmService;
private EVMQuestions evmQuestions=new EVMQuestions();
private String strSO;
private List<SalesOrder> salesOrders;
private List<String> allModules;
private List<EVMQuestions> allQuestions;
private String selectedOption;
private List<EVMOptions> optionList;
private String answer;
public String getAnswer() {
return answer;
}
public void setAnswer(String answer) {
this.answer = answer;
}
public List<EVMOptions> getOptionList() {
return optionList;
}
public void setOptionList(List<EVMOptions> optionList) {
this.optionList = optionList;
}
public String getSelectedOption() {
return selectedOption;
}
public void setSelectedOption(String selectedOption) {
this.selectedOption = selectedOption;
}
public List<EVMQuestions> getAllQuestions() {
return allQuestions;
}
public void setAllQuestions(List<EVMQuestions> allQuestions) {
this.allQuestions = allQuestions;
}
public PublicService getPublicService() {
return publicService;
}
public void setPublicService(PublicService publicService) {
this.publicService = publicService;
}
public EVMService getEvmService() {
return evmService;
}
public void setEvmService(EVMService evmService) {
this.evmService = evmService;
}
public EVMQuestions getEvmQuestions() {
return evmQuestions;
}
public void setEvmQuestions(EVMQuestions evmQuestions) {
this.evmQuestions = evmQuestions;
}
public String getStrSO() {
return strSO;
}
public void setStrSO(String strSO) {
this.strSO = strSO;
}
public List<SalesOrder> getSalesOrders() {
return salesOrders;
}
public void setSalesOrders(List<SalesOrder> salesOrders) {
this.salesOrders = salesOrders;
}
public List<String> getAllModules() {
return allModules;
}
public void setAllModules(List<String> allModules) {
this.allModules = allModules;
}
@PostConstruct
public void init() {
this.salesOrders = publicService.getAllSalesOrders();
}
public void loadModules()
{
this.allModules=evmService.getAllModules(strSO);
this.allQuestions=evmService.getAllQuestions(strSO);
PrimeFaces.current().ajax().update("form2:mydatatable");
//PrimeFaces.current().ajax().update("form3:mydatatable2");
}
public void updateTable2()
{
PrimeFaces.current().ajax().update(":mydatatable2");
}
public List<EVMOptions> options(String module,int questionID)
{
this.optionList=evmService.getOptions(strSO, module, questionID);
return optionList;
}
}