我的JSP页面:
<h:form> <h:selectOneMenu id="tag" valueChangeListener="#{myForm.change}"> <f:selectItem itemValue="1" itemLabel="1"/> <f:selectItem itemValue="2" itemLabel="2"/> </h:selectOneMenu> <h:dataTable var="row" value="#{myForm.data}"> <h:column> <h:outputText value="#{row.value}"/> </h:column> </h:dataTable> <h:commndButton id="next" actionListener="#{myForm.next}"/> </h:form>
|
我的JAVA代码:
public class MyForm { private List<IntBean> data = new ArrayList<IntBean>(); public MyForm() { for(int i = 0; i < 100; i++) { data.add(new IntBean(i)); } } public void change(ValueChangeEvent event) { System.out.println("change"); } public void next(ActionEvent event) { System.out.println("next"); } }
public class IntBean { private int value; public IntBean(int val) { value = val; } public int getValue() { return value; } }
|
每次点击next按钮,后台都会打印【change】,不管下拉列表中的值是否有变化。
为什么会这样呢?请各位大虾指点下。
我想实现成点击next按钮时,不触发change方法,不知应该如何实现,请指点下。
最开始的时候,我在下拉列表里是有【onchange="this.form.submit()"】的,想实现的就是通过改变下拉列表的值的时候更新下面table中的值,但这样每次点击next按钮时,却同时触发了change方法,这个不是我想要的。