You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Konrad Billewicz <ko...@akonet.pl> on 2005/07/28 20:46:59 UTC
Filtering bean properties
I have a report with a huge number of columns (about 150). In the prior form
user can choose some of them. My current task is to show only choosen columns in
the report. I'm unexpectedly uncertain how to do it elegantly (using, of course,
Struts). The current version of this huge result page (showing all colums) is
similar to this:
<table>
<tr>
<td><b>Agreement type</b></td>
<td><b>Agreement symbol</b></td>
<!-- many, many (about 150) other columns) -->
</tr>
<logic:iterate name="treaties" id="treaty" scope="request">
<tr>
<td>
<bean:write name="treaty" property="agreementType"/>
</td>
<td>
<bean:write name="treaty" property="agreementSymbol"/>
</td>
<!-- many, many (150 too) values, mostly String and Date objects -->
</tr>
In my opinion reports are quite common, so it should be a quite common problem.
How would you handle it?
Best regards,
Konrad Billewicz
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Filtering bean properties
Posted by Ed Griebel <ed...@gmail.com>.
You could have a collection/array of fields that needed to be
displayed. You would iterate on each record in the result set. For
each row, you would then iterate thru the collection of field names,
using the field name as a key to the record "bean". I'd do it
something like below, though there may be some syntax errors
(particularly the c:out line, it's from memory). Again, this only
works if your records are key/value pairs (e.g. a Map) that can be
evaluated by the JSTL and EL.
<c:set var="fieldList" value="${myFieldList}"/>
<c:set var="records" value="${myRecordList}"/>
...
<!-- print out record header -->
<tr>
<c:forEach var="field" value="${fieldList}">
<th><c:out value="${field}"/></th>
</c:forEach>
</tr>
<c:forEach var="record" items="${records}">
<tr>
<c:forEach var="field" items="${fieldList}">
<td><c:out value="${record[field]}"/></td>
</c:forEach>
</tr>
</c:forEach>
...
-ed
On 7/28/05, Dave Newton <ne...@pingsite.com> wrote:
> Konrad Billewicz wrote:
>
> >How would you handle it?
> >
> >
> If the columns are all formatted the same (or even if they're not and
> I'm feeling saucy) I might consider writing a custom tag that does the
> entire report (maybe outputting XML for easy format changes? I dunno) or
> iterating over a collection of "columns to show" and using existing or
> custom tags to output the appropriate value or table cell.
>
> Or I might just have a million <c:if...> tags, but I really hate JSP
> pages like that.
>
> Dave
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Filtering bean properties
Posted by Dave Newton <ne...@pingsite.com>.
Konrad Billewicz wrote:
>How would you handle it?
>
>
If the columns are all formatted the same (or even if they're not and
I'm feeling saucy) I might consider writing a custom tag that does the
entire report (maybe outputting XML for easy format changes? I dunno) or
iterating over a collection of "columns to show" and using existing or
custom tags to output the appropriate value or table cell.
Or I might just have a million <c:if...> tags, but I really hate JSP
pages like that.
Dave
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org