2011-03-24 46 views
1

假设我有两个selectOneMenu标签绑定到两个不同的列表(让我们说产品和部门)。互斥jsf selectOneMenu项目

我想阻止根据所选产品选择一些部门,反之亦然。我可以把这个逻辑放在哪里?

+0

你使用Seam发出Ajax请求

<h:selectOneMenu id="product" value="#{bean.selectedProduct}"> <f:selectItem itemLabel="Select Product" itemValue="" /> <f:selectItems value="#{bean.productList}"/> <!-- here is where I send out ajax request --> <p:ajax listener="#{bean.loadDepartmentById}" event="change" update="department" /> </h:selectOneMenu> <h:selectOneMenu id="department" value="#{bean.selectedDepartment}"> <f:selectItem itemLabel="" itemValue="" /> <f:selectItems value="#{bean.departmentList}"/> </h:selectOneMenu> 

这里?你使用的是RichFaces还是类似的东西?这些可能会影响答案。 – 2011-03-24 19:51:45

回答

2

不知道这是否是你想要这样做的方式。但是,您可以根据所选产品加载部门清单。为此,您需要在选择产品时发送Ajax请求以更新部门列表。为了说明这一点,我将使用PrimeFaces是我的豆

@ManagedBean 
@ViewScoped 
public class bean{ 
    private List<SelectItem> productList = null; 
    private List<SelectItem> departmentList = null; 
    private Long selectedProduct = null; 
    private Long selectedDepartment = null; 

    @PostConstruct 
    public void init(){ 
     //Pre load product list 
     productList = new ArrayList<SelectItem>(); 
     productList.add(new SelectItem("value1", "label1")); 
     productList.add(new SelectItem("value2", "label2")); 
     productList.add(new SelectItem("value3", "label3")); 
     //The values are the keys passed to the selectItem property. 
     //The labels are those what you see on the menu. 
    } 

    public void loadDepartmentById(){ 
     if(selectedProduct != null){ 
      //Load the appropriate list of department. 
     } 
    } 

}