Announcement Announcement Module
Collapse
No announcement yet.
using webmvc form and controller on same page Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • using webmvc form and controller on same page

    I have a jsp page with a form and a list of objects that the form submits. I need my controller to be both the Controller and and FormController but when I extend SimpleFormController I cannot override the handleRequest method.

    my controller with the error because I cannot override the handle request method
    Code:
    public class AppSubmitController extends SimpleFormController implements InitializingBean {
    
    private AppDAO appDAO;
    
    public void afterPropertiesSet() throws Exception {
        Assert.notNull(appDAO,
            "An AppDAO implementation is required");
    }
    
    /* (non-Javadoc)
     * @see org.springframework.web.servlet.mvc.Controller#handleRequest(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
     */
    public ModelAndView handleRequest(HttpServletRequest arg0, HttpServletResponse arg1) throws Exception {
      ArrayList apps = appDAO.findAll();
      return new ModelAndView("app", "apps", apps);
    }
    
    protected ModelAndView disallowDuplicateFormSubmission(
        HttpServletRequest request, HttpServletResponse response)
        throws Exception {
        BindException errors = new BindException(formBackingObject(request), getCommandName());
        errors.reject("err.duplicateFormSubmission",
            "Duplicate form submission.");
    
        return showForm(request, response, errors);
    }
    
      public ModelAndView onSubmit(Object command) throws ServletException{
        App app = (App)command;
        appDAO.save(app);
        appDAO.addPermission(null, new SimpleAclEntry(), 1, "ROLE_ADMIN");
        
        return new ModelAndView(new RedirectView(getSuccessView()),"app", app);
      }
      /* (non-Javadoc)
       * @see org.springframework.web.servlet.mvc.AbstractFormController#formBackingObject(javax.servlet.http.HttpServletRequest)
       */
      protected Object formBackingObject(HttpServletRequest req) throws Exception {
        App app = new App();
        if(Parameter.getInt(req.getParameter("id")) != 0){
          app = appDAO.find(Parameter.getLong(req.getParameter("id")));
        }
        return app;
      }
    /**
     * @return
     */
    public AppDAO getAppDAO() {
      return appDAO;
    }
    
    /**
     * @param newAppDAO
     */
    public void setAppDAO(AppDAO newAppDAO) {
      appDAO = newAppDAO;
    }
    
    }
    my jsp
    Code:
    <body>
    <jsp:include page="toolbar.jsp" flush="false"></jsp:include>
    <form>
    <Spring:hasBindErrors name="app">
    Could not add application. Please fix all errors!
    </Spring:hasBindErrors>
    <Spring:bind path="app.appName">
    App Name: <input type="text" name="appName" size="35"  value="<c:out value="${status.value}" />"/><font color="red"><c:out value="${status.errorMessage}" /></font><br />
    </Spring:bind>
    <Spring:bind path="app.description">
    App Description: <textarea rows="3" cols="35" name="appDescription"><c:out value="${status.value}" /></textarea><br />
    <font color="red"><c:out value="${status.errorMessage}" /></font>
    </Spring:bind>
    <br />
    <input
    	type="submit" name="addApp" value="Add App" />
    </form>
    <h2>Applications</h2>
    <c:forEach items="${apps}" var="apps">
    <form id="mainItem">
    <c:out value="${app.appname}"/>
    	<input type="submit" name="newDeploy" value="New Deploy" />
    	<input type="submit" name="ViewEditRoles" value="View/Edit Roles" />
    	</form>
    <c:out value="${app.description}" />
    <hr />
    </c:forEach>
    
    </body>
    my context xml
    Code:
    		<bean id="appManagement" class="edu.bju.aem.controller.AppSubmitController">
    			<property name="appDAO">
    	<ref bean="appDAOHibernateManaged"/>
    	</property>
    		<property name="sessionForm">
    			<value>true</value>
    		</property>
    		<property name="commandName">
    			<value>app</value>
    		</property>
    		<property name="commandClass">
    			<value>edu.bju.shared.model.security.App</value>
    		</property>
    		<property name="validator">
    			<ref bean="appValidator" />
    		</property>
    		<property name="formView">
    			<value>app</value>
    		</property>
    		<property name="successView">
    			<value>appManagement.html</value>
    		</property>
    	</bean>
Working...
X