当前位置: 首页 > 知识库问答 >
问题:

对于带有嵌套逻辑迭代标记的bean错误的属性值,没有getter方法

何超英
2023-03-14

我试图迭代一个ArrayList"sampleBeanList"在我的jsp使用逻辑:迭代。每个SampleBean对象都包含一个变量ArrayList"subBeanList"。我使用另一个逻辑:迭代标签内的第一个标签迭代,这样,一旦提交的形式,我可以检索的数据形式的ArrayList"sampleBeanList"和ArrayList"subBeanList"变量为每个SampleBean.我相应地添加了setters和getters,如下所示。但是,我不能理解这个问题,因为当我运行时,我得到了以下错误:

“bean子BeaneElement的属性值没有getter方法”

源代码:

JSP:

<logic:iterate id="toFamilyElement" name="myRolloverForm" property="sampleBeanList" indexId="toFamilyIndex"  type="MYRolloverFamilyBean">
    <tr>    
        <td align="center">
            <%=sno%>    
        </td>
        <td align="center" rowspan="<bean:write name="toFamilyElement" property="toFamilyListSize"/>">
            <bean:write name="toFamilyElement" property="fromFamily"/>
        </td>   
        <td align="center" rowspan="<bean:write name="toFamilyElement" property="toFamilyListSize"/>">
            <IMG src="images/rightArrow.png" width="35px" height="30px" />
        </td>
        <td align="center">
            <table width="100%" height="100%" border="1" cellpadding="0" cellspacing="0">
                <%int toFamilyListCount = 0; %>
                <logic:iterate id="subBeanElement" name="toFamilyElement" property="toFamilyList" indexId="toFamilyListIndex" type="String">
                    <html:hidden styleId='<%="toFamilyCode[" + toFamilyCount+"]["+toFamilyListCount+"]"%>' indexed="true" name="subBeanElement" property="value"/>
                    <tr>
                        <td>
                            <bean:write name="subBeanElement" property="value"/>
                        </td>
                    </tr>
                    <%toFamilyListCount++; %>
                </logic:iterate>
            </table>
        </td>
    </tr>
    <%toFamilyCount++; 
    sno++;%>    
</logic:iterate>

MYRolloverForm(包含SampleBeanList变量的表单bean):

public class MYRolloverForm extends ActionForm {


    private ArrayList<SampleBean> sampleBeanList= new ArrayList<SampleBean>();

    public ArrayList<SampleBean> getSampleBeanList() {
        return sampleBeanList;
    }

    public void setSampleBean(ArrayList<SampleBean> sampleBeanList) {
        this.sampleBeanList = sampleBeanList;
    }

    public void setToFamilyElement(int index, SampleBean value) {
        this.sampleBeanList.add(value);
    }

    public SampleBean getToFamilyElement(int index) {
        int size = sampleBeanList.size();
        while (index >= size) {
            sampleBeanList.add(new SampleBean());
            size = sampleBeanList.size();
        }
        return this.sampleBeanList.get(index);
    }
}

SampleBean(包含子BeanList):

public class SampleBean implements Serializable {

    private ArrayList<String> subBeanList = new ArrayList<String>();

    public ArrayList<String> getSubBeanList() {
        return subBeanList;
    }

    public void setSubBeanList(ArrayList<String> subBeanList) {
        this.subBeanList = subBeanList;
    }

    public void setSubBeanElement(int index, String value) {
        this.subBeanList.add(value);
    }

    public String getSubBeanElement(int index) {
        int size = subBeanList.size();
        while (index >= size) {
            subBeanList.add(new String());
            size = subBeanList.size();
        }
        return this.subBeanList.get(index);
    }
}

请提出解决方案!!!

共有2个答案

陶俊晤
2023-03-14

我有问题。我试图在第二个逻辑中获取字符串元素的属性“值”:迭代循环。这就是为什么我得到上面的错误。我修改了ArrayList,而不是ArrayList,我使用ArrayList,其中OptionBean是一个定义有“值”变量的类。它解决了我的问题。谢谢你的回答:)

万俟嘉珍
2023-03-14

我认为您将列表中的元素与每个元素的属性混为一谈:

name应该是bean(一个SampleBean),而value应该是要访问的属性的名称(subBeanElement):

<logic:iterate id="mySample" name="toFamilyElement" property="toFamilyList" indexId="toFamilyListIndex" type="String">
    <html:hidden styleId='<%="toFamilyCode[" + toFamilyCount+"]["+toFamilyListCount+"]"%>' indexed="true" name="mySample" property="subBeanElement"/>
    <tr>
        <td>
            <bean:write name="mySample" property="subBeanElement"/>
        </td>
    </tr>
    <%toFamilyListCount++; %>
</logic:iterate>
 类似资料:
  • 我正在尝试用Struts填充select。但是,我得到了一条错误消息:name在其所查找的类中也没有名为“label”的变量,因此我不知道它是如何查找 表单类是一个非常典型的实体类 关于为什么会出现这个错误,有什么建议吗?

  • 我试图使用NetworkX来读取Shapefile,并使用函数来生成包含节点和边的Shapefile,但是当我试图运行代码时,它会给我以下错误: 我使用的是Python 3.4,并通过pip安装安装了NetworkX。 在这个错误之前,它已经给了我另一个说“xrange不存在”或类似的东西,所以我查了一下,只是在nx_shp.py文件中将更改为,这似乎去解决它。 据我所知,它可能与Python版本

  • 嗨,我试图使用strut得到一个bean到我的jsp代码,我在我的jsp页面中使用的bean是:但是每当我运行jsp时,我就会收到 bean的“unitForm”的属性“testData.team.type”没有getter方法。 我正在尝试将棒球写入我的JSP页面。 我的行动表单的代码是: 测试数据类具有: 最后在我的体育课上:

  • Struts(1.38)新手,我得到以下错误:没有getter方法可用于名称hsForm下的bean的属性hs.has关系ToTeam。我被告知在HSDivForm中创建getHs和setHs方法,但这是问题所在吗?或者我该怎么做? 我的豆子: 我的表格: 我的jsp:

  • 我正在尝试反序列化一个 JSON 响应,其中包含一些标准字段和一个包含子类属性的 嵌套对象,例如: 字段< code>id和< code>type是标准的,所以我有一个基类< code>Base,然后扩展一些更具体的类: 如何让杰克逊读取 对象作为进一步字段值的来源?我假设我需要创建一个自定义反序列化程序,但我不确定如何具体完成此操作。

  • 如何使用自定义setter声明属性,但在Kotlin中没有getter?例如,在安科,他们这样做: 但在我看来,这有点骇人。这样做对吗?如果是,那么当一个项目没有Anko依赖关系时,情况会怎样呢? 附言:让我说清楚——我想没有吸气剂,而不是私人吸气剂