Re: Using Variable as a List name
rizzz86 <[email protected]>
| Newsgroups | gmane.comp.web.freemarker.user |
|---|---|
| Message-ID | <[email protected]> |
What I want to say is that, "argList1" contains the menu names:
List argList1 = new ArrayList();
argList1.add(menu1);
argList1.add(menu2);
And "argList2, argList3" contains the subMenus of "menu1, menu2"
respectively. (This will be done while populating "argList1") It will look
like as follows:
// subMenus of menu1
List argList2 = new ArrayList();
argList2.add(subMenu1);
argList2.add(subMenu2);
argList2.add(subMenu3);
// subMenus of menu2
List argList3 = new ArrayList();
argList3.add(subMenu4);
argList3.add(subMenu5);
argList3.add(subMenu6);
I am passing HashMap "root" as the argument for by freemarker template by
setting "argList1, menu1, menu2" keys.
HashMap root = new HashMap();
root.put("argList1",argList1);
root.put("menu1",argList2);
root.put("menu2",argList3);
Now the .ftl have an outer loop for "argList1" (for main menus) and inner
loop (for their subMenus). Another thing is that I doesn't know the the menu
names (i.e. menu1, menu2) while rendering my subMenus. I have to get these
menu names from the "argList1" and use them as a list to access
"root.put("menu1",argList2) or root.put("menu2",argList3)"
Doing this <#foreach subMenu in .vars[menu]> gives the following Error
"freemarker.core.InvalidReferenceException: Expression .vars[menu] is
undefined"
OR can someone suggest a better way to render these subMenus. I also cannot
able to use 2D Arrays in ftl's.
rizzz86
rizzz86 wrote:
>
> Hi all,
>
> I am trying to use any variable as a name of list ... i.e.,
>
> <#foreach list1 in argList1>
> <#foreach list2 in list1>
> // The name of list2 is the first element of list1
> </#foreach>
> </#foreach>
>
> Following error occured if I pass variable as a list name "Expected
> collection or sequence. list1 evaluated instead to
> freemarker.ext.beans.StringModel"
>
> Can anyone help ?
>
> rizzz86
>
>
--
View this message in context: http://www.nabble.com/Using-Variable-as-a-List-name-tp25781062p25798327.html
Sent from the freemarker-user mailing list archive at Nabble.com.
------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference