• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Regarding onSubmit method

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello!

I am using Spring 2.5.x to develop a small Application.
The application retreives a number of records from a database with Hibernate.
This records are shown in a web page with a link to another web page where it should be able to change a specific record.
When I klick on the link to change a specific record a new page is shown with the specific record.
In this page I change data for a specific field and click on a Submit button.
My controller (SimpleFormController) will be executed and the formbackingobject method will be executed.
After that onSubmit method will be executed but it the new entered data will not be sent to onSubmit method.
Instead the old data will be send to this method.

Why?

Best regards

/Håkan


 
Hakan Axheim
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
UpdateController.java:

package BL.controller;

import javax.servlet.http.*;
import javax.servlet.ServletException;


import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;
import org.springframework.web.bind.RequestUtils;
import org.springframework.validation.BindException;

import BL.Project;
import BL.service.ProjectServiceImpl;
import IL.util.DAOException;

public class UpdateProjectController extends SimpleFormController {

// private static final Logger logger = Logger.getLogger(UpdateProjectController.class.getName());
ProjectServiceImpl projectServiceImpl = new ProjectServiceImpl();

public UpdateProjectController() {
logger.info("Current: Inne i UpdateProjectController --> Constructor");
setCommandClass(Project.class);
setCommandName("ProjectForm");
setSessionForm(true);
//setSuccessView("studentSuccess");
logger.info("Current: Constructor slutförd");
}

@Override
protected Object formBackingObject(HttpServletRequest request) throws ServletException {
logger.info("Current: Inne i UpdateProjectController --> formBackingObject ");

logger.info("Current: Project ID " + String.valueOf(RequestUtils.getIntParameter(request,"projectId")));

Project project = new Project();
project = projectServiceImpl.getAllProjects(RequestUtils.getIntParameter(request,"projectId"));

logger.info("Current: Projektnamn " + project.getProjectName());

return projectServiceImpl.getAllProjects(RequestUtils.getIntParameter(request,"projectId"));

}

@Override
public ModelAndView onSubmit(Object command) throws ServletException
{
logger.info("Current: Bekräfta");

Project projectCommand = (Project) command;

logger.info("Current: " + projectCommand.getProjectId());
logger.info("Current: " + projectCommand.getProjectNumber());
logger.info("Current: " + projectCommand.getProjectName());
logger.info("Current: " + projectCommand.getStartDate());
logger.info("Current: " + projectCommand.getEndDate());

try {
projectServiceImpl.updateProject(projectCommand);
} catch (DAOException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
return new ModelAndView("readProject","project",projectCommand);

/*
logger.info("Current: Projektnamn " + project.getProjectName());

Project commandName = (Project) command;
project.setProjectName(commandName.getProjectName());
project.setStartDate(commandName.getStartDate());
project.setEndDate(commandName.getEndDate());

logger.info("Current: ProjectId " + String.valueOf(project.getProjectId()));
logger.info("Current: ProjectNr " + project.getProjectNumber());
logger.info("Current: ProjectNamn " + project.getProjectName());
logger.info("Current: StartDate " + project.getStartDate());
logger.info("Current: EndDate " + project.getEndDate());


try {
projectServiceImpl.updateProject(project);
} catch (DAOException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}




return new ModelAndView("readProject","project",project);
*/
}

}
 
Hakan Axheim
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JSP file for updating a record:
 
Ranch Hand
Posts: 206
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Simply you didn't do it correctly on the next step, there are a lot of work that you need to do here.

1. Put "projectId" in the session.
2. Passing "projectId" in the jsp page that you have the data to edit.
3. Create a new controller to handle the edit process
4. Whatever the next step you like to do from here...

Hope it help....
 
Hakan Axheim
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well the source code I give to you is the Controller that should handle the update.
The JSP page I have posted is the update page - this JSP page should handle the update.
I'm a newbie at Spring therefore my questions.

When I cklick on the Submit button on the web page (see JSP page in this thread) the onSubmit method will be called but the new entered value will not be sent to that method!
I don't know what you mean by putting projectID in the session.

When the JSP page listed in this thread (updateProject.jsp) will be called it receives a projectID and the formBackingObject method will be called.

/Håkan
 
Tommy Delson
Ranch Hand
Posts: 206
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I see your update controller code, it's not done correctly. You need a good reference or tutorial to walk you through here...

Check this out: http://static.springsource.org/docs/Spring-MVC-step-by-step/index.html

Basically you need to do several things in order to get an updated data on the next page.

1. Passing "projectId" in param or any way you know how to the request in your first page.

(This is where you've missed)
2. Put "projectId" in the session in the controller where it handle the submit form and set all updated value on the object you want to update

3. Retrieve "projectId" in your update controller and retrieve all the value from an object where you have saved set earlier, and set to the instance variables.

4. On your JSP update page retrieve all updated value that you set in an instance variables.

5. On submit you're done.
 
Tommy Delson
Ranch Hand
Posts: 206
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I see your update controller code, it's not done correctly. You need a good reference or tutorial to walk you through here...

Check this out: http://static.springsource.org/docs/Spring-MVC-step-by-step/index.html

Basically you need to do several things in order to get an updated data on the next page.

1. Passing "projectId" in param or any way you know how to the request in your first page.

(This is where you've missed)
2. Put "projectId" in the session in the controller where it handle the submit form and set all updated value on the object you want to update

3. Retrieve "projectId" in your update controller and retrieve all the value from an object where you have saved set earlier, and set to the instance variables. Next pass it or set to an object you want to update.

4. On your JSP update page retrieve all updated value from an object that you set in an instance variables.

5. On submit you're done.


Hope it help...
 
Hakan Axheim
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have solved this problem. I had different versions of spring.jar and spring-web.jar.
Everything works as expected!

/Håkan
 
There is no "i" in denial. Tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic