Announcement Announcement Module
Collapse
No announcement yet.
Spring MVC + Annotations Pre-Filling Form From DB Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring MVC + Annotations Pre-Filling Form From DB

    Hi,

    In my application I present the user with a form to fill. If the user comes back later I want to be able to show him/her the values entered before, which I stored in the database. I thought I could just set the filled object into the ModelAndView with the right name and that would do the trick but it is not working. I have read some stuff about setting the this:

    Code:
                    setBindOnNewForm(true);
    		setCommandClass(EducationalBackground.class);
    		setCommandName("questionnaire");
    and then override formBackingObject() but since I am using the Controller annotation I don't have visibility of such inherited methods. I tried using both the annotation and extending SimpleFormController but it is not working.
    This is part of my form

    Code:
    <form:form name="formQuestionnaire" id="formQuestionnaire"
    			method="post"
    			action="${pageContext.request.contextPath}/questionnaire/submitEducationalBackground.spr"
    			commandName="questionnaire">
    and my Controller

    Code:
    @Controller
    @Scope("session")
    public class QuestionnaireController extends SimpleFormController{
    		@RequestMapping(value = "/questionnaire/showQuestionnaireForm.spr", method = RequestMethod.GET)
    	public ModelAndView showQuestionnaire(
    			HttpServletRequest request,
    			@RequestParam(value = WebConstants.STUDENT_SERVICE_PROFILE_ID, required = false) final String srvcPrflId,
    			@RequestParam(value = "studentId", required = false) final String studentId) {
    			
    		ModelAndView mav = new ModelAndView("QuestionnaireIncomplete");
    		
    		EducationalBackground educationalBackground =  getEducationalBackground(Long.valueOf(srvcPrflId));
    	      
    	      if(educationalBackground!=null){
    	    	  mav.addObject("questionnaire", educationalBackground);
    	      }
    
    		mav.addObject("isACT", isACT(srvcPrflId));
    		mav.addObject("subjects", PreCollegeSubjects.values());
    		mav.addObject("availableGrades", PreCollegeAcademicYear.values());
    		mav.addObject("questionnaire", new EducationalBackgroundForm());
    		mav.addObject("SATsubjects", SATSubjects.values());
    		mav.addObject("programs", AdvancedPlacementProgram.values());
    		mav.addObject(WebConstants.STUDENT_SERVICE_PROFILE_ID, srvcPrflId);
    		return mav;
    	}
    }
    EducationalBackground is my command.
    Last edited by jr_arzuaga; Apr 1st, 2010, 01:43 PM.

  • #2
    setBindOnNewForm(k_of_j);

    setBindOnNewForm(true);
    setCommandClass(EducationalBackground.class);
    setCommandName("questionnaire");

    Comment


    • #3
      I am sorry, my code was not accurate, my controller is not extending anything since it is annotated so I dont have access to those methods. Anyways I already solved my problem, I was overwriting my command with a new object so I was loosing my data. Thanks though!



      Regards,

      jra
      Last edited by jr_arzuaga; May 11th, 2010, 03:31 PM.

      Comment


      • #4
        Angel nos van a botar del community por estar jodiendo aqui!!!!!

        Comment

        Working...
        X