【问题标题】:How to create multiple dropdowns with the same attribute如何创建具有相同属性的多个下拉列表
【发布时间】:2015-02-26 16:38:36
【问题描述】:

我使用的是 Struts 1.3,我希望能够为不同的选项提供下拉菜单,如下所示:

以下示例具有这种格式:

Radio button:   dropdown value 1
                dropdown value 2

English: good morning
         hello
     
French: bonjour
        salut
    
Spanish: buenos dias
         hola

我的地图如下所示:

[[English, {good morning, hello}][French, {bonjoue, salut}][Spanish, {buenos dias, hola}]]

所以我的 JSP 看起来像这样(半伪代码):

For each item in the map:
   set optionList = item.values;
   
    If item.key == English {
        Radio button English:
    }
    
    If item.key == French {
        Radio button French:
     }

    If item.key == Spanish 
      Radio button Spanish:
    }
    <html:select property="salutation">
           <html:optionsCollection name="optionList" label="key" value="value"/>
    </html:select>
End for each

问题是我最终得到了 tis:

English: good morning
     hello
     bonjour
     salut
     buenos dias
     hola
     
French:  good morning
     hello
     bonjour
     salut
     buenos dias
     hola

Spanish: good morning
     hello
     bonjour
     salut
     buenos dias
     hola   

我会假设 optionList 会在每次迭代中打印出正确的值,但似乎并非如此。我还尝试在每个 IF 语句中复制 html:select 代码,但结果相同,似乎是在评估之后。

我愿意接受更好的实施建议。如果我需要进一步澄清,请告诉我。

【问题讨论】:

  • 问题出在 java 代码中,我没有在每次迭代后创建新的地图对象,所以我所做的只是传递 1 个包含所有值的单个地图。 JSP 工作正常。

标签: jsp html-select struts struts-1


【解决方案1】:

看起来您正在使用地图的entrySet() 来作为选项集合。

但您需要通过keyMap 获取选项列表。

使用映射的keySet() 的迭代器并将选项集合定义为一个值。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-10-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多