Announcement Announcement Module
Collapse
No announcement yet.
Spring 2.x to Spring 3.x upgrade Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring 2.x to Spring 3.x upgrade

    Hi All,

    We are upgrading Spring 2.x base web application to 3.x. After upgrade I am getting following exception in Login page it self.

    We have our own taglib which works fine in Spring 2.x where as it throwing exception with Spring 3.x

    Using org.springframework.web.servlet.mvc.UrlFilenameVie wController as the Conroller

    Code:
    org.apache.jasper.JasperException: An exception occurred processing JSP page /WEB-INF/jsp/login.jsp at line 49
    
    46:     </form>
    47:     <br/>
    48:     <br/>
    49:     <security:a href="${app}/user/forgotUserId">Forgot Username</security:a>
    50:     <br/>
    51:     <security:a href="${app}/user/resetPassword">Reset Password</security:a>
    52: </div>
    
    java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name '' available as request attribute
    	org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:141)
    	org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getBindStatus(AbstractDataBoundFormElementTag.java:174)
    Any help would be great.

    here is my login.jsp

    Code:
    <%@ page import="org.acegisecurity.AuthenticationServiceException" %>
    <%@ include file="include.jsp" %>
    <html>
    <head>
        <title>Login</title>
    </head>
    
    <!--<body onload="$('user_name').focus();">-->
    <%-- $('x') does not work in Firefox ... --%>
    <body onload="document.getElementById('user_name').focus();">
    
    <div class="smallCenteredBox">
    
        <c:if test="${not empty sessionScope.ACEGI_SECURITY_LAST_EXCEPTION and not empty param.login_error}">
            <div class="error">
                <!--Your login attempt was not successful, please try again.<BR/>-->
                ${sessionScope.ACEGI_SECURITY_LAST_EXCEPTION.message}
            </div>
        </c:if>
    
        <form name="loginForm" action="${ctx}/app/j_security_check" method="POST">
            <table>
                <tr>
                    <th><label for="user_name">Username:</label></th>
                    <td>
                        <input id="user_name" type='text' name='j_username'
                               value="${sessionScope.ACEGI_SECURITY_LAST_USERNAME}"/>
                    </td>
                </tr>
                <tr>
                    <th><label for="password">Password:</label></th>
                    <td>
                        <input id="password" type="password" name="j_password"/>
                    </td>
                </tr>
    
                <tr>
                    <td></td>
                    <td>
                        <input type="submit" class="button" name="submit" value="Submit"/>
                        <input type="reset" class="button" name="reset" value="Reset"/>
                    </td>
                </tr>
            </table>
    
        </form>
        <br/>
        <br/>
        <security:a href="${app}/user/forgotUserId">Forgot Username</security:a>
        <br/>
        <security:a href="${app}/user/resetPassword">Reset Password</security:a>
    </div>
    
    </body>
    </html>
    Last edited by ndhilliprasad; Aug 9th, 2012, 08:26 AM.

  • #2
    I have found the solution.

    The problem here is i don't have model object configured for the form as i am using the normal html form tag instead of <form:form> tag.

    When it tries to render the the custom tag lib it is trying to auto generate the id and name values in AbstractDataBoundFormElementTag.java.

    In spring 3.x This class uses BindStatus to find the model in the request. In my case model is empty. which is resulting in an Exception

    snapshot of code where the exception is thrown in the BindStatus
    Code:
    139		Object target = requestContext.getModelObject(beanName);
    140		if (target == null) {
    141	                  throw new IllegalStateException("Neither BindingResult nor plain target object for bean name '" +
    142						beanName + "' available as request attribute");
    143	}

    To tweak this I have provide my own implementation for org.springframework.web.servlet.mvc.UrlFilenameVie wController as following

    Code:
    package com.orbitz.bop.web.controllers;
    
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    import org.springframework.web.servlet.ModelAndView;
    import org.springframework.web.servlet.mvc.UrlFilenameViewController;
    
    public class UrlFilenameViewModelController extends UrlFilenameViewController{
    
        @Override
        protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) {
            ModelAndView modelView = super.handleRequestInternal(request, response);
            
            modelView.addObject("","test");
            
            return modelView;
        }
    }
    here i am setting a dummy model object value against the empty model name.

    This problem is not there in the spring 2.x

    Comment

    Working...
    X