【问题标题】:displaying nested beans in a primefaces, JSF webapp在primefaces,JSF webapp中显示嵌套bean
【发布时间】:2012-08-23 17:03:12
【问题描述】:

在我的 JSF 页面中,我有以下内容:

<h:outputText value="#{entity[column.key]}" />

我的实体豆(简单版):

public class Entity implements Serializable {
private int id;
private Entity entity;

public int getId() {
    return id;
}
public void setId(int id) {
    this.id = id;
}

public Entity getEntity() {
    return this.entity;
}
public void setEntity(Entity entity) {
    this.entity = entity;
}
}

当我的 [column.key] 变量保存为值“id”时,将显示实体的 id 属性。 当我的 [column.key] 变量保持为值“entity.id”时,我收到一个错误:

/WEB-INF/flows/parametersPage/parametersPage.xhtml @51,66 value="#{entity[column.key]}":在 eu.acsone.agc.db 类型上找不到属性“entity.id” .entity.Entity

debug的时候看到bean中设置了entity,所以不为null。

希望大家帮忙,谢谢!

我正在使用: * 莫哈拉 2.1.7 * Primefaces 3.3.1

【问题讨论】:

    标签: java spring jsf primefaces


    【解决方案1】:

    这是因为你没有属性(这在 java 中实际上是非法的 - 不允许使用点分隔符)

    private int entity.id; //its not even legal
    

    在你的豆子里

    当你尝试像这样value="#{entity[variableThatHoldSomeString]}":访问你的bean时

    JSF 将在您的 bean 中查找属性 SomeString...这就是您收到此错误的原因 试试这样的

    value="#{entity.entity[column.key]}":
    

    [column.key] 变量将保存一个值 'id',

    (顺便说一句,相同类型的嵌套属性对我来说看起来很奇怪)

    【讨论】:

    • 我不认为他想解析一个名为“entity.id”的整数,而是想到达字段“entity”的“id”字段。他可能在做一些奇怪的事情,但从技术上讲,使用例如 bean utils 的 EL 函数可以解决它。
    猜你喜欢
    • 2012-07-21
    • 1970-01-01
    • 2010-10-18
    • 2014-08-10
    • 1970-01-01
    • 1970-01-01
    • 2012-05-14
    • 2021-04-07
    • 1970-01-01
    相关资源
    最近更新 更多