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

  • Problem by using SimpleFormController

    Here are my codes.

    Controller:
    Code:
    public class RequestFormController extends SimpleFormController{
    
    	public RequestFormController() {
    		setCommandClass(RequestData.class);
    	}
    
    	@Override
    	protected ModelAndView onSubmit(HttpServletRequest request,
    			HttpServletResponse response, Object command, BindException errors)
    			throws Exception {
    		RequestData requestData = (RequestData)command;
    		Map<String, String> responseMap = new HashMap<String, String>(); 
    		responseMap.put("provision", requestData.getRequestStr());
    		ModelAndView mav = new ModelAndView();
    		mav.addObject("response", responseMap);
    		mav.setViewName(getSuccessView());
    		return mav;
    	}
    	
    
    }
    The jsp:
    Code:
    ...
    <form:form action="example.html" method="post">
    <table>
    	<tr>
    		<td><form:input path="requestStr"/></td>
    	</tr>
    	<tr>
    		<td>Output: <c:out value="${response.provision}"></c:out></td>
    	</tr>
    	<tr>
    		<td><input type="submit" value="Excecute" /></td>
    	</tr>
    </table>
    </form:form>
    The bean mapping:
    Code:
    ...
    	<bean id="requestFormController" class="com.mycompany.myapp.example.RequestFormController">
    		<property name="formView">
    			<value>example</value>
    		</property>
    		<property name="successView">
    			<value>example</value>
    		</property>
    	</bean>
    ...
    But after the mav is returned, the page can not be shown. It seems the syntatic of the jsp file is wrong.

  • #2
    From what I can tell you're trying to do, the MAV you're returning does not contain the model with the expected command object.
    Try something like this:

    Code:
    @Override
    protected ModelAndView onSubmit(HttpServletRequest request,
    		HttpServletResponse response, Object command, BindException errors)
    		throws Exception {
    	RequestData requestData = (RequestData)command;
    	Map<String, Serializable> model = errors.getModel();
    	model.put("provision", requestData.getRequestStr());
    	return new ModelAndView(getSuccessView(),model);
    }
    
    ...
    
    <form:form action="example.html" method="post">
    <table>
    	<tr>
    		<td><form:input path="requestStr"/></td>
    	</tr>
    	<tr>
    		<td>Output: <c:out value="${provision}"></c:out></td>
    	</tr>
    	<tr>
    		<td><input type="submit" value="Excecute" /></td>
    	</tr>
    </table>
    </form:form>

    Comment


    • #3
      Bingo!

      Many thanks!

      Comment

      Working...
      X