| 
 | 
 
| 
 
 Java学习者论坛 
jsp文件內容: 
<h:form id="form"> 
<h:selectOneMenu id="schema" value="#{TestBean.schemaValue}"> 
<f:selectItems value="#{TestBean.schemaItems}"/> 
</h:selectOneMenu> 
 
<h:selectOneMenu id="table" value="#{TestBean.tableValue}"> 
<f:selectItems value="#{TestBean.tableItems}"/> 
</h:selectOneMenu> 
 
<h utputText value="#{TestBean.schemaValue}"/> 
 
<h:commandButton value="refresh" actionListener="#{TestBean.refresh}"/> 
 
</h:form> 
 
BackBean如下: 
public class TestBean { 
private String schemaValue; 
private String tableValue; 
 
public Map<String, List> map = new HashMap<String, List>(); 
private List schemas; 
 
public TestBean() { 
List tables1 = new ArrayList(); 
tables1.add(new SelectItem("Table1")); 
 
List tables2 = new ArrayList(); 
tables2.add(new SelectItem("Table2")); 
tables2.add(new SelectItem("Table3")); 
 
List tables3 = new ArrayList(); 
tables3.add(new SelectItem("Table4")); 
 
map.put("schema1", tables1); 
map.put("schema2", tables2); 
map.put("schema3", tables3); 
 
schemas = new ArrayList(); 
schemas.add(new SelectItem("schema1")); 
schemas.add(new SelectItem("schema2")); 
schemas.add(new SelectItem("schema3")); 
} 
 
public String getTableValue() { 
return tableValue; 
} 
 
public void setTableValue(String tableValue) { 
this.tableValue = tableValue; 
} 
 
public List getTableItems() { 
ArrayList list = new ArrayList(); 
Date d = new Date(); 
String v = String.valueOf(d.getTime()); 
list.add(new SelectItem(schemaValue == null ? "null" : schemaValue)); 
return list; 
} 
 
public List getSchemaItems() { 
return schemas; 
} 
 
public String getSchemaValue() { 
return schemaValue; 
} 
 
public void setSchemaValue(String schemaValue) { 
this.schemaValue = schemaValue; 
} 
 
public void refresh(ActionEvent event) { 
 
} 
 
public void processValueChange(ValueChangeEvent valueChangeEvent) { 
 
} 
} 
 
目的就想做一个级联的下拉框。 
问题在于: 点击refresh按钮后,第一個下拉框的值这次正常下次就是null了,总是交替变化,使得第二个下拉框里面不能正确得到第一个schemaValue。 
 
不知道是哪里写错了??? 
 
 
欢迎来到Java学习者论壇,转载請注明地址:http://www.javaxxz.com. |   
 
 
 
 |