ModelDriven无法设置我的数据类型属性

时间:2015-08-10 08:30:48

标签: java struts2

这是我的动作类:

    public class AdminCategorySecondAction extends ActionSupport implements ModelDriven<CategorySecond> {
    private CategorySecond categorySecond = new CategorySecond();

    @Override
    public CategorySecond getModel() {
    return categorySecond;
    }

    /*
    * add categorySecond
    */
    public String add() {
    System.out.println("property category:"+categorySecond.getCategory());
    categorySecondService.add(categorySecond);
    return "add";
    }
}

这是我的实体类 Cagorysecond

    public class CategorySecond {
    private int csid;
    private String csname;
    private Category category ;
    private Set<Product> products = new HashSet<Product>();

    public int getCsid() {
        return csid;
    }
    public void setCsid(int csid) {
        this.csid = csid;
    }
    public String getCsname() {
        return csname;
    }
    public void setCsname(String csname) {
        this.csname = csname;
    }
    public Category getCategory() {
        return category;
    }
    public void setCategory(Category category) {
        this.category = category;
    }
    public Set<Product> getProducts() {
        return products;
    }
    public void setProducts(Set<Product> products) {
        this.products = products;
    }
}

这是另一个实体类别

    public class Category {
    private int cid;
    private String cname;
    private Set<CategorySecond> categoryseconds = new HashSet<CategorySecond>();

    public int getCid() {
        return cid;
    }
    public void setCid(int cid) {
        this.cid = cid;
    }
    public String getCname() {
        return cname;
    }
    public void setCname(String cname) {
        this.cname = cname;
    }
    public Set<CategorySecond> getCategoryseconds() {
        return categoryseconds;
    }
    public void setCategoryseconds(Set<CategorySecond> categoryseconds) {
        this.categoryseconds = categoryseconds;
    }
}

这是JSP中的表单:

    <form id="userAction_save_do" name="Form1" action="${pageContext.request.contextPath}/adminCategorySecond_add.action" method="post">
    <select name="category.cid">
        <s:iterator var="c" value="cList">
            <option value="<s:property value="#c.cid"/>"><s:property value="#c.cname"/></option>
        </s:iterator>
    </select>
    <button type="submit" id="userAction_save_do_submit" value="确定" class="button_ok">
        &#30830;&#23450;
    </button>
    </form>

struts.xml中:

<?xml version="1.0" encoding="UTF-8" ?>

<constant name="struts.devMode" value="false" />

<package name="usermodel" extends="struts-default">
    <global-results>
        <result name="msg">/WEB-INF/jsp/msg.jsp</result>
    </global-results>
    <action name="index" class="indexAction" method="execute">
        <result name="index">/WEB-INF/jsp/index.jsp</result>
        <result name="unlogin">/WEB-INF/jsp/login.jsp</result>
    </action>
    <action name="user_*" class="userAction" method="{1}">
        <result name="registPage">/WEB-INF/jsp/regist.jsp</result>
        <result name="input">/WEB-INF/jsp/regist.jsp</result>
        <result name="loginPage">/WEB-INF/jsp/login.jsp</result>
        <result name="activate">/WEB-INF/jsp/activated.jsp</result>
        <result name="loginSuccess" type="redirectAction">index</result>
        <result name="loginFail">/WEB-INF/jsp/login.jsp</result>
        <result name="quit" type="redirectAction">user_loginPage</result>
    </action>
    <action name="checkCode" class="checkImaAction" method="execute"></action>
    <action name="product_*" class="productAction" method="{1}">
        <result name="productFindByPid">/WEB-INF/jsp/product.jsp</result>
        <result name="productsFindByCsid">/WEB-INF/jsp/productList.jsp</result>
        <result name="productsFindByCid">/WEB-INF/jsp/productList.jsp</result>
    </action>
    <action name="cart_*" class="cartAction" method="{1}">
        <result name="add">/WEB-INF/jsp/cart.jsp</result>
        <result name="clear">/WEB-INF/jsp/cart.jsp</result>
        <result name="remove">/WEB-INF/jsp/cart.jsp</result>
        <result name="show">/WEB-INF/jsp/cart.jsp</result>
    </action>
    <action name="order_*" class="orderAction" method="{1}">
        <result name="generate">/WEB-INF/jsp/order.jsp</result>
        <result name="cartIsNull" type="redirectAction">cart_show</result>
        <result name="findByUid">/WEB-INF/jsp/orderList.jsp</result>
        <result name="findByOid">/WEB-INF/jsp/order.jsp</result>
    </action>
    <action name="adminUser_*" class="adminUserAction" method="{1}">
        <result name="loginSuccess">admin/home.jsp</result>
        <result name="loginFail">admin/index.jsp</result>
    </action>
    <action name="adminCategory_*" class="adminCategoryAction" method="{1}">
        <result name="findAll">admin/category/list.jsp</result>
        <result name="add" type="redirectAction">adminCategory_findAll</result>
        <result name="delete" type="redirectAction">adminCategory_findAll</result>
        <result name="update" type="redirectAction">adminCategory_findAll</result>
        <result name="edit">admin/category/edit.jsp</result>
    </action>
    <action name="adminCategorySecond_*" class="adminCategorySecondAction" method="{1}">
        <result name="findAll">admin/categorysecond/list.jsp</result>
        <result name="addPage">admin/categorysecond/add.jsp</result>
        <result name="editPage">admin/categorysecond/edit.jsp</result>
        <result name="add" type="redirectAction">adminCategorySecond_findAll</result>
        <result name="update" type="redirectAction">adminCategorySecond_findAll</result>
        <result name="delete" type="redirectAction">adminCategorySecond_findAll</result>
    </action>
