【问题标题】:pass an arraylist from jsp to action class using struts2使用struts2将数组列表从jsp传递到动作类
【发布时间】:2012-11-08 08:14:01
【问题描述】:

我有一个带有 jqgrid 的 jsp 页面我想将该网格数据传递给操作类。我正在使用 cellEdit 编辑 jqgrid 数据,现在我想将这个新数据传递给操作类以更新数据库中的这些数据。我该怎么做将 jqgrid 数据从 jsp 传递到 action 类?

 <sjg:grid id="gridtable" caption=" " dataType="json" 
                href="%{listurl}"
                gridModel="listMS_AUTONUMBER"
                            cellEdit="true"
                    cellurl="%{cellediturl}">

<sjg:gridColumn frozen="false"  name="autonumberCd" index="autonumberCd" title="%{getText('autonumber.autonumbercode')}"
                    sortable="true" search="true" editable="true" key="true" editoptions="{maxlength :2}"
                    editrules="{required:true,custom:true,custom_func:validateCapitalAlphanumeric}" formatter="String"  formoptions="{elmsuffix:'  *'}"/>     

                <sjg:gridColumn name="autonumberNm" index="autonumberNm" title="%{getText('autonumber.autonumbername')}"
                    sortable="true" editable="true" edittype="text" editrules="{required:true}" editoptions="{maxlength :10}" formoptions="{elmsuffix:'  *'}" />        

                <sjg:gridColumn name="nextAutonumber" index="nextAutonumber" title="%{getText('autonumber.nextautonumber')}"
                    sortable="true" editable="true" edittype="text" editrules="{required:true,custom:true,custom_func:validateNumericOnly}" editoptions="{maxlength :10}" align="right" formoptions="{elmsuffix:'  *'}" />                      
            </sjg:grid>

这是我的 jqgrid,其中listMS_AUTONUMBER 是从数据库中检索值并来自另一个动作类的列表。

【问题讨论】:

  • 你在 jqgrid 中使用了什么样的格式? json?您应该发布代码,以便人们更好地理解您

标签: jqgrid struts2


【解决方案1】:

要将 jqgrid 数据从 jsp 传递到操作类,我使用 json 如下:

var data=jQuery("#gridtable").jqGrid('getRowData');      //this method gets all the data from grid
var postData = JSON.stringify(data);          //using json stringify convert the data in string format
alert(postData);

使用警报我正在以字符串格式显示 jqgrid 的数据。

之后,我通过 AJAX 将这些数据发送到操作类,如下所示:

$.ajax({
       type: "Get",
    url: "action_name?AutoList="+postData,
    data : {
           jgGridData: postData,
        },
    dataType:"json",
    contentType: "application/json; charset=utf-8",
});

在action类中,将这个String转成json格式如下:

JSONArray outerArray = (JSONArray) JSONSerializer.toJSON(AutoList); 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-04-28
    • 2012-04-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多