Announcement Announcement Module
Collapse
No announcement yet.
use hashmap to simplify commandClass? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • use hashmap to simplify commandClass?

    Hi, all

    I just read a post in this forum, the author created a simple bean which only has a hashmap. The hashmap hold all fields in html form, but I can't get it work.

    Here is the command class source:


    import java.util.*;

    public class hashCommand {

    private HashMap formData;

    public hashCommand() {

    formData=new HashMap();

    formData.put("username","");
    formData.put("password","");

    }

    public void setHashMap(HashMap formData) {

    this.formData=formData;

    }

    public HashMap getHashMap() {

    return this.formData;

    }

    }


    I have the following configuration for my dispatcher servlet:

    <bean name="/signonForm.form" class="signonFormController">
    <property name="sessionForm" value="true"/>
    <property name="commandClass" value="hashCommand"/>
    <property name="formView" value="signonForm"/>
    <property name="successView" value="welcome"/>
    </bean>

    My JSP looks like this:

    <spring:bind path="command.formData['username']">
    <tr><td>ID:</td><td><input type=text name=username size=15 value="<c:out value="${status.value}"/>"</td></tr>
    </spring:bind>


    I can't get it work and tomcat complained:

    2005/10/7 下? 05:05:03 org.springframework.web.servlet.FrameworkServlet processRequest
    嚴?的: Could not complete request
    org.apache.jasper.JasperException: Invalid property 'formData[]' of bean class [hashCommand]: Bean property 'formData[]' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?
    at org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:370)
    at org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:291)
    at org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:241)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:802)
    at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:252)
    at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:173)
    at org.apache.catalina.core.ApplicationDispatcher.inv oke(ApplicationDispatcher.java:672)
    at org.apache.catalina.core.ApplicationDispatcher.pro cessRequest(ApplicationDispatcher.java:463)
    at org.apache.catalina.core.ApplicationDispatcher.doF orward(ApplicationDispatcher.java:398)
    at org.apache.catalina.core.ApplicationDispatcher.for ward(ApplicationDispatcher.java:301)
    at org.springframework.web.servlet.view.InternalResou rceView.renderMergedOutputModel(InternalResourceVi ew.java:97)
    at org.springframework.web.servlet.view.AbstractView. render(AbstractView.java:250)
    at org.springframework.web.servlet.DispatcherServlet. render(DispatcherServlet.java:928)
    at org.springframework.web.servlet.DispatcherServlet. doDispatch(DispatcherServlet.java:705)
    at org.springframework.web.servlet.DispatcherServlet. doService(DispatcherServlet.java:625)
    at org.springframework.web.servlet.FrameworkServlet.p rocessRequest(FrameworkServlet.java:392)
    at org.springframework.web.servlet.FrameworkServlet.d oGet(FrameworkServlet.java:347)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:689)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:802)
    at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:252)
    at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:173)
    at org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperValve.java:213)
    at org.apache.catalina.core.StandardContextValve.invo ke(StandardContextValve.java:178)
    at org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:126)
    at org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:105)
    at org.apache.catalina.core.StandardEngineValve.invok e(StandardEngineValve.java:107)
    at org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:148)
    at org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:856)
    at org.apache.coyote.http11.Http11Protocol$Http11Conn ectionHandler.processConnection(Http11Protocol.jav a:744)
    at org.apache.tomcat.util.net.PoolTcpEndpoint.process Socket(PoolTcpEndpoint.java:527)
    at org.apache.tomcat.util.net.LeaderFollowerWorkerThr ead.runIt(LeaderFollowerWorkerThread.java:80)
    at org.apache.tomcat.util.threads.ThreadPool$ControlR unnable.run(ThreadPool.java:684)
    at java.lang.Thread.run(Unknown Source)

    ---

    Is there any successfully story? How can I make it work?


    Thanks,

    Vincent Chen

  • #2
    Your setter is called getHashMap, not getFormData.

    Comment


    • #3
      Take a look at...

      Hi vincent,

      you can take the code from my second post in this thread http://forum.springframework.org/showthread.php?t=18687

      This was copied and pasted from a working application, so it is running.

      Also take a look in the contents of my third post (action-servlet.xml) in the same thread.

      As said, everything is working.
      Last edited by robyn; May 14th, 2006, 08:01 PM.

      Comment

      Working...
      X