Announcement Announcement Module
Collapse
No announcement yet.
Help me please, with Spring tag Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Help me please, with Spring tag

    This is my first experience with Spring. When I was reading the “Spring Live” all worked Ok. Equinox works well too. But in my project I have strange problem with binding. And I don’t see the difference between book example and my project.

    There is filePersonList.jsp with one and very easy form which contains one input tag only:

    Code:
    <form method="post" action="<c&#58;url value="/filePersonList.html"/>" name="searchParametersForm">
        <table class="search-panel-form" width="100%" cellpadding="0" cellspacing="0">
            <tr>
                <th>Text&#58;</th>
                <td>
                    <spring&#58;bind path="searchParameters.field">
                    <input type="text" name="field" id="field" value="$&#123;status.value&#125;"/>
                    <span class="fieldError">$&#123;status.errorMessage&#125;</span>
                    </spring&#58;bind>
                </td>
            </tr>
            <tr>
                <td class="search-panel-button-cell">
                    <input name="start" class="panel-button" type="submit" value="Start">
                </td>
                <td class="search-panel-button-cell">
                    <input name="clear" class="panel-button" type="submit" value="Clear">
                </td>
            </tr>
        </table>
    </form>
    I use the “searchParameters” as command object for the form. The class SearchParameters has all needed fields:

    Code:
    public class SearchParameters extends BaseObject 
    &#123;
        private String field;
        public String getField&#40;&#41;
        &#123;
            return field;
        &#125;
    
        public void setField&#40; String field &#41;
        &#123;
            this.field = field;
        &#125;
    &#125;
    There is information about it in the action-servlet.xml

    Code:
    <bean id="filePersonListController"class="com.company.web.FilePersonListController">
            <property name="commandName"><value>searchParameters</value></property>
            <property name="commandClass"><value> com.company.web.SearchParameters</value></property>
            <property name="formView"><value>filePersonList</value></property>
            <property name="successView"><value>redirect&#58;filePersonList.html</value></property>
    </bean>
    And sure, I have the class FilePersonListController with implemented formBackingObject method

    Code:
    public class FilePersonListController extends SimpleFormController
    &#123;
        private static Log log = LogFactory.getLog&#40; FilePersonListController.class &#41;;
    
        public ModelAndView onSubmit&#123;...&#125;;
    
        protected Object formBackingObject&#40; HttpServletRequest request &#41; throws ServletException
        &#123;
            log.debug&#40; "CALL - new SearchParameters&#40;&#41;" &#41;;
            return new SearchParameters&#40;&#41;;
        &#125;
    &#125;
    I can see my form well while I don’t use the spring:bind. Something like that:

    Code:
    <input type="text" name="field" id="field" value="111"/>
    When I add the binding I have exception:
    The exception is:

    Code:
    javax.servlet.jsp.JspTagException&#58; Neither Errors instance nor plain target object for bean name 'searchParameters' available as request attribute at org.springframework.web.servlet.tags.BindTag.doStartTagInternal&#40;BindTag.java&#58;108&#41;
    	at org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag&#40;RequestContextAwareTag.java&#58;71&#41;
    	at org.apache.jsp.filePersonList_jsp._jspService&#40;org.apache.jsp.filePersonList_jsp&#58;101&#41;
    	at org.apache.jasper.runtime.HttpJspBase.service&#40;HttpJspBase.java&#58;97&#41;
    	at javax.servlet.http.HttpServlet.service&#40;HttpServlet.java&#58;802&#41;
    	at org.apache.jasper.servlet.JspServletWrapper.service&#40;JspServletWrapper.java&#58;322&#41;
    	at org.apache.jasper.servlet.JspServlet.serviceJspFile&#40;JspServlet.java&#58;291&#41;
    	at org.apache.jasper.servlet.JspServlet.service&#40;JspServlet.java&#58;241&#41;
    	at javax.servlet.http.HttpServlet.service&#40;HttpServlet.java&#58;802&#41;
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter&#40;ApplicationFilterChain.java&#58;252&#41;
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter&#40;ApplicationFilterChain.java&#58;173&#41;
    	at com.opensymphony.module.sitemesh.filter.PageFilter.doFilter&#40;PageFilter.java&#58;39&#41;
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter&#40;ApplicationFilterChain.java&#58;202&#41;
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter&#40;ApplicationFilterChain.java&#58;173&#41;
    	at com.company.web.MessageFilter.doFilter&#40;MessageFilter.java&#58;36&#41;
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter&#40;ApplicationFilterChain.java&#58;202&#41;
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter&#40;ApplicationFilterChain.java&#58;173&#41;
    	at org.apache.catalina.core.ApplicationDispatcher.invoke&#40;ApplicationDispatcher.java&#58;672&#41;
    	at org.apache.catalina.core.ApplicationDispatcher.processRequest&#40;ApplicationDispatcher.java&#58;463&#41;
    	at org.apache.catalina.core.ApplicationDispatcher.doForward&#40;ApplicationDispatcher.java&#58;398&#41;
    	at org.apache.catalina.core.ApplicationDispatcher.forward&#40;ApplicationDispatcher.java&#58;301&#41;
    	at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel&#40;InternalResourceView.java&#58;97&#41;
    	at org.springframework.web.servlet.view.AbstractView.render&#40;AbstractView.java&#58;247&#41;
    	at org.springframework.web.servlet.DispatcherServlet.render&#40;DispatcherServlet.java&#58;839&#41;
    	at org.springframework.web.servlet.DispatcherServlet.doDispatch&#40;DispatcherServlet.java&#58;616&#41;
    	at org.springframework.web.servlet.DispatcherServlet.doService&#40;DispatcherServlet.java&#58;543&#41;
    	at org.springframework.web.servlet.FrameworkServlet.serviceWrapper&#40;FrameworkServlet.java&#58;390&#41;
    	at org.springframework.web.servlet.FrameworkServlet.doPost&#40;FrameworkServlet.java&#58;350&#41;
    	at javax.servlet.http.HttpServlet.service&#40;HttpServlet.java&#58;709&#41;
    	at javax.servlet.http.HttpServlet.service&#40;HttpServlet.java&#58;802&#41;
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter&#40;ApplicationFilterChain.java&#58;252&#41;
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter&#40;ApplicationFilterChain.java&#58;173&#41;
    	at org.displaytag.filter.ResponseOverrideFilter.doFilter&#40;ResponseOverrideFilter.java&#58;125&#41;
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter&#40;ApplicationFilterChain.java&#58;202&#41;
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter&#40;ApplicationFilterChain.java&#58;173&#41;
    	at com.opensymphony.module.sitemesh.filter.PageFilter.parsePage&#40;PageFilter.java&#58;118&#41;
    	at com.opensymphony.module.sitemesh.filter.PageFilter.doFilter&#40;PageFilter.java&#58;52&#41;
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter&#40;ApplicationFilterChain.java&#58;202&#41;
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter&#40;ApplicationFilterChain.java&#58;173&#41;
    	at com.company.web.MessageFilter.doFilter&#40;MessageFilter.java&#58;36&#41;
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter&#40;ApplicationFilterChain.java&#58;202&#41;
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter&#40;ApplicationFilterChain.java&#58;173&#41;
    	at org.apache.catalina.core.StandardWrapperValve.invoke&#40;StandardWrapperValve.java&#58;213&#41;
    	at org.apache.catalina.core.StandardContextValve.invoke&#40;StandardContextValve.java&#58;178&#41;
    	at org.apache.catalina.core.StandardHostValve.invoke&#40;StandardHostValve.java&#58;126&#41;
    	at org.apache.catalina.valves.ErrorReportValve.invoke&#40;ErrorReportValve.java&#58;105&#41;
    	at org.apache.catalina.core.StandardEngineValve.invoke&#40;StandardEngineValve.java&#58;107&#41;
    	at org.apache.catalina.connector.CoyoteAdapter.service&#40;CoyoteAdapter.java&#58;148&#41;
    	at org.apache.coyote.http11.Http11Processor.process&#40;Http11Processor.java&#58;856&#41;
    	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection&#40;Http11Protocol.java&#58;744&#41;
    	at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket&#40;PoolTcpEndpoint.java&#58;527&#41;
    	at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt&#40;LeaderFollowerWorkerThread.java&#58;80&#41;
    	at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run&#40;ThreadPool.java&#58;684&#41;
    	at java.lang.Thread.run&#40;Thread.java&#58;595&#41;
    Could you help me? What I did wrong? I use JDK 1.5, Spring 1.1.4, Tomcat 5.5.9
    Thanks in advance.

  • #2
    Try adding setCommandName("searchParameters"); to your FilePersonListController constructor.

    Comment


    • #3
      Thank you, katentim, for your answer.

      I found out where was a problem. The problem was with relation between jsp and controller. According to my scenario I need to go from formOne to formTwo (after submission). In my method onSubmit for formOne’s controller I used:

      Code:
      return new ModelAndView&#40; getSuccessView&#40;&#41;, model &#41;;
      According to examples I should use (to avoid doubling submit):

      Code:
      return new ModelAndView&#40; new RedirectView&#40; getSuccessView&#40;&#41; &#41;, model &#41;;
      When I tune my urlMapping it starts to work. Unfortunately, with RedirectView I can’t use 'model' in my next step JSP directly. I have to pass arguments by using request parameter and it is not so good for some object. It looks like I should use method formTwo-formBackingObject to process some operations and use command object to prepare JSP. May be there are other ways?

      The “return new ModelAndView( getSuccessView(), model );” works fine if I go to the same form only. I feel, I don’t understand Spring’s mechanic well yet.

      Comment

      Working...
      X