Re: Displaying nested outputs by name
Max <maxxam-cuDQgYkrLFxfAa1EqD/[email protected]>
| Newsgroups | gmane.comp.java.keel.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi Shash,
Thanks again. The jstl does indeed work :-).
Max
> Max,
>
> The "nested" property is a List, not a Map, so it's contents cannot be
> retrieved by name (key), just iterated upon.
>
> What you can do though, is instead off adding the name, phone, etc.
> as Outputs, add them as attributes of the row:
>
> Output table = res.createOutput("table");
> res.add(table);
> for (int rows = 0; rows < 10; rows++) {
> Output row = res.createOutput("row" + rows);
> table.add(row);
> row.setAttribute( "name", "name" + rows );
> row. setAttribute ( "addr", "addr" + rows );
> row. setAttribute ( "tel", "tel" + rows );
> }
>
> and in the JSP:
>
> <table>
> <c:forEach var="row" items="${table.map['nested']}">
> <tr>
> <td> <c:out value="${row.map['attributes'].map['name '] .
> map[' content '] }" default=""/> </d>
> <td> <c:out value="${row. map['attributes'] . map['tel '] .
> map[' content '] }" default=""/> </td>
> <td> <c:out value="${row. map['attributes'] . map['addr '] .
> map[' content '] }" default=""/> </td>
> </tr>
> </c:forEach>
> </table>
>
> Disclaimer: I haven't actually tried the JSTL, in theory this should
> work :-). The "map" is a result of using DynaBeans instead of regular
> JavaBeans. Basically, we have the "row" output, which has a
> "attributes" property, which has a "name" property, which has a
> "content" property.
>
> HTH,
> Shash
>
> Max wrote:
>
>> I'm having a real hard time understanding how to display nested
>> elements in Keel. I'm beginning to think that I have misunderstood
>> something horribly as this should be pretty standard stuff. I
>> remember doing this quite often using Expresso and having no problems
>> in referencing the nested outputs by name.
>>
>> I need to display a table of items. My model code looks something like:
>>
>> Output table = res.createOutput("table");
>> res.add(table);
>> for (int rows = 0; rows < 10; rows++) {
>> Output row = res.createOutput("row" + rows);
>> table.add(row);
>> Output name = res.createOutput("name", "name" + rows);
>> row.add(name);
>> Output addr = res.createOutput("addr", "addr" + rows);
>> row.add(addr);
>> Output tel = res.createOutput("tel", "tel" + rows);
>> row.add(tel);
>> }
>>
>> I can display this in a jsp page by using:
>>
>> <c:forEach var="row" items="${table.map['nested']}">
>> <p><c:out value="${row.map['name']}" default=""/> = <c:out
>> value="${row.map['content']}" default=""/> </p>
>> <c:forEach var="output" items="${row.map['nested']}">
>> <p><c:out value="${output.map['name']}" default=""/> =
>> <c:out value="${output.map['content']}" default=""/> </p>
>> </c:forEach>
>> </c:forEach>
>>
>> However this simply iterates over all outputs. In my view I wish to
>> explicitly reference an output, so I would like something like:
>>
>> <table>
>> <c:forEach var="row" items="${table.map['nested']}">
>> <tr>
>> <td> {display name} </d>
>> <td> {display tel} </td>
>> <td> {display addr} </td>
>> </tr>
>> </c:forEach>
>> </table>
>>
>> Note that I am changing the order of the outputs here.
>>
>> One solution that will likely work but is so clumsy as to be
>> unreasonable is to iterate over all the outputs and test each one in
>> a <c:if> statement to see if it is the output I am looking for. This
>> solution gets even worse if I have mixed inputs/outputs/commands and
>> now also need to test the type.
>>
>> I have tried all sorts of ways to try to reference these nested
>> outputs by name but can't seem to find a way. I have also tried to
>> write a struts tag based solution without success. I have also tried
>> nesting the outputs as attributes using row.setAttribute(...) without
>> success.
>>
>> Is there a way to do this or have I got the wrong end of the stick
>> and should be approaching this problem differently?
>>
>> Thanks for any assistance.
>> Max
>> http://keelframework.org/documentation.shtml
>> Keelgroup mailing list
>> [email protected]
>> <mailto:[email protected]>
>> http://lists.keelframework.com/listinfo.cgi/keelgroup-keelframework.com
>
>
http://keelframework.org/documentation.shtml
Keelgroup mailing list
[email protected]
http://lists.keelframework.com/listinfo.cgi/keelgroup-keelframework.com