索引属性在表单提交时获得重复的struts2

时间:2012-07-27 06:57:46

标签: struts2

我需要在struts2中添加/编辑/删除对象表。当我提交表单时,我得到了重复的对象。

让我知道我犯了什么错误。

这是我的代码:

<s:form action="addPromotionLineItems" id="promotionLineItemsAddFormId">
    <display:table id="data"
        name="lstPromotionLineItems" sort="external" uid="row" htmlId="rowid"
        class="tborder" excludedParams="*" style="width:100%" export="false">
        <display:column titleKey="table.title.material" style="width:100px">
            <s:property value="%{#attr.row.materialCode}" />
            <s:hidden
                name="lstPromotionLineItems(%{#attr.row_rowNum-1}).promotionLineItemId"
                value="%{#attr.row.promotionLineItemId}" />
            <s:hidden
                name="lstPromotionLineItems(%{#attr.row_rowNum-1}).materialCode"
                value="%{#attr.row.materialCode}" />
            <s:hidden
                name="lstPromotionLineItems(%{#attr.row_rowNum-1}).material.description"
                value="%{#attr.row.material.description}" />
            <s:hidden
                name="lstPromotionLineItems(%{#attr.row_rowNum-1}).programId"
                value="%{#attr.row.programId}" />
        </display:column>
        <display:column property="material.description"
            titleKey="table.title.materialdesc" />

</s:form>



function refreshTableRecords(url,formNameId,resultId)
    $.ajax({
        type:'POST',
        url: url,
        data:$('#'+formNameId).serialize(),
        success : function(response) {
            $('#'+resultId).html(response); 
            },
            error:function(data)
            {
                alert(data);
            }
        });
}

我在jQuery ui modal popup中有这个内容。

1 个答案:

答案 0 :(得分:0)

我认为在struts中映射到集合数据时,语法不是:

name="lstPromotionLineItems(%{#attr.row_rowNum-1}).promotionLineItemId"

,而:

name="lstPromotionLineItems[%{#attr.row_rowNum-1}].promotionLineItemId"

输入名称中row_num属性周围的包围略有不同。