[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1829
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

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