我尽可能多地检查,但我找不到问题所在,我看到很少有与我相关的堆栈溢出问题,但大多数似乎都缺少#。 我已经看到某个地方老版本的mojora lib可能会导致这种例外。我检查了我在hibernate bean中使用的名称它们看起来都很好但是我找不到问题.....
我的Html页面:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:t="http://myfaces.apache.org/tomahawk">
<h:body>
<ui:composition template="/WEB-INF/templates/layout.xhtml">
<ui:param name="category" value="Admin" />
<ui:param name="item" value="Create User" />
<ui:param name="user" value="#{createUserAccountBean}" />
<ui:define name="content">
<h:form id="productsForm">
<div class="headerbg">
<div id="innerheaderbg">
<div id="iconarea">
<img src="#{request.contextPath}/images/headerimages/productlist.png" />
</div>
<div id="headertextarea">
<p class="headingtext">Order</p>
<p id="breadCrumbtext">Order  <img src="#{request.contextPath}/images/error-bullet.gif" />
 Product Category List
</p>
</div>
<div id="otherarea"></div>
</div>
</div>
<p:growl />
<div class="widget widget-table action-table">
<div class="widget-header"> <i class="icon-th-list"></i>
<h3>Product List</h3>
<p:spacer width="10px" height="30px"/>
<h:outputLabel value="Product Category" style="color:#0A8FFF;font-weight:bold;margin-bottom:50px;"/>
<p:selectOneMenu value="#{productBean.productCategoryId}" id="pFilter" >
<f:selectItem itemLabel="--All--" itemValue="all" noSelectionOption="false"/>
<f:selectItems value="#{productCategoryBean.categoriesList}" var="category"
itemLabel="#{category.productCategoryName}"
itemValue="#{category.productCategoryId}" />
<p:ajax update=":productsForm:productsTable" event="change" listener="#{productBean.filterProducts}" />
</p:selectOneMenu>
</div> <!-- /widget-header -->
<div class="widget-content">
<p:dataTable id="productsTable" value="#{productBean.products}" var="products" rowIndexVar="rowIndex"
paginator="true" rows="10" paginatorPosition="bottom"
paginatorTemplate="{FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}" widgetVar="dt_products">
<p:column headerText="S.No">#{rowIndex+1}</p:column>
<p:column headerText="Product Name">#{products.name}</p:column>
<p:column headerText="Product Code">#{products.code}</p:column>
<p:column headerText="Price">#{products.price}</p:column>
</p:dataTable>
</div> <!-- /widget-content -->
</div>
</h:form>
<br></br>
</ui:define>
</ui:composition>
</h:body>
</html>
这是我的bean,ProductCategoryBean.java:
@Named(value = "productCategoryBean")
@Scope("session")
public class ProductCategoryBean
{
private java.util.List<ProductCategory> categoriesList;
public java.util.List<ProductCategory> getCategoriesList()
{
categoriesList.removeAll(Collections.singleton(null));
return categoriesList;
}
public void setCategoriesList(java.util.List<ProductCategory> categoriesList)
{
this.categoriesList = categoriesList;
}
}
在LoginBean.java登录时初始化类别列表
@Named(value = "loginBean")
@Scope("session")
public class LoginBean {
@Inject
private UserService userService;
@Inject
private StocktrackService stocktrackService;
@Inject
private MenuController menuController;
@Inject
private CheckOut checkOut;
@Inject
private ProductCategoryBean categoryBean;
@Inject
private ProductsBean productsBean;
private String userName;
private String password;
private String statusMessage;
HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(true);
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getStatusMessage() {
return statusMessage;
}
public void setStatusMessage(String statusMessage) {
this.statusMessage = statusMessage;
}
public String login() throws EncryptionException, ServiceException
{
StringEncrypter se = new StringEncrypter("DES");
String encpassword = se.encrypt(getPassword());
UserAccount userAccount = userService.validateLogin(userName,
encpassword);
if (userAccount == null) {
statusMessage = "The username or password is incorrect.";
return "login.xhtml";
}
session.setAttribute("UserAccount", userAccount);
statusMessage = "";
menuController.setTopmenu(menuLoader(userAccount));
checkOut.setUserId(userAccount.getUserId());
checkOut.setUsername(userAccount.getUserName());
checkOut.setUserAccount(userAccount);
//setting category list of ProductCategoryBean
categoryBean.setCategoriesList(stocktrackService.getProductCategory());
//setting product list of ProductListBean
productsBean.setProducts(stocktrackService.getProduct());
return "/pages/leave/home.xhtml?faces-redirect=true";
}
}
我收到以下错误:
> Feb 09, 2015 1:04:54 PM
> com.sun.faces.application.view.FaceletViewHandlingStrategy
> handleRenderException SEVERE: Error Rendering
> View[/pages/order/products.xhtml] javax.faces.FacesException:
> javax.el.PropertyNotFoundException: /pages/order/products.xhtml @52,59
> itemLabel="#{category.productCategoryName}": Property
> 'productCategoryName' not found on type java.lang.String at
> javax.faces.component.UIComponentBase$AttributesMap.get(UIComponentBase.java:2364)
> at
> org.primefaces.renderkit.InputRenderer.createSelectItem(InputRenderer.java:102)
> at
> org.primefaces.renderkit.InputRenderer.getSelectItems(InputRenderer.java:86)
> at
> org.primefaces.component.selectonemenu.SelectOneMenuRenderer.encodeMarkup(SelectOneMenuRenderer.java:71)
> at
> org.primefaces.component.selectonemenu.SelectOneMenuRenderer.encodeEnd(SelectOneMenuRenderer.java:65)
> at
> javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875)
> at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1786)
> at javax.faces.render.Renderer.encodeChildren(Renderer.java:168) at
> javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
> at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1779)
> at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1782)
> at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1782)
> at
> com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:419)
> at
> com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:125)
> at
> com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
> at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
答案 0 :(得分:5)
问题是您已使用参数名称category
并且它引用了String
<ui:param name="category" value="Admin" />
然后您在f:selectItems
,
<f:selectItems value="#{productCategoryBean.categoriesList}" var="category"
itemLabel="#{category.productCategoryName}"
itemValue="#{category.productCategoryId}" />
但由于它已被定义为ui:param
,因此您将获得给定的异常。要解决此问题,请在var
中使用f:selectItems
的其他名称:
<f:selectItems value="#{productCategoryBean.categoriesList}" var="productCategory"
itemLabel="#{productCategory.productCategoryName}"
itemValue="#{productCategory.productCategoryId}" />