在提交时调用valueChangeListener,而不更改selectOneMenu中的选项 [英] valueChangeListener is invoked on submit without changing options in selectOneMenu
问题描述
在我的页面中,我有selectonemenu,并且注意到当我单击datatable的分页时,将调用valueChangeListener方法,而实际上并未更改selectonemenu中的值或选项.
In my page I have selectonemenu and I have noticed that when I click the pagination of datatable, valueChangeListener method is getting invoked without actually changing values or options in selectonemenu.
这是怎么回事,以及如何防止这种情况发生,因为仅当用户在selectonemenu中更改值时才需要调用valueChangeListener方法.
How is this happening and how could I prevent this from happening as I need to invoke valueChangeListener method only if user changes values in selectonemenu.
感谢并感谢您的帮助.
致谢
这是我的selectonemenu代码
Here is my code for selectonemenu
更新1
<ice:selectOneMenu value="#{list.selectedItem}"
partialSubmit="true" valueChangeListener="#{list.val}">
<f:selectItems value="#{list.selectItems}" />
</ice:selectOneMenu>
还有bean方法
public void val(ValueChangeEvent event) {
logger.info("1");
selectedValue = event.getNewValue().toString();
}
像这样添加值
public void loadItems(){
selectItems.add(new SelectItem("1", "One"));
selectItems.add(new SelectItem("2", "Two"));
selectItems.add(new SelectItem("3", "Three"));
selectItems.add(new SelectItem("4", "Four"));
}
然后方法调用如下
public List<SelectItem> getSelectItems() {
if (selectItems == null) {
loadItems;
}
return selectItems;
}
推荐答案
JSF valueChangeListener
与客户端事件无关.这是服务器端事件,当 submitted 值与 initial 值不同时,将调用该事件.
The JSF valueChangeListener
is in no way related to the client-side events. It is a server-side event which will be invoked when the submitted value differs from the initial value.
列表的第一项的值为1
,因此当用户不更改下拉菜单时,提交的值将为1
.如果您不希望调用valueChangeListener
,则需要确保初始值也等于1
.那就是#{list.selectedItem}"
后面的值.在bean的构造/初始化过程中,将其初始化为与第一项相同的值.
The first item of your list has a value of 1
, so when the user doesn't change the dropdown, the submitted value will be 1
. If you don't want the valueChangeListener
to be invoked, then you need to ensure that the initial value also equals to 1
. That is the value behind #{list.selectedItem}"
. Initialize it to the same value as the first item during bean's construction/initialization.
this.selectedItem = "1";
这篇关于在提交时调用valueChangeListener,而不更改selectOneMenu中的选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!