【问题标题】:h:selectManyListBox valueChangeListener is not callingh:selectManyListBox valueChangeListener 没有调用
【发布时间】:2012-03-07 11:06:19
【问题描述】:

我使用的是 Netbeans 6.9.1。我正在使用代码,其中我只是使用 selectManyListBox 并且我希望当用户选择所有值时调用我的 valueChangeListener。这是我在做什么

<h:selectManyListbox id="countryListBox" size="5" value="#{news.saarcCountries}"
                     onselect="form.submit();" valueChangeListener="#{news.changeAppearOnCountryPage}">
    <f:selectItems value="#{news.saarcCountriesMap}"/>
    <f:ajax render="countryPageExpiryCalender" />

</h:selectManyListbox>

<p:calendar id="countryPageExpiryCalender" value="#{news.countryPageExpiryDate}"
            navigator="true" style="z-index: 1;" locale="en" mode="popup"
            pattern="dd/MM/yyyy" showOn="button" readOnlyInputText="true"
            disabled="#{!news.appearOnCountryPage}" />

我也试过这个,而不是 onselect 我使用 onchnage 之类的

onchange="submit()"

这是我的 valueChangeListener

@ManagedBean(name = "news")
@ViewScoped
public class News {

    private Map<String, String> saarcCountriesMap = new LinkedHashMap<String, String>();
    private Set<String> saarcCountries = new TreeSet<String>();
    ...

    public void changeAppearOnCountryPage(ValueChangeEvent vcEvent){
        Iterator iter = saarcCountries.iterator();
        while(iter.hasNext()) {

            String name = (String)iter.next();
            System.out.println(name);
        }
    } //end of changeAppearOnCountryPage


} //end of class News

我希望当用户从 selectmanyListBox 中选择所有值时,我的 valueChangeListener 被调用,我检查我是否有 saarcCountries 变量中的值,然后我设置 appearOncountryPage = true ,所以我的日历是渲染的。但我的 valueChangeListener 没有打电话。我做错了什么?

如果我选择 onselect,那么我想问一件事,当我选择值时,这个事件将触发,或者在我选择了所有值之后。我希望当用户选择所有值时调用我的 ValueChangeListener 并且用户选择的值将在我的 saarcCountries 变量中。所以我可以检查用户选择的值。

我认为 onchange() 不适合我的情况。请帮忙。我因此被卡住了:(

谢谢

【问题讨论】:

    标签: jsf-2


    【解决方案1】:

    试试这样:

    <h:selectManyListbox id="countryListBox" size="5" value="#{news.saarcCountries}">
        <f:selectItems value="#{news.saarcCountriesMap}"/>
        <f:ajax event="change" listener="#{news.changeAppearOnCountryPage}" render="countryPageExpiryCalender"/>
    </h:selectManyListbox>
    

    你不需要 form.submit();因为你可以使用 ajax...

    【讨论】:

      猜你喜欢
      • 2015-12-07
      • 1970-01-01
      • 2012-01-03
      • 2012-01-03
      • 2013-05-02
      • 1970-01-01
      • 1970-01-01
      • 2012-01-14
      • 2015-04-08
      相关资源
      最近更新 更多