0
我正在嘗試開發一個從列表中輸出文本的組合。要顯示的列表和項目屬性必須設置爲參數。所以我創造了這個複合(簡化我只是不停什麼是必要的):按名稱訪問bean屬性
<?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:c="http://java.sun.com/jsp/jstl/core"
xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:p="http://primefaces.org/ui" xmlns:o="http://omnifaces.org/ui"
xmlns:composite="http://xmlns.jcp.org/jsf/composite" xmlns:bt="http://xmlns.jcp.org/jsf/composite/tags/bt">
<composite:interface>
<composite:attribute name="id" />
<composite:attribute name="list" shortDescription="Output list (items itself)" />
<composite:attribute name="listValue" shortDescription="Bean attribute to be displayed in the list" />
</composite:interface>
<composite:implementation>
<h:panelGroup id="#{cc.attrs.id}" layout="block">
<p:repeat var="item" value="#{cc.attrs.list}">
<h:outputText value="#{item[cc.attrs.listValue]}" />
</p:repeat>
</h:panelGroup>
</composite:implementation>
</html>
用法:
<bt:selectToDataTable id="rolesSd" list="#{aclControlBean.componentSecurity.roles}" listValue="name" />
componentSecurity.roles是Hibernate的JPA實體和角色是一個集合。
當我打開頁面,獲取此異常:
Caused by: javax.el.PropertyNotFoundException: The class 'org.hibernate.collection.internal.PersistentSet' does not have the property 'name'.
at javax.el.BeanELResolver.getBeanProperty(BeanELResolver.java:568)
at javax.el.BeanELResolver.getValue(BeanELResolver.java:229)
at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
at com.sun.el.parser.AstValue.getValue(AstValue.java:139)
at com.sun.el.parser.AstValue.getValue(AstValue.java:203)
at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:226)
at org.jboss.weld.el.WeldValueExpression.getValue(WeldValueExpression.java:50)
at org.jboss.weld.el.WeldValueExpression.getValue(WeldValueExpression.java:50)
at com.sun.faces.facelets.el.ContextualCompositeValueExpression.getValue(ContextualCompositeValueExpression.java:158)
at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
... 105 more
看來「變種」屬性不被認爲是渲染視圖時,因爲它正試圖從「角色」從PersistentSet獲得的,而不是一個項目屬性組。
對發生了什麼有什麼想法?
在此先感謝。
它沒有複合工作嗎?它是否與'ui:repeat'一起使用?把錯誤文本放在谷歌? – Kukeltje
你好@Kukeltje,它在複合材料之外也不起作用。很奇怪的是,訪問bean屬性的相同代碼在f:selectItems中工作: –
@DavidFlorez,這是一個EL聲明,是的,在理論上我可以得到任何財產的訪問那樣。使用XHTML反射是不可能的。看一看:https://docs.oracle.com/cd/E19798-01/821-1841/bnahx/index.html –