NutzCN Logo
问答 Extjs+nutz 前台form加载时,无论如何都是只是执行failure方法
发布于 2445天前 作者 qq_78893c8c 1962 次浏览 复制 上一个帖子 下一个帖子
标签:

Extjs+nutz 前台form加载时,无论如何都是只是执行failure方法。
前台extjs的加载方法:

form.load({
 		url: "reportItem/getLableVal",
 		waitMsg: "参数读取中...",
 		method:'POST', 
// 		params: {
// 			labelValItemName:"lab	elValItemName",
// 			labelValCusprice:"labelValCuspric"
// 		},
 		success:function(form, action){
			Ext.Msg.alert("数据", "加载成功!"+action.result.success);
		},
		failure:function(form, action){
			console.log(action);
//			console.log(form);
//			Ext.Msg.alert("数据", "加载失败!"+action.result.success+", data:"+action.result.data);
			Ext.Msg.alert("数据", action.response.responseText);
		}
 	});

后台返回json串方法:

@At
	public String getLableVal(){
//	public Map<Object, Object> getLableVal(){
		boolean success = true;
		Map<Object, Object> map = new HashMap<Object, Object>();
		Map<String, String> mapList = new HashMap<String, String>();
		List<Map<String, String>> list = new ArrayList<Map<String, String>>();
//		System.out.println("------------"+lableVal.getX());
//		System.out.println("------------"+lableVal.getY());
//		System.out.println("------------"+lableVal.getHeight());
//		System.out.println("------------"+lableVal.getFontStyle());
//		System.out.println("------------"+lableVal.getUnderLine());
//		System.out.println("------------"+lableVal.getFontName());
		map.put("success", success);
		mapList.put("labelValItemName", "111");
		mapList.put("labelValCusprice", "222");
		list.add(mapList);
		map.put("list", list);
		return "{success: "+true+", list: {'labelValItemName': 'Fred. Olsen Lines','labelValCusprice': 'FXT'}}";
	}

哪里有问题呢?

28 回复

console.log(action); 输出啥

然后就木有然后了。。。

constructor {form: constructor, url: "reportItem/getLableVal", waitMsg: "参数读取中...", method: "POST", success: function…}failure: function (form, action)arguments: Arguments(2)caller: function (callback, scope, args, delay)length: 2name: "failure"prototype: Object__proto__: function ()[[FunctionLocation]]: printbar.js:596[[Scopes]]: Scopes[1]failureType: "load"form: constructorapi: undefinedbaseParams: undefinedcheckDirtyTask: Ext.util.DelayedTaskcheckValidityTask: Ext.util.DelayedTaskerrorReader: undefinedevents: ObjectfloatingAncestor: constructorhasListeners: HasListenersinitialized: truejsonSubmit: undefinedmanagedListeners: Array(56)method: undefinedmonitor: constructorowner: constructorparamOrder: undefinedparamsAsHash: undefinedreader: constructorsavePreventFocusOnActivate: undefinedstandardSubmit: undefinedtimeout: undefinedtrackResetOnLoad: undefinedurl: undefinedwaitMsgTarget: undefinedwaitTitle: undefined_boundItems: constructor__proto__: constructormethod: "POST"response: Objectresult: Objectsuccess: function (form, action)url: "reportItem/getLableVal"waitMsg: "参数读取中..."__proto__: constructor

后段日志有吗?确定已经进入口方法了吗?

@At
	public String getLableVal(){
//	public Map<Object, Object> getLableVal(){
		boolean success = true;
		Map<Object, Object> map = new HashMap<Object, Object>();
		Map<String, String> mapList = new HashMap<String, String>();
		List<Map<String, String>> list = new ArrayList<Map<String, String>>();
//		System.out.println("------------"+lableVal.getX());
//		System.out.println("------------"+lableVal.getY());
//		System.out.println("------------"+lableVal.getHeight());
//		System.out.println("------------"+lableVal.getFontStyle());
//		System.out.println("------------"+lableVal.getUnderLine());
//		System.out.println("------------"+lableVal.getFontName());
		map.put("success", success);
		mapList.put("labelValItemName", "111");
		mapList.put("labelValCusprice", "222");
		list.add(mapList);
		map.put("list", list);
		return "{'success': "+true+", list: {'labelValItemName': '111','labelValCusprice': '222'}}";
	}

返回方法里已经加了success了。还是不行。

先搞清楚Ext报啥错误

		failure:function(form, action){
			console.log(action);
                if (action.failureType === action.CONNECT_FAILURE) {
                    Ext.Msg.alert('Error',
                        'Status:'+action.response.status+': '+
                        action.response.statusText);
                }
                if (action.failureType === action.SERVER_INVALID){
                    // server responded with success = false
                    Ext.Msg.alert('Invalid', action.result.errormsg);
                }
                Ext.Msg.alert('Invalid',action.failureType);
		}

Ext.form.action.Action
view sourceLOAD_FAILURE : String
Failure type returned when the response's success property is set to false, or no field values are returned in the response's data property.

话说, 这个方法没有@Ok的?

@At("/reportItem")
@IocBean
@Ok("json")
public class ReportItemModule {

@Ok在类上

action.failureType的值是load

那我知道为啥了