</package>

这是错误消息和控制台输出:

08:16:02,213 ERROR InstantiatingNullHandler:38 - Could not create and/or set value back on to object
java.lang.IllegalArgumentException
    at org.springframework.asm.ClassReader.<init>(Unknown Source)
    at org.springframework.asm.ClassReader.<init>(Unknown Source)
    at org.springframework.asm.ClassReader.<init>(Unknown Source)
    at org.springframework.core.LocalVariableTableParameterNameDiscoverer.inspectClass(LocalVariableTableParameterNameDiscoverer.java:112)
    at org.springframework.core.LocalVariableTableParameterNameDiscoverer.getParameterNames(LocalVariableTableParameterNameDiscoverer.java:86)
    at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:193)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1049)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowire(AbstractAutowireCapableBeanFactory.java:344)
    at com.opensymphony.xwork2.spring.SpringObjectFactory.buildBean(SpringObjectFactory.java:179)
    at com.opensymphony.xwork2.conversion.impl.InstantiatingNullHandler.createObject(InstantiatingNullHandler.java:161)
    at com.opensymphony.xwork2.conversion.impl.InstantiatingNullHandler.nullPropertyValue(InstantiatingNullHandler.java:137)
    at com.opensymphony.xwork2.ognl.OgnlNullHandlerWrapper.nullPropertyValue(OgnlNullHandlerWrapper.java:21)
    at ognl.ASTProperty.getValueBody(ASTProperty.java:118)
    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:234)
    at com.opensymphony.xwork2.ognl.OgnlValueStack.trySetValue(OgnlValueStack.java:183)
    at com.opensymphony.xwork2.ognl.OgnlValueStack.setValue(OgnlValueStack.java:170)
    at com.opensymphony.xwork2.ognl.OgnlValueStack.setParameter(OgnlValueStack.java:148)
    at com.opensymphony.xwork2.interceptor.ParametersInterceptor.setParameters(ParametersInterceptor.java:318)
    at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:231)
    at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
    at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:239)
    at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
    at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:191)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
    at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:73)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
    at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:91)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
    at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:252)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
    at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
    at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
    at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:145)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
    at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:171)
    at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
    at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:161)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
    at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
    at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:193)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
    at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:189)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
    at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54)
    at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:563)
    at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
    at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:99)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:957)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:620)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:745)
08:16:02,215  WARN OgnlValueStack:64 - Error setting expression 'category.cid' with value '[Ljava.lang.String;@4c2858f8'
ognl.OgnlException: target is null for setProperty(null, "cid", [Ljava.lang.String;@4c2858f8)
    at ognl.OgnlRuntime.setProperty(OgnlRuntime.java:2326)
    at ognl.ASTProperty.setValueBody(ASTProperty.java:127)
    at ognl.SimpleNode.evaluateSetValueBody(SimpleNode.java:220)
    at ognl.SimpleNode.setValue(SimpleNode.java:301)
    at ognl.ASTChain.setValueBody(ASTChain.java:227)
    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:234)
    at com.opensymphony.xwork2.ognl.OgnlValueStack.trySetValue(OgnlValueStack.java:183)
    at com.opensymphony.xwork2.ognl.OgnlValueStack.setValue(OgnlValueStack.java:170)
    at com.opensymphony.xwork2.ognl.OgnlValueStack.setParameter(OgnlValueStack.java:148)
    at com.opensymphony.xwork2.interceptor.ParametersInterceptor.setParameters(ParametersInterceptor.java:318)
    at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:231)
    at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
    at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:239)
    at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
    at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:191)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
    at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:73)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
    at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:91)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
    at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:252)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
    at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
    at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
    at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:145)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
    at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:171)
    at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
    at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:161)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
    at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
    at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:193)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
    at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:189)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
    at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54)
    at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:563)
    at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
    at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:99)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:957)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:620)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:745)
property category:null

这是我的问题: *提交表单时,如何通过ModelDriven自动设置我的数据类型属性类别。 *

0 个答案:

没有答案