jill juneja wrote:
> I am sorry, I think I conveyed my need differently. I do not need a
> decorator.
>
> My need is to create columns from database.
>
>
> <display:table name="bean2" >
> <display:column property="name" title="School Name" ></display:column>
>
> <c:forEach var="cl" items="bean2.bean1">
> <display:column title="${cl.title}" property="${cl.value}" />
> </c:forEach>
>
[snip]
>
>
> </display:table>
>
I think the <display:column> element above is where you're going wrong.
the property attribute needs to contain the property of bean2 that
displaytag can use to retrieve the value of the cell. You appear to be
putting the actual value into the property attribute. In the small
example below you can see that to reference a bean contained in the
ArrayList of beans I needed to use innerBeans[${index.index}].value
which results in Displaytag calling (for example for the 1st bean in the
List): getInnerBeans().get(0).getValue(). I am assuming that either you
have a single bean2 which creates a table with a single row or that all
your bean2 objects have the same number of bean1 beans in their Lists
and they are present in the same order. Hope this helps.
// File OuterBean.java
package test;
import java.util.ArrayList;
public class OuterBean {
private ArrayList innerBeans;
public OuterBean() {
innerBeans = new ArrayList();
innerBeans.add(new InnerBean("One", 5));
innerBeans.add(new InnerBean("Two", 6));
innerBeans.add(new InnerBean("Three", 7));
}
public ArrayList getInnerBeans() {
return innerBeans;
}
}
//File InnerBean.java
package test;
public class InnerBean {
private String title;
private int value;
public InnerBean(String title, int value) {
this.title = title;
this.value = value;
}
public String getTitle() {
return title;
}
public int getValue() {
return value;
}
}
// File displaytest.jsp
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://displaytag.sf.net" prefix="display" %>
<html>
<head>
</head>
<body>
<%
java.util.ArrayList outerBeans = new java.util.ArrayList();
for (int i = 0; i < 5; i++) {
outerBeans.add(new test.OuterBean());
}
request.setAttribute("items", outerBeans);
%>
<display:table uid="item" name="items">
<c:forEach var="cl" items="${item.innerBeans}" varStatus="index">
<display:column title="${cl.title}"
property="innerBeans[${index.index}].value" />
</c:forEach>
</display:table>
</body>
</html>
Ed!
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
displaytag-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/displaytag-user