按名称访问 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 实体,roles 是一个 Set。

当我加载页面时,出现以下异常:

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

呈现视图时似乎没有考虑"var"属性,因为它试图从 PersistentSet 获取属性,而不是从"角色"集中获取项目。

对正在发生的事情有什么想法吗?

提前谢谢。

好的,找到了问题。将在此处添加我的答案以帮助解决相同问题的其他人。

正在发生的事情是,在 JSF 中我无法迭代 Set,它必须是 List 类型。所以我从"设置"更改为"列表",它现在可以工作了。

无论如何,谢谢你们的帮助!

相关内容

最新更新