JSF 2-找不到Ajax属性 [英] JSF 2 - Ajax Property not found

查看:106
本文介绍了JSF 2-找不到Ajax属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到此错误:

execute="#{localeManager.changeLocale}": Property 'changeLocale' not found on type xyz.com.i18n.LocaleManager

LocaleManager在哪里:

where LocaleManager is:

@ManagedBean
@ViewScoped
public class LocaleManager implements Serializable
{
    // other codes here

    public static void changeLocale(AjaxBehaviorEvent event) {
       newLocale = (Locale) new Locale((String) event.toString());
       FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("selectedLocale", newLocale); 
    }
}

我在这里调用bean的方法:

and I'm calling the bean's method here:

<h:selectOneMenu id="selectLang" immediate="true" value="#{langListing.language}">
    <f:ajax event="change" execute="#{localeManager.changeLocale}" />
    <f:selectItems value="#{langListing.languages}" />
</h:selectOneMenu>

我正在通过尝试此代码来学习AJAX.但是我不明白Ajax如何评估bean的方法.这是一个直接解决的问题吗?

I'm learning AJAX by experimenting with this code. But I don't understand how Ajax evaluates bean's method. Is this a straightforward issue to resolve?

推荐答案

按照

As per the <f:ajax> tag documentation the execute attribute should refer to a collection of client IDs which are to be processed at the server side. This should not refer to some bean action method. The exception is coming because it's expecting a getter method which returns a collection of client IDs.

您想改用listener属性.

<f:ajax listener="#{localeManager.changeLocale}" />

请注意,h:selectOneMenu的默认事件已经是valueChange.您可以忽略它.

Note that the default event for h:selectOneMenu is already valueChange. You can just omit it.

这篇关于JSF 2-找不到Ajax属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