Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
Mk Sin
How to get value - text of item in velocity
July 20, 2012 3:18 AM
Answer

Mk Sin

Rank: Junior Member

Posts: 74

Join Date: May 25, 2012

Recent Posts

I have structure with 1 Selection List and 1 Multi-Selection List
 1
 2<dynamic-element name="mySLMenu" type="list" index-type="keyword" repeatable="false">
 3        <dynamic-element name="itemOne" type="0" index-type="" repeatable="false"></dynamic-element>
 4        <dynamic-element name="itemTwo" type="1" index-type="" repeatable="false"></dynamic-element>       
 5    </dynamic-element>
 6    <dynamic-element name="myMSMenu" type="multi-list" index-type="" repeatable="false">
 7        <dynamic-element name="itemOne" type="0" index-type="" repeatable="false"></dynamic-element>
 8        <dynamic-element name="itemTwo" type="1" index-type="" repeatable="false"></dynamic-element>   
 9    </dynamic-element>

In my velocity i use
1
2                     $mySLMenu.getData()

for Selection List
and
1
2                         #if($myMSMenu.getOptions().size() >0)
3                                <select multiple >
4                #foreach($item in $myMSMenu.getOptions())
5                                     <option> $item </option>
6                                #end
7                                </select>
8            #end

for Mutil-Selection List

But it only return me the type, I want to get both the type(value) and text(name), please show me the way emoticon
Mk Sin
RE: How to get value - text of item in velocity
August 24, 2012 3:11 AM
Answer

Mk Sin

Rank: Junior Member

Posts: 74

Join Date: May 25, 2012

Recent Posts

Last answer, It CAN NOT ?!
Scott Palmer
RE: How to get value - text of item in velocity
February 10, 2013 11:55 PM
Answer

Scott Palmer

Rank: Junior Member

Posts: 36

Join Date: January 8, 2010

Recent Posts

Anyone found a way to do this? Having the same issue. Looking into it further.
Scott Palmer
RE: How to get value - text of item in velocity
February 11, 2013 7:15 PM
Answer

Scott Palmer

Rank: Junior Member

Posts: 36

Join Date: January 8, 2010

Recent Posts

Solution by Chun Ho:

The Liferay structure does not carry the name on the options. Workaround is to define a map in Velocity to show the actual name. Which means you have to duplicate the data somewhat - but at least you only have to do it once in the template and then all your pages using the template will inherit the change. Hopefully Liferay can fix this in an upcoming release so the multi-selection field can be fully utilised.

 1
 2#set ($myMSMenuMap = {"item1" : "Item One Full Name" , "item2" : "Item TwoFull Name"})
 3<h2>List of Stuff: </h2>
 4    #if($myMSMenu.getOptions().size() >0)
 5    <ul>
 6    #foreach($item in $myMSMenu.getOptions())
 7        <li> $myMSMenuMap.get($item) </li>   
 8    #end
 9    </ul>
10 #end
Scott Palmer
RE: How to get value - text of item in velocity
February 11, 2013 7:35 PM
Answer

Scott Palmer

Rank: Junior Member

Posts: 36

Join Date: January 8, 2010

Recent Posts

Have added a ticket here: http://issues.liferay.com/browse/LPS-32957 please add your comments/votes/etc.