【问题标题】:<html:select> problem with <html:options> tag<html:select> <html:options> 标签的问题
【发布时间】:2010-12-09 11:55:22
【问题描述】:

我有一个带有 struts 标签的表单,如下所示。

<html:form styleId='catform' action='/cat/submit.html' method='post'>
   <html:select property='catName' styleId='catName'>
      <html:options collection='catList' property='category'>
   </html:select>
</html:form>

在我的操作中,我将 catList 设置如下

 List <Category> catList = getCategoryList();
   request.setAttribute("catList", catList);

这里的Category是一个以catName和catId为变量的类。

我收到一条错误消息,提示找不到属性类别的 getter。 我错过了什么?

【问题讨论】:

    标签: java struts


    【解决方案1】:

    你需要放

    <html:options collection='catList' property='catId' labelProperty='catName'>
    

    struts 正在尝试获取Category 实例的category 属性

    【讨论】:

    • 如果 List 是 String 即:List catList = getCategoryList() 怎么办?这里我应该使用什么?
    • 以及 struts 调用您在列表的每个元素的 property 属性上定义的内容,如果没有指定属性,它直接使用该元素,在您的情况下是实际的 String
    【解决方案2】:

    您需要放置一个“集合”,这是在 java 标记之间完成的,如下所示:

    collection="<%= myCollection %>"
    

    或者像这样使用“名称”和“属性”属性:

    name="mybean" property="beanPropertyWhichContainsTheCollection"
    

    不要同时使用“property”和“collection”属性。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-27
      • 1970-01-01
      • 1970-01-01
      • 2011-06-10
      • 2011-09-27
      • 2014-09-19
      • 1970-01-01
      相关资源
      最近更新 更多