Dinkar Thakur
Dinkar Thakur

Reputation: 3103

Unable to get value in view after form post in Spring mvc

This is my ControllerClass

public class ScheduleClassController extends SimpleFormController {

public ScheduleClassController() {
    setCommandClass(ScheduleClass.class);
    setCommandName("scheduleClass");
}

protected ModelAndView onSubmit(HttpServletRequest request,
        HttpServletResponse response, Object command) throws Exception {

    ScheduleClass wiziqClass = (ScheduleClass) command;
    System.out.println(wiziqClass);
    return new ModelAndView("classdetail", "ScheduleClass", wiziqClass);

}
}

This is my springapp-servelet.xml

http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">

<bean id="viewResolver"
    class="org.springframework.web.servlet.view.UrlBasedViewResolver">
    <property name="viewClass"
        value="org.springframework.web.servlet.view.JstlView" />
    <!-- <property name="prefix" value="/WEB-INF/jsp/" /> -->
    <property name="suffix" value=".jsp" />
    <property name="order" value="10" />
</bean>

<bean name="/index.htm" class="org.sakaiproject.wiziq.tool.HelloWorldController">
    <property name="sakaiProxy" ref="org.sakaiproject.wiziq.logic.SakaiProxy" />
</bean>

<bean name="/schedule.htm" class="org.sakaiproject.wiziq.tool.ScheduleClassController">
    <property name="formView" value="schedule" />
    <property name="successView" value="classdetail" />
</bean>

This is my classdetail.jsp

<jsp:directive.include file="/templates/includes.jsp" />
<jsp:directive.include file="/templates/header.jsp" />

hello there
${wiziqClass.name}

<jsp:directive.include file="/templates/footer.jsp" />

After submitting the form i land on this view but not getting the wiziqClass.name here I have made Model and added getter and setter there.

What i'm doing wrong? Not able to figure out.

Upvotes: 0

Views: 523

Answers (3)

Dinkar Thakur
Dinkar Thakur

Reputation: 3103

Got it working the main problem is that the onSubmit was not working i mistakenly removed BindException errors from
onSubmit(HttpServletRequest request, HttpServletResponse response, Object command,BindException errors) and that was causing the error second error was what M.Dienum told

Thanks to both of you

Upvotes: 0

M. Deinum
M. Deinum

Reputation: 124441

According to your code the name of the attribute is 'ScheduleClass' and not 'wiziqClass'... So change the expression in your jsp

protected ModelAndView onSubmit(HttpServletRequest request,
    HttpServletResponse response, Object command) throws Exception {

  ScheduleClass wiziqClass = (ScheduleClass) command;
  System.out.println(wiziqClass);
  return new ModelAndView("classdetail", "ScheduleClass", wiziqClass);
}

${ScheduleClass.name}

Upvotes: 0

Prabhakaran Ramaswamy
Prabhakaran Ramaswamy

Reputation: 26094

Please change any one of place . Don't change in two places.

 protected ModelAndView onSubmit(HttpServletRequest request,
      HttpServletResponse response, Object command) throws Exception {

      ScheduleClass wiziqClass = (ScheduleClass) command;
      System.out.println(wiziqClass);
      return new ModelAndView("classdetail", "wiziqClass", wiziqClass);
}

or

 ${ScheduleClass.name}

Upvotes: 1

Related Questions