我知道这已经解决了这个问题,但我不知道为什么我的代码无法正常工作
我有两个列表,我希望当第一个更改时,其他人更新 这是我的代码
<h:selectOneMenu id="e4" styleClass="col-md-5" value="#{categoryModel.selectedMenu}">
<f:selectItem />
<f:selectItems value="#{categoryModel.catFinanceVect}" var="catFinance"itemLabel="#{catFinance.designation}" itemValue="#{catFinance.ligne}" />
<!-- <a4j:ajax event="valueChange" render="e3" execute="@this" />-->
<f:ajax event="valueChange" execute="@this" render="e3" listener="#{categoryModel.getCatItList}"/>
</h:selectOneMenu>
<div class="col-md-1"></div>
<h:selectOneMenu id="e3" styleClass="col-md-6">
<f:selectItem />
<f:selectItems value="#{categoryModel.catItVect}" var="catIt"itemLabel="#{catIt.designation}" itemValue="#{catIt.designation}" />
</h:selectOneMenu>
这是我的支持豆:
@ManagedBean
@SessionScoped
public class CategoryModel {
private CatFinance catFinance= new CatFinance();
private Vector<CatFinance> catFinanceVect = new Vector<CatFinance>();
private CatIt catIt= new CatIt();
private Vector<CatIt> catItVect = new Vector<CatIt>();
private Integer selectedMenu;
public CategoryModel() {
super();
// TODO Auto-generated constructor stub
}
public CatFinance getCatFinance() {
return catFinance;
}
public void setCatFinance(CatFinance catFinance) {
this.catFinance = catFinance;
}
public Vector<CatFinance> getCatFinanceVect() {
return catFinanceVect;
}
public void setCatFinanceVect(Vector<CatFinance> catFinanceVect) {
this.catFinanceVect = catFinanceVect;
}
public CatIt getCatIt() {
return catIt;
}
public void setCatIt(CatIt catIt) {
this.catIt = catIt;
}
public Vector<CatIt> getCatItVect() {
return catItVect;
}
public void setCatItVect(Vector<CatIt> catItVect) {
this.catItVect = catItVect;
}
public Integer getSelectedMenu() {
return selectedMenu;
}
public void setSelectedMenu(Integer selectedMenu) {
this.selectedMenu = selectedMenu;
}
public void getCatFinanceList(){
this.setCatFinance(new CatFinance());
CatFinanceService catFinanceService = (CatFinanceService) SpringDaoCtxFactory.getDaoContext().getBean("CatFinanceService");
this.getCatFinanceVect().clear();
try {
this.getCatFinanceVect().addAll(catFinanceService.getCatFinanceList());
} catch (Exception e) {
e.printStackTrace();
}
}
public void getCatItList(AjaxBehaviorEvent event){
this.setCatIt(new CatIt());
CatItService catItService = (CatItService) SpringDaoCtxFactory.getDaoContext().getBean("CatItService");
this.getCatItVect().clear();
System.out.println("aaaa");
try {
this.getCatItVect().addAll(catItService.getCatItList(2));
} catch (Exception e) {
e.printStackTrace();
}
}
@PostConstruct
public void init(){
getCatFinanceList();
}
}
如果有人可以帮忙或者给我一个如何做的好的指导我将非常感激 提前谢谢
答案 0 :(得分:1)
f:ajax
事件无效。它应为change
(或为change
默认为h:selectOneMenu
为空。)
<f:ajax execute="@this" render="e3" listener="#{categoryModel.getCatItList}"/>