You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by "Angelo C." <an...@gmail.com> on 2012/08/03 02:40:44 UTC

Iterating a map in template

Hi,

I'm trying to iterate a map in template with following code, but, it turns
out that the entire map is only one row, I'm sure I have made something
wrong, can anybody point it out? Thanks,

template:

  <t:loop source="counts" value="count">
            <p>${count}</p>
        </t:loop>
code:

@Property
private Map<Integer, String> count;

@Cached
public Map<Integer, String> getCounts() {
  return cnts;
}

private static TreeMap<Integer, String> cnts = new TreeMap<Integer,
String>();
static {
  cnts.put(1, "ITEM1");
  cnts.put(2, "ITEM2");
}




--
View this message in context: http://tapestry.1045711.n5.nabble.com/Iterating-a-map-in-template-tp5715010.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Iterating a map in template

Posted by Ray Nicholus <rn...@widen.com>.
I don't understand.  Your loop source and value are both the same type?

The way you have this setup, it won't work.  You should consider setting
your source to the keyset of the map, and provide properties in your class
that return the value based on the current key.

On Thu, Aug 2, 2012 at 7:40 PM, Angelo C. <an...@gmail.com> wrote:

> Hi,
>
> I'm trying to iterate a map in template with following code, but, it turns
> out that the entire map is only one row, I'm sure I have made something
> wrong, can anybody point it out? Thanks,
>
> template:
>
>   <t:loop source="counts" value="count">
>             <p>${count}</p>
>         </t:loop>
> code:
>
> @Property
> private Map<Integer, String> count;
>
> @Cached
> public Map<Integer, String> getCounts() {
>   return cnts;
> }
>
> private static TreeMap<Integer, String> cnts = new TreeMap<Integer,
> String>();
> static {
>   cnts.put(1, "ITEM1");
>   cnts.put(2, "ITEM2");
> }
>
>
>
>
> --
> View this message in context:
> http://tapestry.1045711.n5.nabble.com/Iterating-a-map-in-template-tp5715010.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: Iterating a map in template

Posted by Stephan Windmüller <st...@tu-dortmund.de>.
On 03.08.2012 02:40, Angelo C. wrote:

> I'm trying to iterate a map in template with following code, but, it turns
> out that the entire map is only one row, I'm sure I have made something
> wrong, can anybody point it out? Thanks,

Try this (untested):

-----

<t:loop source="entries" value="entry">
    <p>${entry.key}: ${entry.value}</p>
</t:loop>

@Property
private Map.Entry<Integer, String> entry;

public Set<Map.Entry<Integer, String>> getEntries() {
    return cnts.entrySet;
}

-----

HTH
 Stephan



Re: Iterating a map in template

Posted by "mailinglist@j-b-s.de" <ma...@j-b-s.de>.
I expect count to be of type MapEntry or in case getCounts() returns cnts.values() instead it has to be of type string?

Jens

Sent from my iPhone

On 03.08.2012, at 02:40, "Angelo C." <an...@gmail.com> wrote:

> Hi,
> 
> I'm trying to iterate a map in template with following code, but, it turns
> out that the entire map is only one row, I'm sure I have made something
> wrong, can anybody point it out? Thanks,
> 
> template:
> 
>  <t:loop source="counts" value="count">
>            <p>${count}</p>
>        </t:loop>
> code:
> 
> @Property
> private Map<Integer, String> count;
> 
> @Cached
> public Map<Integer, String> getCounts() {
>  return cnts;
> }
> 
> private static TreeMap<Integer, String> cnts = new TreeMap<Integer,
> String>();
> static {
>  cnts.put(1, "ITEM1");
>  cnts.put(2, "ITEM2");
> }
> 
> 
> 
> 
> --
> View this message in context: http://tapestry.1045711.n5.nabble.com/Iterating-a-map-in-template-tp5715010.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org