2017-03-03 36 views
1
*I have to display US states in dropdown in .ftl file.I have stored data as key value pair in properties file as given below. I have to read data from properties file and display in ftl file. 
    AL=Alabama 
    AK=Alaska 
    AZ=Arizona 
    AR=Arkansas 
    CA=California 
    CO=Colorado 
    CT=Connecticut 
    DE=Delaware 
    DC=District of Columbia 

//我必須顯示如下給出的下拉列表。我是初學者free-marker.Could任何人都可以請幫我做到這一點。從屬性文件中顯示下拉列表中的自由標記

<select> 
     <option value=AL>Alabama</option> 
     <option value=AK>Alaska</option> 
     . 
     . 
    </select> 
+0

freemarker是一個模板引擎,你是否在爲你的應用程序使用其他框架? (如果您使用的是Struts,那麼有易於使用的標記庫) – fustaki

+0

我正在使用Spring – Girish

回答

0

如果您使用的是框架,提供一個select標籤,你可以使用它像這樣:

<form:select items="${countryMap}" /> <!-- SpringMVC --> 
<@s.select list="countryMap" /> <!--Struts2 --> 

其中countryMap在這兩種情況下是一個鍵值Map曝光(可用)模板你已經閱讀並存儲了你的屬性。

在純freemarker的會是這樣的:

<select> 
    <#list countryMap as key, value> 
     <option value="${key}">${value}</option> 
    </#list> 
</select> 

而且this page可以幫助你。