首先简单描述下:
首先我用的springside-3.3.4中的CrudActionSupport 用简单的对象(意思是对象里面没有对象就不会报错,而对象里面有对象的就会报错,我里面用了List)
我先说下对象关系吧用代码:
package com.tang.flight.vo.custom;
import java.util.List;
import com.tang.flight.vo.DomeTicketFlight;
import com.tang.flight.vo.ThirdPolicyItem;
public class OrderVo {
private String orderNo;
public String getOrderNo() {
return orderNo;
}
public void setOrderNo(String orderNo) {
this.orderNo = orderNo;
}
private List<DomeTicketFlight> flights;
private List<ThirdPolicyItem> thirdPolicyItems;
public List<DomeTicketFlight> getFlights() {
return flights;
}
public void setFlights(List<DomeTicketFlight> flights) {
this.flights = flights;
}
public List<ThirdPolicyItem> getThirdPolicyItems() {
return thirdPolicyItems;
}
public void setThirdPolicyItems(List<ThirdPolicyItem> thirdPolicyItems) {
this.thirdPolicyItems = thirdPolicyItems;
}
}
package com.tang.flight.actions.order;
import java.util.ArrayList;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import com.tang.flight.actions.CrudActionSupport;
import com.tang.flight.vo.DomeTicketFlight;
import com.tang.flight.vo.ThirdPolicyItem;
import com.tang.flight.vo.custom.OrderVo;
@Namespace("/order")
@Results({@Result(type="redirect",location="manager.action",name=CrudActionSupport.RELOAD)})
public class ManagerAction extends CrudActionSupport<OrderVo> {
private static final long serialVersionUID = -6137449398836451112L;
private Long id;
public void setId(Long id) {
this.id = id;
}
private OrderVo entity;
@Override
public String delete() throws Exception {
// TODO Auto-generated method stub
return null;
}
@Override
public String input() throws Exception {
// TODO Auto-generated method stub
return INPUT;
}
@Override
public String list() throws Exception {
// TODO Auto-generated method stub
return SUCCESS;
}
@Override
protected void prepareModel() throws Exception {
if (id!=null) {
}else{
entity = new OrderVo();
ArrayList<DomeTicketFlight> flights = new ArrayList<DomeTicketFlight>(0);
flights.add(new DomeTicketFlight());
entity.setFlights(flights);
ArrayList<ThirdPolicyItem> thirdPolicyItems = new ArrayList<ThirdPolicyItem>(0);
thirdPolicyItems.add(new ThirdPolicyItem());
entity.setThirdPolicyItems(thirdPolicyItems);
}
}
@Override
public String save() throws Exception {
// TODO Auto-generated method stub
System.out.println(entity);
return RELOAD;
}
public OrderVo getModel() {
// TODO Auto-generated method stub
return entity;
}
}
<#assign s=JspTaglibs["/WEB-INF/struts-tags.tld"] />
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'index.jsp' starting page</title>
</head>
<body>
<h1></h1>
<@s.form action="manager!save.action" theme="simple">
<@s.textfield label="fltNo" title="fltNo" name="flights[0].fltNo" theme="simple"/>
<@s.textfield title="fltNo" name="thirdPolicyItems[0].protocolNo" theme="simple" />
<@s.textfield label="orderNo" title="orderNo" name="orderNo" theme="simple"/>
<@s.submit theme="simple"/>
</@s.form>
</body>
</html>
save方法保存之前会执行
@Override
protected void prepareModel() throws Exception {
if (id!=null) {
}else{
entity = new OrderVo();
ArrayList<DomeTicketFlight> flights = new ArrayList<DomeTicketFlight>(0);
flights.add(new DomeTicketFlight());
entity.setFlights(flights);
ArrayList<ThirdPolicyItem> thirdPolicyItems = new ArrayList<ThirdPolicyItem>(0);
thirdPolicyItems.add(new ThirdPolicyItem());
entity.setThirdPolicyItems(thirdPolicyItems);
}
}
很奇怪这里面的entity是空的,然后到下面这个方法时又不是空的
@Override
public String save() throws Exception {
// TODO Auto-generated method stub
System.out.println(entity);
return RELOAD;
}
下面的这个错误是在prepareModel这个方法报的
2013-01-24 14:33:46,170 [http-8083-1] WARN [com.opensymphony.xwork2.ognl.OgnlValueStack] - Error setting expression 'flights[0].fltNo' with value '[Ljava.lang.String;@179d47f'
ognl.OgnlException: source is null for getProperty(null, "0")
at ognl.OgnlRuntime.getProperty(OgnlRuntime.java:2293)
at ognl.ASTProperty.getValueBody(ASTProperty.java:114)
at ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:212)
at ognl.SimpleNode.getValue(SimpleNode.java:258)
at ognl.ASTChain.setValueBody(ASTChain.java:222)
at ognl.SimpleNode.evaluateSetValueBody(SimpleNode.java:220)
at ognl.SimpleNode.setValue(SimpleNode.java:301)
at ognl.Ognl.setValue(Ognl.java:737)
at com.opensymphony.xwork2.ognl.OgnlUtil.setValue(OgnlUtil.java:217)
at com.opensymphony.xwork2.ognl.OgnlValueStack.trySetValue(OgnlValueStack.java:186)
at com.opensymphony.xwork2.ognl.OgnlValueStack.setValue(OgnlValueStack.java:173)
at com.opensymphony.xwork2.ognl.OgnlValueStack.setParameter(OgnlValueStack.java:151)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.setParameters(ParametersInterceptor.java:292)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:203)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:90)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:176)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:192)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:187)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at org.apache.struts2.interceptor.MessageStoreInterceptor.intercept(MessageStoreInterceptor.java:194)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:510)
at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:662)
2013-01-24 14:33:46,173 [http-8083-1] WARN [com.opensymphony.xwork2.ognl.OgnlValueStack] - Error setting expression 'thirdPolicyItems[0].protocolNo' with value '[Ljava.lang.String;@22ed4b'
ognl.OgnlException: source is null for getProperty(null, "0")
at ognl.OgnlRuntime.getProperty(OgnlRuntime.java:2293)
at ognl.ASTProperty.getValueBody(ASTProperty.java:114)
at ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:212)
at ognl.SimpleNode.getValue(SimpleNode.java:258)
at ognl.ASTChain.setValueBody(ASTChain.java:222)
at ognl.SimpleNode.evaluateSetValueBody(SimpleNode.java:220)
at ognl.SimpleNode.setValue(SimpleNode.java:301)
at ognl.Ognl.setValue(Ognl.java:737)
at com.opensymphony.xwork2.ognl.OgnlUtil.setValue(OgnlUtil.java:217)
at com.opensymphony.xwork2.ognl.OgnlValueStack.trySetValue(OgnlValueStack.java:186)
at com.opensymphony.xwork2.ognl.OgnlValueStack.setValue(OgnlValueStack.java:173)
at com.opensymphony.xwork2.ognl.OgnlValueStack.setParameter(OgnlValueStack.java:151)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.setParameters(ParametersInterceptor.java:292)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:203)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:90)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:176)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:192)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:187)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at org.apache.struts2.interceptor.MessageStoreInterceptor.intercept(MessageStoreInterceptor.java:194)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:510)
at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:662)
com.tang.flight.vo.custom.OrderVo@98746b