我有一个名为Experiment的bean,它有一个属性叫做Assay类型的bean的arraylist。
在jsp中,我想迭代存储在Experiment bean中的分析列表,我试着这样做:
<c:forEach items="${exp.assays}" var="ay">
<tr><td>${ay.decision}</td><td>${ay.comment}</td></tr>
</c:forEach>
'descision'和'comment'是Assay bean的属性。
但这不起作用。我收到错误:
SEVERE: javax.el.PropertyNotFoundException: The class 'beans.Experiment' does not have the property 'decision'.
好像“exp.assays”列表中的项目是bean类型的实验,而不是我期望的Assay。
所以我尝试在forEach循环中访问Experiment属性(eid,我知道我可以通过直接编写$ {exp.eid}来访问),如下所示:
<c:forEach items="${exp.assays}" var="ay">
<tr><td>${ay.eid}</td></tr>
</c:forEach>
但后来我收到了错误消息:
SEVERE: javax.el.PropertyNotFoundException: The class 'beans.Assay' does not have the property 'eid'.
任何知道发生了什么事情或我如何解决问题的人?
完整的bean代码很长,但这里是我认为与此相关的部分
实验:
public class Experiment extends dataItem implements Serializable {
private String eid;
private List<Assay> assays = new ArrayList();
public String getEid() {
return eid;
}
public void setEid(String id) {
eid = id;
}
public List<Assay> getAssays() {
return assays;
}
public void setAssays(List<Assay> assays) {
this.assays = assays;
}
}
并且分析:
public class Assay extends dataItem implements Serializable {
private Integer id;
private stock antigen;
private String decision;
private String comment;
private String freeAb;
private List<AssayData> data;
private List<conjugate> conjugates = new ArrayList();
public List<conjugate> getConjugates() {
return conjugates;
}
public void setConjugates(List<conjugate> conjugates) {
this.conjugates = conjugates;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public stock getAntigen() {
return antigen;
}
public void setAntigen(String id) {
stock s = new stock();
s.setSID(id);
this.antigen = s;
}
public String getDecision() {
return decision;
}
public void setDecision(String decision) {
this.decision = decision;
}
public String getComment() {
return comment;
}
public void setComment(String comment) {
this.comment = comment;
}
public String getFreeAb() {
return freeAb;
}
public void setFreeAb(String freeAb) {
this.freeAb = freeAb;
}
public List<AssayData> getData() {
return data;
}
public void setData(List<AssayData> data) {
this.data = data;
}
}
答案 0 :(得分:2)
我刚尝试复制您遇到的问题,并发现它可以正常运行。这是我的代码:
分析课程:
public class Assay {
private String decision;
private String comment;
Assay(){}
Assay(String decision, String comment){
setComment(comment);
setDecision(decision);
}
public String getComment() {
return comment;
}
public void setComment(String comment) {
this.comment = comment;
}
public String getDecision() {
return decision;
}
public void setDecision(String decision) {
this.decision = decision;
}
}
实验课:
public class Experiment {
private ArrayList<Assay> assays = new ArrayList<Assay>();
public Experiment() {
assays.add(new Assay("c1","d1"));
assays.add(new Assay("c2","d2"));
}
public ArrayList<Assay> getAssays() {
return assays;
}
public void setAssays(ArrayList<Assay> assays) {
this.assays = assays;
}
}
JSP:
<%
Experiment e = new Experiment();
pageContext.setAttribute("exp", e);
%>
<c:forEach items="${exp.assays}" var="ay">
<tr><td>${ay.decision}</td><td>${ay.comment}</td></tr>
</c:forEach>
输出为:c1d1 c2d2
将我上面所做的与您的代码进行比较,看看您是否可以识别出任何差异。如果您在此处发布代码时仍有问题。
答案 1 :(得分:0)
这已经解决了。
问题与我如何将值分配到检测列表有关。我犯了一个错误,将测定列表值转换为实验bean。