You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Halil Karakose <ha...@gmail.com> on 2010/09/03 11:38:27 UTC
[T5.1.0.5] Loop inside grid
Hi all,
Does it make sense to use a loop to generate t:parameter components inside a
grid?
<t:grid source="searchResults" row="searchResult"
model="searchResultDisplayModel">
<t:loop source="selectedMandatoryAttributes"
value="anAttribute">
<t:parameter name="${anAttribute}">xxx</t:parameter>
</t:loop>
</t:grid>
Actually my real problem is to display a HashMap inside a grid. *What if my
row object is a hashmap, how could I display the values in a grid? *
Following code demonstrates the types of my objects(searchResults,
searchResults,
searchResultDisplayModel)
List<HashMap<String,String>> searchResults;
HashMap<String, String> searchResult;
public BeanModel getSearchResultDisplayModel() {
BeanModel model = beanModelSource.createDisplayModel(Object.class,
resources.getMessages());
Set<String> attributeSet = searchResults.keySet();
for (String s : attributeSet) {
model.add(s, null);
}
return model;
}
Thanks...
Re: [T5.1.0.5] Loop inside grid
Posted by Halil Karakose <ha...@gmail.com>.
I have found a solution to this issue, but in an inpractical way:
1. I created the attached class and transformed hashmap values into
SillyObject values:
public List<SillyObject> getSillyObjectList() {
ArrayList<SillyObject> list = new ArrayList<SillyObject>();
List<HashMap<String, String>> mapList = getHashMap();
for (HashMap<String, String> map : mapList) {
Collection<String> strings = map.values();
SillyObject sillyObject = new SillyObject(strings);
list.add(sillyObject);
}
return list;
}
private List<HashMap<String, String>> getHashMap() {
HashMap<String, String> a = new HashMap<String, String>();
a.put("cn", "12345");
a.put("dn", "12345");
a.put("en", "12345");
HashMap<String, String> b = new HashMap<String, String>();
b.put("cn", "b12345");
b.put("dn", "b12345");
b.put("en", "b12345");
List<HashMap<String, String>> hashMapList = new
ArrayList<HashMap<String, String>>();
hashMapList.add(a);
hashMapList.add(b);
return hashMapList;
}
2. I defined a grid model as below:
public BeanModel getSillyObjectModel() {
BeanModel model =
beanModelSource.createDisplayModel(SillyObject.class,
resources.getMessages());
List<HashMap<String, String>> mapList = getHashMap();
HashMap<String, String> map = mapList.get(0);
Set<String> stringSet = map.keySet();
int i = 0;
for (String s : stringSet) {
model.get("x" + i).label(s);
i++;
}
for (; i < SillyObject.COUNT; i++) {
model.exclude("x" + i);
}
return model;
}
3. And following is my grid definition in the template page:
<t:grid t:id="searchResultsGrid" source="sillyObjectList" row="sillyObject"
model="sillyObjectModel">
</t:grid>
On Mon, Sep 6, 2010 at 10:31 AM, Halil Karakose <ha...@gmail.com>wrote:
> I see that, I should use the grid component as follows:
>
> List list = CollectionFactory.newList(MyHashMap.values());
>
> <t:grid t:source="list"...
>
>
>
> But this solution renders only 1 row, doesn't it? On the other hand, I want
> to use following object in grid component as source parameter, which should
> be displayed as multiple rows.
>
>
> List<HashMap<String,String>> searchResults;
>
>
> On Fri, Sep 3, 2010 at 9:02 PM, based2 <ba...@free.fr> wrote:
>
>>
>>
>> http://stackoverflow.com/questions/2524045/tapestry5-display-grid-component-using-a-hashmap
>>
>>
>> == http://wiki.apache.org/tapestry/Tapestry5HowTos
>> == http://wiki.apache.org/tapestry/Tapestry5OpensourceApps
>> == http://wiki.apache.org/tapestry/Tapestry5ModuleRegistry
>> --
>> View this message in context:
>> http://tapestry.1045711.n5.nabble.com/T5-1-0-5-Loop-inside-grid-tp2801942p2802640.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: [T5.1.0.5] Loop inside grid
Posted by Halil Karakose <ha...@gmail.com>.
I see that, I should use the grid component as follows:
List list = CollectionFactory.newList(MyHashMap.values());
<t:grid t:source="list"...
But this solution renders only 1 row, doesn't it? On the other hand, I want
to use following object in grid component as source parameter, which should
be displayed as multiple rows.
List<HashMap<String,String>> searchResults;
On Fri, Sep 3, 2010 at 9:02 PM, based2 <ba...@free.fr> wrote:
>
>
> http://stackoverflow.com/questions/2524045/tapestry5-display-grid-component-using-a-hashmap
>
>
> == http://wiki.apache.org/tapestry/Tapestry5HowTos
> == http://wiki.apache.org/tapestry/Tapestry5OpensourceApps
> == http://wiki.apache.org/tapestry/Tapestry5ModuleRegistry
> --
> View this message in context:
> http://tapestry.1045711.n5.nabble.com/T5-1-0-5-Loop-inside-grid-tp2801942p2802640.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: [T5.1.0.5] Loop inside grid
Posted by based2 <ba...@free.fr>.
http://stackoverflow.com/questions/2524045/tapestry5-display-grid-component-using-a-hashmap
== http://wiki.apache.org/tapestry/Tapestry5HowTos
== http://wiki.apache.org/tapestry/Tapestry5OpensourceApps
== http://wiki.apache.org/tapestry/Tapestry5ModuleRegistry
--
View this message in context: http://tapestry.1045711.n5.nabble.com/T5-1-0-5-Loop-inside-grid-tp2801942p2802640.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