简体   繁体   English

JSF 2-找不到Ajax属性

[英]JSF 2 - Ajax Property not found

I got this error: 我收到此错误:

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

where LocaleManager is: LocaleManager在哪里:

@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); 
    }
}

and I'm calling the bean's method here: 我在这里调用bean的方法:

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

I'm learning AJAX by experimenting with this code. 我正在通过尝试此代码来学习AJAX。 But I don't understand how Ajax evaluates bean's method. 但是我不明白Ajax如何评估bean的方法。 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. 根据<f:ajax>标记文档execute属性应引用要在服务器端处理的客户端ID的集合。 This should not refer to some bean action method. 这不应引用某些bean操作方法。 The exception is coming because it's expecting a getter method which returns a collection of client IDs. 即将到来的异常是因为它期望使用getter方法来返回客户端ID的集合。

You want to use the listener attribute instead. 您想改用listener属性。

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

Note that the default event for h:selectOneMenu is already valueChange . 请注意, h:selectOneMenu的默认事件已经是valueChange You can just omit it. 您可以忽略它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM