Results 1 to 4 of 4

Thread: error using spring:bind

  1. #1
    Join Date
    Feb 2007
    Posts
    8

    Default error using spring:bind

    Hi, this is my first post, and I'm sorry if this is a noob question. My problem is trying to bind a bean in a jsp page. These are the details:

    1º The user has a login page (let's call it adminLogin.jsp). When he logs in, then I do
    Code:
      return new ModelAndView((getSuccessView()));
    The success view of that form is admin, which in turn is resolved to admin.jsp (this works)

    2º In admin.jsp I have:


    Code:
    <spring:bind path="adminHomeFormBean.selected">  	
      <select name="usersCombo">
        <c:forEach var="person" items="${adminHomeFormBean.people}">
          <option value="<c:out value="${person.key}"/>" 
             <c:if test="${person.key == status.value}"> selected="selected"</c:if> 
          >
            <c:out value="${person.key}"/>
          </option>
        </c:forEach>
      </select>
    </spring:bind>
    The trouble is:
    * It works if I type directly on the address bar the URL (http://localhost:8080/AppName/admin.htm)
    * When reaching that page from the controller of the login controller it doesn't work. I've found that the controller of this admin page is never used to make the command object in this second scene.


    Config and others:

    Code:
       
    <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
            <property name="mappings">
                <props>
                	
                    <prop key="/adminLogin.htm">webAdminLoginFormControl</prop>
                    <prop key="/addUser.htm">webAddUserFormControl</prop>
                    <prop key="/admin.htm">webAdminHomeFormControl</prop>
                </props>
            </property>
        </bean>


    Code:
         <bean id="webAdminLoginFormControl" class="web.control.AdminLoginFormControl">
            <property name="sessionForm"><value>true</value></property>
            <property name="commandName"><value>adminLoginFormBean</value></property>
            <property name="commandClass"><value>forms.AdminLoginFormBean</value></property>
            <property name="validator"><ref bean="adminLoginValidator"/></property>
            <property name="formView"><value>adminLogin</value></property>
            <property name="successView"><value>admin</value></property>
            <property name="adminLoginFormControl"><ref bean="adminLoginFormControl" /></property>
        </bean>
        
    
    
    
        <bean id="webAdminHomeFormControl" class="web.control.AdminHomeFormControl">
        	<property name="methodNameResolver"><ref bean="actionResolver"/></property> 
            <property name="sessionForm"><value>true</value></property> 
            <property name="commandName"><value>adminHomeFormBean</value></property> 
            <property name="commandClass"><value>forms.AdminHomeFormBean</value></property> 
            <property name="validator"><ref bean="adminHomeValidator"/></property> 
            <property name="formView"><value>admin</value></property> 
            <property name="successView"><value>adminSuccess</value></property> 
            <property name="personDAO"><ref bean="personDAO"/></property>
            <property name="bindOnNewForm"><value>true</value></property>
        </bean>

    The controller class extends the AbstractMultiActionFormController from

    http://forum.springframework.org/sho...FormController

    (implemented in the post with subject java 1.4 compatibility)

    I don't know how to make spring use the formBackingObject I've implemented in the controller when reaching the page through the login controller


    Regards

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,629

    Default

    If you call the jsp the way you configured it is never going to be called thru the controller.

    Code:
    return new ModelAndView((getSuccessView()));
    The above code will just render the page. What you actually want to do, to pass it through the controller reconfigure your succesView in your configuration

    Code:
    <bean id="webAdminLoginFormControl" class="web.control.AdminLoginFormControl">
      <property name="sessionForm"><value>true</value></property>
      <property name="commandName"><value>adminLoginFormBean</value></property>
      <property name="commandClass"><value>forms.AdminLoginFormBean</value></property>
      <property name="validator"><ref bean="adminLoginValidator"/></property>
      <property name="formView"><value>adminLogin</value></property>
      <property name="successView" value="redirect:admin.htm"/>
      <property name="adminLoginFormControl"><ref bean="adminLoginFormControl" /></property>
    </bean>
    This will redirect your browser to http://localhost:8080/AppName/admin.htm and thus it will pass the controller. Notice the redirect: keyword. You can find more about this in the reference guide.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Feb 2007
    Posts
    8

    Default

    Thank you!!! I had been studying this and I found that I could do

    return new ModelAndView(new RedirectView(getSuccessView()));


    but I like more the idea of the redirect: tag in the xml file. My problem is that i've been studying almost everything by examples, and I'm not comfortable with the reference yet.

  4. #4
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,629

    Default

    When I first started Spring I used both. Looked at the examples and look at the reference guide (and the javadocs are great to) with the things I couldn't figure out directly. That was in the 1.x versions, since 2.0 the reference guide has greatly improved.

    Or as someone here on the forum mentioned 'the reference guide is your friend'.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •