Announcement Announcement Module
Collapse
No announcement yet.
SimpleFormController Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • SimpleFormController

    I have a form and a SimpleFormController, and the values I enter are not getting to the controller.


    The controller:

    Code:
        public DocumentFormController() {
            
        	setCommandName("doc"); 
    	setSessionForm(true);
        }
        /**
         * 
         */
        public ModelAndView onSubmit(Object command, BindException errors)
                throws ServletException 
        {
            NewDocument doc = (NewDocument) command;
    
           [b] //The following line has empty string for the title and not the title entered[/b]:
            logger.info("doc TITLE is " + doc.getTitle() );
    
    ...
    
            return new ModelAndView(new RedirectView(getSuccessView()));
        } ...
    The xml:

    Code:
        <!--  Validator and Form Controller for the "New Document" page -->
        <bean id="createDocForm" class="com.myApp.web.DocumentFormController">
            <property name="sessionForm"><value>true</value></property>
            <property name="commandName"><value>doc</value></property>
            <property name="commandClass"><value>com.myApp.business.NewDocument</value></property>
            <property name="formView"><value>createdoc</value></property>
            <property name="successView"><value>inbox.htm</value></property>
            <property name="documentManager">
                <ref bean="docMan"/>
            </property>
            <property name="userManager">
                <ref bean="userMan"/>
            </property>
        </bean>
    The jsp :
    Code:
    <%@ page session="false"%>
    <%@ taglib prefix="c" uri="http&#58;//java.sun.com/jstl/core" %>
    <%@ taglib prefix="spring" uri="/spring" %>
    
    ...
    
    	<form method="post" enctype="multipart/form-data" name="newdocument">
    	<table>
    		
    		<tr>
    			<th>
    				Title
    			</th>
    			<td><spring&#58;bind path="doc.title"><input type="text" name="title"  size="40" maxlength="255" value="<c&#58;out value="$&#123;status.value&#125;"/>" /></spring&#58;bind></td>
    		</tr>
    		<tr>
    			<th>
    				Purpose
    			</th>
    			<td><spring&#58;bind path="doc.purpose"><textarea name="purpose" rows="6" cols="40"><c&#58;out value="$&#123;status.value&#125;"/></textarea></spring&#58;bind></td>
    		</tr>
    		<tr>
    			<th>
    				
    			</th>
    			<td><input type="submit" name="submit" value="Save" />
    			<input type="button" name="cancel" value="Cancel" onclick="history.back&#40;&#41;" /></td>
    		</tr>
    	</table>
    		
    	</form>
    And the command class:

    Code:
    public class NewDocument 
    &#123;
        private String title;
        private int statusId;
        private int id;
        private String purpose;
        private int ownerId;
        private User owner;
    
        /**
         * 
         * @param i
         */
        public void setId&#40;int i&#41; &#123;
            id = i;
        &#125;
    
        /**
         * 
         * @return int
         */
        public int getId&#40;&#41; &#123;
            return id;
        &#125;
    
        /**
         * 
         * @param s
         */
        public void setTitle&#40;String s&#41; 
        &#123;
            title = s;
        &#125;
    
        /**
         * 
         * @return String
         */
        public String getTitle&#40;&#41; 
        &#123;        
            return title;
        &#125;
    
        /**
         * 
         * @param s
         */
        public void setStatusId&#40;int id&#41; 
        &#123;
            statusId = id;
        &#125;
    
        /**
         * 
         * @return int
         */
        public int getStatusId&#40;&#41; 
        &#123;        
            return statusId;
        &#125;
    
        /**
         * 
         * @param s
         */
        public void setPurpose&#40;String s&#41; 
        &#123;
            purpose = s;
        &#125;
    
        /**
         * 
         * @return String
         */
        public String getPurpose&#40;&#41; 
        &#123;        
            return purpose;
        &#125;
    
       
        /**
         * 
         * @param User
         */
        public void setOwner&#40;User u&#41; 
        &#123;
            owner = u;
        &#125;
    
        /**
         * 
         * @return User
         */
        public User getOwner&#40;&#41; 
        &#123;        
            return owner;
        &#125;
    
        /**
         * &#40;delete??&#41;
         * @param s
         */
        public void setOwnerId&#40;int id&#41; 
        &#123;
            ownerId = id;
        &#125;
    
        /**
         * &#40;delete??&#41;
         * @return int
         */
        public int getOwnerId&#40;&#41; 
        &#123;        
            return ownerId;
        &#125;
    &#125;
    What is wrong with the above? I have implemented one other form and it works fine.

    Thanks!

  • #2
    Nevermind, it's working now. I think changing the enctype for the form is what did it (I haven't worked with forms enough to even know what that field is for!)

    Comment


    • #3
      I haven't worked with forms enough to even know what that field (enctype) is for!
      You don't need to specify it unless you are doing a file upload.

      Comment


      • #4
        Actually there is a file upload on the page. I haven't tried uploading anything yet though.

        Comment


        • #5
          You will need to tell spring to use the multi-part upload hander.

          I do it by defining a filter in web.xml:
          Code:
            <filter>
              <filter-name>multipartFilter</filter-name>
              <filter-class>org.springframework.web.multipart.support.MultipartFilter</filter-class>
            </filter>
          but there are lots of other ways

          Comment


          • #6
            Thanks! I'm going to need that.

            Comment


            • #7
              There's an example of file uploads in the imagedb sample.

              Comment

              Working...
              X