0

在我的 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 类型上找不到属性“entity.id”。实体

调试的时候看到实体是在bean中设置的,所以不为null。

希望大家帮忙,谢谢!

我正在使用:* Mojarra 2.1.7 * Primefaces 3.3.1

4

1 回答 1

2

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

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

在你的豆子里

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

JSF 将在你的 bean 中寻找一个属性SomeString......这就是你得到这个错误的原因尝试这样的事情

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

其中[column.key]变量将保存一个值“id”,

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

于 2012-08-23T18:32:20.230 回答