【问题标题】:How to populate a drop down using string array list如何使用字符串数组列表填充下拉列表
【发布时间】:2015-07-27 08:31:36
【问题描述】:

Struts 1.x: 如何使用字符串数组列表填充下拉列表? 在表单bean(formbean)中,列表“blockIds”有getter和setter方法,它是一个字符串arraylist。举个例子

ArrayList<String> blockIds = new ArrayList<String>();
blockIds.add("A");
blockIds.add("B");

渲染后的jsp代码应该如下所示。

<select name=“selectedItem”>
    <option value=“A”>A</option>
    <option value=“B”>B</option>
</select>

【问题讨论】:

  • 停止多次发布同一个问题。并使用正确的标签。
  • 你能回答这个问题吗?看来您是 struts 方面的专家。我之前发布了相同的问题,但描述有所不同,希望得到解决方案。但没有运气。所以在这里我再次发帖。仅供参考,我已经删除了上一个。如果您能提供解决方案,我将不胜感激。
  • 在您的表单中设置此ArrayList,该表单在操作方法中声明。您可以从表单中获取列表并使用&lt;logic:iterate&gt; 标签填充下拉列表。

标签: java jsp struts-1


【解决方案1】:

这样看,

public class TestAction extends Action {


public ActionForward populateDropdown(ActionMapping mapping,ActionForm form,
    HttpServletRequest request,HttpServletResponse response) 
            throws Exception {

            ArrayList<String> blockIds = new ArrayList<String>();
            blockIds.add("A");
            blockIds.add("B");

            MyForm myForm=(MyForm)form;
            myForm.setListMsg(blockIds);
            return mapping.findForward("success");
        }
}

在 HTML 中,

<html:select property="selectedItem" styleId="standard">
     <html:optionsCollection name="myForm" 
       property="yourList" label="label" value="value"  />
</html:select>

即使您可以使用&lt;logic:iterate&gt; 标签进行迭代。 希望这会有所帮助

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-08-17
    • 2012-04-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多