最近遇到的一个问题X5 Action能接收Object 的参数
var params = new justep.Request.ActionParam();
//对象参数,ObjectParam对应的class必须有包名
var objectSerialize = {name: "霍金", sex: "男", age: 70};
//var objectSerialize = "<DemoObject name='霍金' sex='男' age='70'></DemoObject>";
var objectParam = new justep.Request.ObjectParam(objectSerialize, "demo.DemoObject");
params.setObject("param_object", objectParam);
justep.Request.sendBizRequest2({
contentType: "application/json",//这个代码不能忘记
action: "demoObjectTest",
parameters: params,
callback: function(result) {
if (result.state) {
alert("调用成功!");
} else {
throw new Error("调用失败!|" + result.response.message);
}
}
});
否则报错:
013-11-02 21:30:43 invokeActions error!
com.justep.model.exception.ModelException: java.lang.NullPointerException
at com.justep.system.action.Engine.invokeActions(Unknown Source)
at com.justep.business.server.BusinessServer.doAction(Unknown Source)
at com.justep.business.server.BusinessServer.doExcute(Unknown Source)
at com.justep.business.server.BusinessServer.excute(Unknown Source)
at com.justep.business.server.BusinessServerServlet.execService(Unknown Source)
at com.justep.business.server.BusinessServerServlet.service(Unknown Source)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at com.justep.x.bs.BusinessServerServlet.service(Unknown Source)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:595)
Caused by: java.lang.NullPointerException
at demo.DemoObject.reader(DemoObject.java:66)
at com.justep.system.transform.ActionParameterTransform.transObjectParam(Unknown Source)
at com.justep.system.transform.ActionParameterTransform.transParam(Unknown Source)
at com.justep.system.transform.ActionParameterTransform.helpTransformByElement(Unknown Source)
at com.justep.system.transform.ActionParameterTransform.transform(Unknown Source)
at com.justep.system.transform.RequestTransform.transParamValue(Unknown Source)
at com.justep.system.transform.RequestTransform.transActionParams(Unknown Source)
at com.justep.system.transform.RequestTransform.transform(Unknown Source)
at com.justep.system.action.Engine.translateParameters(Unknown Source)
at com.justep.system.action.Engine.invokeActions(Native Method)
错误原因是:
contentType: "application/json" 这个contentType 指string 发送请求的格式 ,如果不指定默认是如下格式
'application/x-www-form- urlencoded' (其他解释见http://www.cnblogs.com/mumue/archive/2012/05/24/2515984.html)