• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1836
  • Last Modified:

when is container going to call formBackingObject in controller?

 i mapped MyObjectForm.html to AddEmployeeFormController;

 when i access the application with this url http://localhost/springapp/MyObjectForm.html i assume that it will call formBackingObject in AddEmployeeFormController but it's not happened like that;nothing is called in that controller;when is container going to call formBackingObject in controller?


configuration file
******************

  <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
        <property name="mappings">
            <props>
                    <prop key="/test.html">viewController</prop>
                <prop key="/MyObjectForm.html">empForm</prop>
            </props>
        </property>
    </bean>

     <bean id="empForm" class="web.AddEmployeeFormController">
        <property name="sessionForm"><value>true</value></property>
        <property name="commandName"><value>myobject</value></property>
        <property name="commandClass"><value>bus.Employee</value></property>
   <!--   when i call first time emp.htm it will call formBackingObject intrun formView should match  /emp.htm-->
        <property name="formView"><value>MyObjectForm</value></property>
        <property name="successView"><value>test.html</value></property>
        <property name="empObjectDaoImpl"><ref bean="empObjectDaoImpl"/></property>

   </bean>

 
   
   
   controller
******************
   
   protected Object formBackingObject(HttpServletRequest request) throws
            ServletException {


                    System.out.println("Entering formBackingObject AddEmployeeFormController  ....");

        String id = request.getParameter("id");
        if (null != id && !id.equals("")) {
            Employee emp = (Employee) empObjectDaoImpl.findMyObjectById(Integer.parseInt(id));
            System.out.println("formBackingObject  AddEmployeeFormController IF id is not null====="+emp);

                  return emp;
        }
        return new Employee();
    }

    jsp
    ***

    <tr>
  <td colspan="5"><a href="MyObjectForm.html">Click here to add new Object</a></td>
</tr>
0
chaitu chaitu
Asked:
chaitu chaitu
  • 6
  • 5
1 Solution
 
objectsCommented:
what are your mappings?
0
 
objectsCommented:
>  <!--   when i call first time emp.htm it will call formBackingObject intrun formView should match  /emp.htm-->
 
does this mean that you have emp.htm mapped to your form controller?
If so thats the url you should have in your link

  <td colspan="5"><a href="emp.htm">Click here to add new Object</a></td>
0
 
chaitu chaituAuthor Commented:
sorry i have not seen properly  its calling formBackingObject when i type http://localhost:9090/springapp/MyObjectForm.html;

my question is when is container going to call formBackingObject in controller?
at what situations will it call
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
chaitu chaituAuthor Commented:
<td colspan="5"><a href="MyObjectForm.htm">Click here to add new Object</a></td>

it is mapped to AddEmployeeFormController  ;;
0
 
objectsCommented:
it will get called for a new form
0
 
chaitu chaituAuthor Commented:
i think except for submit buttons it will call all times ;;
0
 
objectsCommented:
> i think except for submit buttons it will call all times ;;

depends if its a GET or a POST
0
 
objectsCommented:
A GET is a request for a new form
A POST would check the session for existing form
0
 
chaitu chaituAuthor Commented:
if it is POST it will not call formBackingObject ;
what is the meaning of this         <property name="sessionForm"><value>true</value></property>

 <bean id="empForm" class="web.AddEmployeeFormController">
        <property name="sessionForm"><value>true</value></property>
        <property name="commandName"><value>myobject</value></property>
        <property name="commandClass"><value>bus.Employee</value></property>
          <property name="formView"><value>MyObjectForm</value></property>
        <property name="successView"><value>test.html</value></property>
   
   </bean>
0
 
objectsCommented:
Indicates whether the form object should be kept in the session when a user asks for a new form.
0
 
chaitu chaituAuthor Commented:
i think only few experts good in spring;
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now