        @Ok("raw:json") // 加上这个
        @At
	public String getLableVal(){

另外, 正确的用法应该是返回Map, 而非字符串

        @Ok("json")
        @At
	public NutMap getLableVal(){

@Ok("json")且方法返回值是String的时候, 启动日志有警告的

Ext.JSON.decode(): You're trying to decode an invalid JSON String: {success=true, list=[{labelValCusprice=222, labelValItemName=111}]}

用了@Ok("raw:json") 报了显性的错误,如上。

补全key的双引号

	@At
	@Ok("raw:json")
	public Map<Object, Object> getLableVal(){
		boolean success = true;
		Map<Object, Object> map = new HashMap<Object, Object>();
		Map<String, String> mapList = new HashMap<String, String>();
		List<Map<String, String>> list = new ArrayList<Map<String, String>>();
//		System.out.println("------------"+lableVal.getX());
//		System.out.println("------------"+lableVal.getY());
//		System.out.println("------------"+lableVal.getHeight());
//		System.out.println("------------"+lableVal.getFontStyle());
//		System.out.println("------------"+lableVal.getUnderLine());
//		System.out.println("------------"+lableVal.getFontName());
		map.put("success", success);
		mapList.put("labelValItemName", "111");
		mapList.put("labelValCusprice", "222");
		list.add(mapList);
		map.put("list", list);
		return map;
	}

我是这样写的。

话说,这个字符串很像一个map对象toString的输出

服了,真是怎么错怎么写。。。

改成@Ok("json:full")

@Ok("json")搭配返回值NutMap, @Ok("raw:json")搭配返回值String

还是不行,貌似几种@Ok只是改了一下几种json格式,前台依旧不走success方法。

贴入口方法的当前代码

	@At
	@Ok("json:full")
	public Map<Object, Object> getLableVal(){
		boolean success = true;
		Map<Object, Object> map = new HashMap<Object, Object>();
		Map<String, String> mapList = new HashMap<String, String>();
		List<Map<String, String>> list = new ArrayList<Map<String, String>>();
//		System.out.println("------------"+lableVal.getX());
//		System.out.println("------------"+lableVal.getY());
//		System.out.println("------------"+lableVal.getHeight());
//		System.out.println("------------"+lableVal.getFontStyle());
//		System.out.println("------------"+lableVal.getUnderLine());
//		System.out.println("------------"+lableVal.getFontName());
		map.put("success", success);
		mapList.put("labelValItemName", "111");
		mapList.put("labelValCusprice", "222");
		list.add(mapList);
		map.put("list", list);
		return map;
	}

后台方法

话说,现在ext的响应不需要data字段了?只需要success?

前台load代码:

	form.load({
 		url: "reportItem/getLableVal",
 		waitMsg: "参数读取中...",
 		method:'POST', 
// 		params: {
// 			labelValItemName:"lab	elValItemName",
// 			labelValCusprice:"labelValCuspric"
// 		},
 		success:function(form, action){
			Ext.Msg.alert("数据", "加载成功!"+action.result.success);
		},
		failure:function(form, action){
			console.log(action);
            if (action.failureType === action.CONNECT_FAILURE) {
                Ext.Msg.alert('Error', 'Status:'+action.response.status+': ' + action.response.statusText);
            }
            if (action.failureType === action.SERVER_INVALID){
                // server responded with success = false
                Ext.Msg.alert('Invalid', action.result.errormsg);
            }
            Ext.Msg.alert('Invalid',action.failureType);
		}
 	});

前台消息(节取):
failureType:"load"
Result:Object
data:null
success:false
responseText:"{↵ "success": true,↵ "list": [{↵ "labelValCusprice": "222",↵ "labelValItemName": "111"↵ }]↵}"

问题搞定,不知什么原因。
后台代码Map换成NutMap

	@At
	@Ok("json:full")
	public Object getLableVal(){
		boolean success = true;
		NutMap map = new NutMap();
		
//		System.out.println("------------"+lableVal.getX());
//		System.out.println("------------"+lableVal.getY());
//		System.out.println("------------"+lableVal.getHeight());
//		System.out.println("------------"+lableVal.getFontStyle());
//		System.out.println("------------"+lableVal.getUnderLine());
//		System.out.println("------------"+lableVal.getFontName());
		map.put("success", success);
		map.put("data", new NutMap().setv("labelValItemName", "111")
									.setv("labelValCusprice", "222"));
		return map;
	}

前台代码params:注释掉,reader注释掉

function printer_setup(){
	prtValSetup_win.show();
	var formLableVal = Ext.getCmp('formLableVal');
	var form = formLableVal.getForm();
	form.load({
 		url: "reportItem/getLableVal",
 		waitMsg: "参数读取中...",
 		method:'POST', 
 		params: {
// 			labelValItemName:"labelValItemName",
// 			labelValCusprice:"labelValCuspric"
 		},
 		success:function(form, action){
			Ext.Msg.alert("数据", "加载成功!"+action.result.success);
		},
		failure:function(form, action){
			console.log(action);
            if (action.failureType === action.CONNECT_FAILURE) {
                Ext.Msg.alert('Error', 'Status:'+action.response.status+': ' + action.response.statusText);
            }
            if (action.failureType === action.SERVER_INVALID){
                Ext.Msg.alert('Invalid', action.result.errormsg);
            }
            Ext.Msg.alert('Invalid',action.failureType);
		}
 	});

恩,看来的确是Ext.data.JsonReader没配好

添加回复
请先登陆
回到顶部