How to get value and text of item selected in liferay's web-content velocity template?

5.1k views Asked by At

I have structure with 1 Selection List and 1 Multi-Selection List

<dynamic-element name="mySLMenu" type="list" index-type="keyword" repeatable="false">
    <dynamic-element name="itemOne" type="0" index-type="" repeatable="false"></dynamic-element>
    <dynamic-element name="itemTwo" type="1" index-type="" repeatable="false"></dynamic-element>        
</dynamic-element>
<dynamic-element name="myMSMenu" type="multi-list" index-type="" repeatable="false">
    <dynamic-element name="itemOne" type="0" index-type="" repeatable="false"></dynamic-element>
    <dynamic-element name="itemTwo" type="1" index-type="" repeatable="false"></dynamic-element>    
</dynamic-element>

I use the following in my velocity, for Selection List:

$mySLMenu.getData()

and for Multi-selection List:

#if($myMSMenu.getOptions().size() >0)
    <select multiple>
    #foreach($item in $myMSMenu.getOptions())
        <option> $item </option>
    #end
    </select>
#end

But it only returns me the type of selected item, I want to get both the type(value) and text(name), please show me the way.

1

There are 1 answers

0
Mark On

The information of name is not stored to JournalArticle in the database, in the DB you have only the types:

<dynamic-content>\u000a\u0009\u0009\u0009<option><![CDATA[0]]></option>\u000a\u0009\u0009\u0009<option><![CDATA[1]]></option>\u000a\u0009\u0009</dynamic-content>\u000a\u0009</dynamic-element>

However you cannot simple hold this information from multi-list element.

Recommendation: If this enoughts your requriments you can take the same type as name:

<dynamic-element name="myMSMenu" type="multi-list" index-type="" repeatable="false">
    <dynamic-element name="itemOne" type="itemOne" index-type="" repeatable="false"></dynamic-element>
    <dynamic-element name="itemTwo" type="itemTwo" index-type="" repeatable="false"></dynamic-element>    
</dynamic-element>