Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need help with a SimpleFormController

 
Hakan Axheim
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm a newbie at Spring framework therefore I need to ask a question in this forum. This is an extract from my servlet.xml file;

<bean name="/createProject.htm" class="businessLayer.controller.CreateProjectController">
<property name="sessionForm" value="true"/>
<property name="formView" value="createProject"/>
<property name="successView" value="readProject"/>
<property name="projectService" ref="projectService"/>
</bean>

I wan't to create an JSP page where I enter some data regarding a project that I wan't to create. This is an extract from my createProject.jsp;

<form:form commandName="project" method="post">
ProjectNr:
<spring:bind path="project.projectNr">
<input type ="text" name="projectNr" value="${status.projectNr}"/>
</spring:bind>
<br>
ProjectName:
<spring:bind path="project.projectName">
<input type = "text" name = "projectName" value="${status.projectName}"/>
</spring:bind>
</br>
<input type="submit" name = "Create Project" value = "Create Project"/>
<input type="reset" name="Rensa" value="Rensa"/>
</form>

My formBackingObject looks like this;

protected Object formBackingObject(HttpServletRequest request)
{

logger.info("Inne i formBackingObject");

try {
project.setProjectNumber(ServletRequestUtils.getRequiredIntParameter(request, "projectNr"));
project.setProjectName(ServletRequestUtils.getRequiredStringParameter(request, "projectName"));
project.setStartDate(ServletRequestUtils.getRequiredStringParameter(request, "startDate"));
project.setEndDate(ServletRequestUtils.getRequiredStringParameter(request, "endDate"));
} catch (ServletRequestBindingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

logger.log(Level.INFO,String.valueOf(project.getProjectNumber()));

projectService.createProject(project);
return projectService;


}

and my onSubmit method looks like this;

public ModelAndView onSubmit(Object command) throws ServletException {

logger.info("Inne i CreateProjectController");

projectService.createProject(project);

project.setProjectNumber(((Project) command).getProjectNumber());

logger.log(Level.INFO,"onSubmit: ProjectNumber ",((Project) command).getProjectNumber());


// projectDao.setProjectNr(projectNumber);

// logger.info("ProjectNr " + projectNumber);

// projectService.createProject(projectDao);

return new ModelAndView(new RedirectView(getSuccessView()));

}

No data will be passed in to the formBackingObject from the JSP page. I don't know why! Is it wrong in my JSP page or is it normal?

Can someone help me with this?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic