Xpages:在休息服务上使用删除调用时无法获得parm

时间:2016-11-02 19:50:53

标签: rest xpages

我的Xpage应用程序有一个Kendo UI网格。通过调用自定义休息服务来填充网格,该服务支持我的一个托管bean连接到java类。

阅读效果很好,但我在删除工作时遇到了麻烦。它正在工作,然后发生了一些变化(无法弄清楚是什么),现在却根本没有。我不确定错误是在Kendo UI部分还是Rest服务部分,所以我将在这里发布。

我能够调试Java并且可以看到我正在使用doDelete方法,但是我无法获取获取文档并删除它所需的parm(UNID)。

java部分如下:

package com.scoular.rest;

import java.io.IOException;
import java.io.Writer;
import java.util.Vector;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.openntf.domino.Database;
import org.openntf.domino.Document;
import org.openntf.domino.Session;
import org.openntf.domino.View;
import org.openntf.domino.ViewEntry;
import org.openntf.domino.ViewNavigator;
import org.openntf.domino.utils.Factory;

import com.ibm.commons.util.io.json.JsonException;
import com.ibm.commons.util.io.json.util.JsonWriter;
import com.ibm.domino.services.ServiceException;
import com.ibm.domino.services.rest.RestServiceEngine;
import com.ibm.xsp.extlib.component.rest.CustomService;
import com.ibm.xsp.extlib.component.rest.CustomServiceBean;
import com.scoular.cache.CacheBean;

public class restPC extends CustomServiceBean {

    @SuppressWarnings("unused")
    private Database appData;

    @Override
    public void renderService(CustomService service, RestServiceEngine engine) throws ServiceException {

        try {

            HttpServletRequest request = engine.getHttpRequest();
            HttpServletResponse response = engine.getHttpResponse();

            response.setHeader("Content-Type", "application/json; charset=UTF-8");
            String method = request.getMethod();

            if (method.equals("GET")) {
                this.doGet(request, response);
            } else if (method.equals("DELETE")) {
                this.doDelete(request, response);
            }

        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    private void doDelete(HttpServletRequest request, HttpServletResponse response) throws IOException {

        // Map prmMap = request.getParameterMap();
        // String id = prmMap.get("id").toString();
        String prmUNID = request.getParameter("id");
        Database DB = this.getAppData();
        // String t = request.getParameter("unid");
        Document tmpDoc = DB.getDocumentByUNID(prmUNID);

        if (tmpDoc != null) {
            tmpDoc.remove(true);
        } else {
        }

    }

我只发布了java代码的相关部分。

以下是调用delta的Xpage的脚本部分(Kendo Grid)。

<!--The Grid-->
<div class="row" id="grid"  style="margin-top:15px"></div>
<!--The Grid-->
 </div>
<!--The Container-->


    <xp:scriptBlock id="scriptBlock1">
        <xp:this.value><![CDATA[   $( document ).ready( function () {


        // Setup Rest Service
        var loc = ( location.href );
        var url = loc.substring( 0, loc.lastIndexOf( "/" ) ) + "/xpRest.xsp/custom/";
        var searchInput = XSP.getElementById("#searchInput");
        var crudServiceBaseUrl = "xpRest1.xsp", 
        dataSource = new kendo.data.DataSource({
            autoSync : true,
            transport   : {
                read            : {
                    url         : url + "get?status=All",
                    dataType    : "json",
                    type        : "GET"
                },
                destroy         : {
                url: function (e) {
                                    return "delete?" + e.id; 
                                    },
                    //url       : url + "delete?id=",       I HAVE ALSO TRIED THIS
                    dataType    : "json",
                    type        :"DELETE"
                    }
            },
            batch: true,
            pageSize : 15,
            scrollable : false,
            height : 600,
            parameterMap: function(options, operation) {
                   if (operation !== "read" && options.models) {
                       return {models: kendo.stringify(options.models[0].id)};
                   }},
                schema : {
                model : {
                    id : "unid",
                    fields : {
                        serialNumber : {
                            type : "string",
                            editable : false
                        },
                        statusDescription : {
                            type : "string",
                            editable : false
                        },
                        lastActionDate : {
                            type : "date",
                            editable : false
                        },
                        lastActionUser : {
                            type : "string",
                            editable : false
                        },
                        lastActionLocation : {
                            type : "string",
                            editable : false
                        },
                        assetTag : {
                            type : "string",
                            editable : false
                        },
                        model : {
                            type : "string",
                            editable : false
                        },
                        unid : {
                            type : "string",
                            nullable : false
                        }
                    }
                }
            }
        });

        // Grid
        grid = $("#grid").kendoGrid( {
           excel:{
                fileName: "PC Inventory All.xlsx",
                filterable:true,
                allPages:false
                },
            dataSource : dataSource,
            dataBound: onDataBound,
            columns : [
                    //define template column with checkbox and attach click event handler
                    {width: "30px", 
                    template: "<input type='checkbox' class='checkbox' />" },           
                    {
                        width : "150px",
                        field : "serialNumber",
                        title : "Serial Number",
                        template : "<a href=xpFormPC.xsp?action=openDocument?&key=#=unid#><h5><b>#=serialNumber#</b></h5></a>"
                    }, {
                        width : "150px",
                        field : "statusDescription",
                        title : "Status",
                        template :"#=status#&nbsp#=statusDescription#"
                    }, {
                        width : "150px",
                        field : "lastActionDate",
                        title : "Last Action Date",
                        template: "#= (lastActionDate == null) ? ' ' : kendo.toString(kendo.parseDate(lastActionDate, 'yyyy-mm-dd'), 'MM/dd/yyyy') #"
                    }, {
                        width : "150px",    
                        field : "lastActionUser",
                        title : "Last Action User"  
                    }, {
                        width : "200px",
                        field : "lastActionLocation",
                        title : "Last Action Location"
                    }, {
                       width : "150px",         
                        field : "assetTag",
                        title : "Asset Tag"
                    }, {
                        //width : "150px",          
                        field : "model",
                        title : "Model"
                    }, {
                        hidden: false,
                        width : "50px",
                        template : "<button type='button' class='btn btn-danger k-grid-delete'>X</button>"
                    }
            ],
            editable : {mode:"inline"},
            pageable : {
                refresh : true,
                pageSizes : true,
                buttonCount : 5
            },
            groupable : true,
            reorderable : true,
            filterable : true,
            selectable : true,
            sortable : true,
            resizable : true,
            columnMenu : true
            });


]]></xp:this.value>
    </xp:scriptBlock>

1 个答案:

答案 0 :(得分:0)

来自OP的

解决方案。

我弄清楚我做错了什么。我发送了一个参数图,我需要得到一个参数图。

所以我在Java代理中的代码改为:

private void doDelete(HttpServletRequest request, HttpServletResponse response) throws IOException, NotesException {

    Map<String, String[]> prmMap = request.getParameterMap();
    String[] prmID = prmMap.get("unid");
    Database DB = this.getAppData();
    Document tmpDoc = DB.getDocumentByUNID(prmID[0]);

    if (tmpDoc != null) {
        tmpDoc.remove(true);
    }
}