時,我有以下簡單selectOneMenu用於PropertyNotFoundException調用valueChangeListner
<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
我收到javax.el.PropertyNotFoundException
警告我Target Unreachable, identifier 'shoppingcenterControler' resolved to null
。
當我使用@ManagedBean
註解我收到警告:Property 'shopChooseAction' not found on type com.manageMyShopping.presentation.controler.ShoppingcenterControler
,whlie shopChooseAction
不是屬性,它是:
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
然而,它既不適合我,也不喜歡假的解決方案。我在尋找一個真正的解決方案,我想了解
- 爲什麼因爲預計
@Named
註釋不能正常工作?我已將相應的依賴項添加到我的項目的pom.xml
文件中。 - 爲什麼
valueChnageListener
應該提出PropertyNotFoundException
這個方法的名字?
任何幫助,高度讚賞。
我的環境:Fedora 24,Java 1.8,apache-tomcat 8.0.33,我正在使用Eclipse Mars。