【问题标题】:No getter method for property value of bean error with nested logic iterate tags带有嵌套逻辑迭代标签的bean错误的属性值没有getter方法
【发布时间】:2014-09-14 06:52:01
【问题描述】:

我正在尝试使用 logic:iterate 在我的 jsp 中迭代一个 ArrayList“sampleBeanList”。每个 SampleBean 对象都包含一个变量 ArrayList “subBeanList”。我正在使用另一个逻辑:迭代第一个标签内的标签进行迭代,这样一旦提交表单,我就可以检索每个 SampleBean 的 ArrayList“sampleBeanList”和 ArrayList“subBeanList”变量形式的数据。我相应地添加了 setter 和 getter,如下所示。但是,我无法理解这个问题,因为当我运行时,我收到以下错误:

"没有获取bean subBeanElement 属性值的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(包含 subBeanList):

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);
    }
}

请提出解决方案!!!

【问题讨论】:

    标签: java jsp arraylist struts


    【解决方案1】:

    我认为您正在将列表中的元素与每个元素的属性混淆:

    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>
    

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 2014-03-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-07-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多