首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >调用PropertyNotFoundException时valueChangeListner

调用PropertyNotFoundException时valueChangeListner
EN

Stack Overflow用户
提问于 2016-07-19 20:40:12
回答 1查看 93关注 0票数 0

我有以下简单的selectOneMenu

代码语言:javascript
复制
<h:selectOneMenu id="shop" styleClass="tcell"
                 value="#{shoppingcenterControler.shoppingCenterScreenBean.shoppingcenterName}"
                 onchange="submit()"
                 valueChangeListener="#{shoppingcenterControler.shopChooseAction}">
  <f:selectItem itemValue="#{option.defaultShoppingcenter}" itemLabel="#{option.defaultShoppingcenter}"></f:selectItem>
  <f:selectItems value="#{shoppingCenterScreenBean.shoppingcenternames}"></f:selectItems>
</h:selectOneMenu>

当我在@Named上使用shoppingcenterControler注释时,我会收到一个警告shoppingcenterControlerjavax.el.PropertyNotFoundException

当我使用@ManagedBean注释时,我收到警告:Property 'shopChooseAction' not found on type com.manageMyShopping.presentation.controler.ShoppingcenterControler,whlie shopChooseAction不是属性,它是:

代码语言:javascript
复制
public void shopChooseAction(ValueChangeEvent event){
    String shopName = getShoppingCenterScreenBean().getShoppingcenterName();
    if (!shopName.equals(defaultShopp)) {
        for (ShoppingCenterScreenBean thisShop : Shoppinglistcontroler.getShoppinglistScreenBean().getShoppingCentersScreenBean()) {
            if (!thisShop.getShoppingcenterName().equals(shopName)) {

                ShoppingCenterScreenBean newShoppingcenter = new ShoppingCenterScreenBean();
                newShoppingcenter.setShoppingcenterName(shopName);
                ShoppinglistScreenBean shoppinglist = Shoppinglistcontroler.getShoppinglistScreenBean();
                shoppinglist.getShoppingCentersScreenBean().add(newShoppingcenter); 
            }
        }
    }
}

我看过不同的链接,包括以下内容:One somehow similar question

然而,它对我没有作用,我也不喜欢伪造的解决方案。我正在寻找一个真正的解决方案,我想要理解

  1. 为什么@Named注释不能像预期的那样起作用?我已经将相应的依赖项添加到项目的pom.xml文件中。
  2. 为什么valueChnageListener应该在方法的名称上引发PropertyNotFoundException

任何帮助都是非常感谢的。

我的环境: Fedora 24,Java1.8,apache 8.0.33,我正在使用Eclipse。

EN

回答 1

Stack Overflow用户

发布于 2016-07-19 22:10:52

我终于解决了我的问题。我没有使用valueChangeListener作为标记<h:selectOneMenu>的属性,而是使用了标记<f:valueChangeListener>,如下所示:

代码语言:javascript
复制
<h:selectOneMenu id="shop" styleClass="tcell"
                                value="#{shoppingcenterControler.shoppingCenterScreenBean.shoppingcenterName}"
                                onchange="submit()">
                                <f:selectItem itemValue="#{option.defaultShoppingcenter}" itemLabel="#{option.defaultShoppingcenter}"></f:selectItem>
                                <f:selectItems
                                    value="#{shoppingCenterScreenBean.shoppingcenternames}"></f:selectItems>
                                <f:valueChangeListener type="com.manageMyShopping.presentation.controler.ShoppingcenterListener"></f:valueChangeListener>
</h:selectOneMenu>

我将类ShoppingcenterListener添加为:

代码语言:javascript
复制
public class ShoppingcenterListener implements ValueChangeListener {

FacesContext context = FacesContext.getCurrentInstance();
String bundleName = "com.manageMyShopping.presentation.elementaryBeans.itemOptions";
Locale local = context.getViewRoot().getLocale();
ResourceBundle bundle = ResourceBundle.getBundle(bundleName, local);
String defaultShop = bundle.getString("defaultShoppingcenter");

@Override
public void processValueChange(ValueChangeEvent event) throws AbortProcessingException {

    String shopName = event.getNewValue().toString();
    System.out.printf("ShoppingcenterNqme is: %s\n", shopName);
    if (!shopName.equals(defaultShop)) {
        for (ShoppingCenterScreenBean thisShop : Shoppinglistcontroler.getShoppinglistScreenBean().getShoppingCentersScreenBean()) {
            if (!thisShop.getShoppingcenterName().equals(shopName)) {

                ShoppingCenterScreenBean newShoppingcenter = new ShoppingCenterScreenBean();
                newShoppingcenter.setShoppingcenterName(shopName);
                ShoppinglistScreenBean shoppinglist = Shoppinglistcontroler.getShoppinglistScreenBean();
                shoppinglist.getShoppingCentersScreenBean().add(newShoppingcenter); 
            }
        }
    }
}

}

这解决了我的问题。尽管如此,我还是不明白为什么@Named注释不像它所设想的那样起作用。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38468108

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档