简体   繁体   English

没有使用 Struts 2 jQuery Grid 为名称“成功”映射的“json”类型定义结果类型

[英]There is no result type defined for type 'json' mapped with name 'success' using Struts 2 jQuery Grid

I'm trying to implement struts2-jquery grid tag in my application but I'm not familiar with JSON so have some trouble with this process.我正在尝试在我的应用程序中实现 struts2-jquery 网格标记,但我不熟悉 JSON,因此在此过程中遇到了一些麻烦。

What is wrong?怎么了?

Original example uses annotation on action class @Result(name = "success", type = "json") but I'm using XML configuration:原始示例在操作类@Result(name = "success", type = "json")上使用注释,但我使用的是 XML 配置:

   <package name="default" namespace="/" extends="struts-default">
   ...
   </package>
   <package name="showcase" extends="struts-default, json-default" namespace="/">
        <action name="jgrid" class="com.user.action.GridDataProvider" method="execute" > //line 106
            <result name="success" type="json">/tabs.jsp</result>//line 107
        </action>
   </package>

Result:结果:

Unable to load configuration. - action -
file:/C:/struts2worksp/Struts2HiberQuize_4/target/classes/struts.xml:106:84
... Caused by: Unable to load configuration. - action -
file:/C:/struts2worksp/Struts2HiberQuize_4/target/classes/struts.xml:106:84
... Caused by: There is no result type defined for type 'json' mapped
with name 'success'.  Did you mean 'json'? - result -
file:/C:/struts2worksp/Struts2HiberQuize_4/target/classes/struts.xml:107:45

From Action class:Action类:

public String execute() {
        log.debug("Page " + getPage() + " Rows " + getRows()
                + " Sorting Order " + getSord() + " Index Row :" + getSidx());
        log.debug("Search :" + searchField + " " + searchOper + " "
                + searchString);

        Object list = session.get("mylist");
        if (list != null) {
            myCustomers = (List<Customer>) list;
        } else {
            log.debug("Build new List");
            myCustomers = new CustomerDAO().getList();
        }

        if (sord != null && sord.equalsIgnoreCase("asc")) {
//          Collections.sort(myCustomers);
        }
        if (sord != null && sord.equalsIgnoreCase("desc")) {
//          Collections.sort(myCustomers);
//          Collections.reverse(myCustomers);
        }

        // Count all record (select count(*) from your_custumers)
        records = CustomerDAO.getCustomersCount(myCustomers);

        if (totalrows != null) {
            records = totalrows;
        }

        // Calucalate until rows ware selected
        int to = (rows * page);

        // Calculate the first row to read
        int from = to - rows;

        // Set to = max rows
        if (to > records)
            to = records;

        if (loadonce) {
            if (totalrows != null && totalrows > 0) {
                setGridModel(myCustomers.subList(0, totalrows));
            } else {
                // All Custumer
                setGridModel(myCustomers);
            }
        } else {
            // Search Custumers
            if (searchString != null && searchOper != null) {
                int id = Integer.parseInt(searchString);
                if (searchOper.equalsIgnoreCase("eq")) {
                    log.debug("search id equals " + id);
                    List<Customer> cList = new ArrayList<Customer>();
                    Customer customer = CustomerDAO.findById(myCustomers, id);
                    

                    if (customer != null)
                        cList.add(customer);

                    setGridModel(cList);
                } else if (searchOper.equalsIgnoreCase("ne")) {
                    log.debug("search id not " + id);
//                  setGridModel(CustomerDAO.findNotById(myCustomers, id, from, to));
                } else if (searchOper.equalsIgnoreCase("lt")) {
                    log.debug("search id lesser then " + id);
//                  setGridModel(CustomerDAO.findLesserAsId(myCustomers, id, from, to));
                } else if (searchOper.equalsIgnoreCase("gt")) {
                    log.debug("search id greater then " + id);
//                  setGridModel(CustomerDAO.findGreaterAsId(myCustomers, id, from, to));
                }
            } else {
//              setGridModel(CustomerDAO.getCustomers(myCustomers, from, to));
            }
        }

        // Calculate total Pages
        total = (int) Math.ceil((double) records / (double) rows);

        // only for showcase functionality, don't do this in production
        session.put("mylist", myCustomers);

        return SUCCESS;
    }

JSP: JSP:

<s:url id="remoteurl" action="jgrid" namespace="/grid"/>
    <sjg:grid
        id="gridtable"
        caption="Customer Examples"
        dataType="json"
        href="%{remoteurl}"
        pager="true"
        gridModel="gridModel"
        rowList="5,10"
        rowNum="5"
        rownumbers="true"
    >
        <sjg:gridColumn name="id" index="id" title="ID" formatter="integer" sortable="false"/>
        <sjg:gridColumn name="name" index="name" title="Name" sortable="true"/>
        <sjg:gridColumn name="country" index="country" title="Country" sortable="false"/>
        <sjg:gridColumn name="city" index="city" title="City" sortable="false"/>
        <sjg:gridColumn name="creditLimit" index="creditLimit" title="Credit Limit" formatter="currency" sortable="false"/>
    </sjg:grid>

You have loading wrong configuration file struts.xml .您加载了错误的配置文件struts.xml The json result type is defined by the struts2-json plugin in the package json-default . json结果类型由json-default包中的struts2-json 插件定义。

If you are using this type for results in your package you should either extend the package where this result type is defined or define this result type in the package that contains results with that type.如果您在包中使用此类型的结果,则应扩展定义此结果类型的包,或在包含该类型结果的包中定义此结果类型。

The json result doesn't have a default attribute, so you shouldn't use it. json结果没有默认属性,因此您不应使用它。 The body of the tag can be used for different parameters used by this result.标签的主体可用于此结果使用的不同参数。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 没有为类型“ jasper”定义名称为“ success”的结果类型 - There is no result type defined for type 'jasper' mapped with name 'success' 没有为使用名称“success”映射的“dynamic-jasper”类型定义结果类型 - There is no result type defined for type 'dynamic-jasper' mapped with name 'success' 没有为名称为“成功”的“redirect-action”类型定义结果类型 - There is no result type defined for type 'redirect-action' mapped with name 'success' 原因:没有为类型为“链”的名称定义为“成功”的结果类型 - Caused by: There is no result type defined for type 'chain' mapped with name 'success' 如何创建结果类型为“ json”的struts动作 - How to create struts action with result type as “json” 必须声明元素类型“struts”。 at (null:26:9) org.xml.sax.SAXParseException 在 Struts 2 中使用 JQuery 网格插件 - Element type "struts" must be declared. at (null:26:9) org.xml.sax.SAXParseException in Struts 2 using JQuery Grid plugin Struts2操作不适用于JSON和分派器的结果类型 - Struts2 action not working with result type both json and dispatcher 如何在struts2中使用调度程序结果类型设置状态代码 - how to set status code using dispatcher result type in struts2 在Struts-2中使用iText生成PDF:结果类型流不起作用 - PDF generation using iText in Struts-2 : result type stream not working 在Struts 2的同一操作方法中使用多个结果类型? - Using more than one result type in the same action method in struts 2?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM