Announcement Announcement Module
No announcement yet.
Validation Exception and Properties not getting set using <aop:scoped-proxy/> Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Validation Exception and Properties not getting set using <aop:scoped-proxy/>

    Hi All

    I am trying to use session beans (i.e. scope="session") in a web app that uses a SimpleFormController. The Controller which is a singleton has a collaborator i.e. the session bean that I have set up session beans as defined below. Requests to this controller use a "POST" method so they are validated using my custom validator as described below. However, when the validation stage is reached, the execption below is thrown and I am not sure how to go about solving this.

    I can get around the problem by creating a new instance(using the new operator see commented out code below) of the scoped session bean in the formBackingObject method of the controller and then passing that to the validator. However, this is not what I want, I want the scoped session bean(i.e. the form backing object) to be injected into the controller.

    Also, when I set the properties on the scoped session objects, they do not get set.I have stepped through the code using a debugger and what happens is when the the debugger is in the setter method of the property, the property does changes value to whatever you set it to however, when you return from the setter method to the method that called the property's setter method, the property's value returns to the original value as though you havent called the setter method. e.g. Lets say in my scoped session bean (lets call it loginFormObject), I have a property called username which is of type string hence the the setter on the property name is
    public void setUsername(String newUsername){this.username=newUsername;}
    . In my controller if I call
    , the method returns without setting the username property to "myNewName". The username doesnt get changed to "myNewName". However, if I step through the code using the debugger, in the setUsername method, I can see the the value of username property changed to "myNewName" I dont understand how that happens.
    I am using eclipse galileo debugger and i have cglib-nodep-2.1_3.jar on my build path


    java.lang.IllegalArgumentException: Validator [class com.raptorsoftdynamics.iBankUI.validators.LoginFormValidator] does not support [class com.raptorsoftdynamics.iBankUI.formObjects.LoginFormObject$$EnhancerByCGLIB$$6e9ef8d]
    	at org.springframework.validation.ValidationUtils.invokeValidator(
    	at org.springframework.web.servlet.mvc.BaseCommandController.bindAndValidate(
    	at org.springframework.web.servlet.mvc.AbstractFormController.handleRequestInternal(
    	at org.springframework.web.servlet.mvc.AbstractController.handleRequest(
    	at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(
    	at org.springframework.web.servlet.DispatcherServlet.doDispatch(
    	at org.springframework.web.servlet.DispatcherServlet.doService(
    	at org.springframework.web.servlet.FrameworkServlet.processRequest(
    	at org.springframework.web.servlet.FrameworkServlet.doPost(
    	at javax.servlet.http.HttpServlet.service(
    	at javax.servlet.http.HttpServlet.service(
    	at com.evermind.server.http.ResourceFilterChain.doFilter(
    	at com.opensymphony.sitemesh.webapp.SiteMeshFilter.obtainContent(
    	at com.opensymphony.sitemesh.webapp.SiteMeshFilter.doFilter(
    	at com.evermind.server.http.ServletRequestDispatcher.invoke(
    	at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(
    	at com.evermind.server.http.HttpRequestHandler.doProcessRequest(
    	at com.evermind.server.http.HttpRequestHandler.processRequest(
    	at com.evermind.server.http.HttpRequestHandler.serveOneRequest(
    	at com.evermind.util.ReleasableResourcePooledExecutor$

    <bean id="loginFormObject" class ="com.raptorsoftdynamics.iBankUI.formObjects.LoginFormObject" scope="session">
    <bean id = "loginController" class="com.raptorsoftdynamics.iBankUI.controllers.LoginController">
    	<property name="sessionForm" value="true"/> 
    	<property name="formView" value="login"/> 
    	<property name="successView" value="redirect:home.html"/>
    	<property name="commandClass" value="com.raptorsoftdynamics.iBankUI.formObjects.LoginFormObject" />
    	<property name="commandName" value="loginForm"/>
    	<property name="validator">
    <bean class ="com.raptorsoftdynamics.iBankUI.validators.LoginFormValidator"/>
    	<property name="loginFormObject" ref ="loginFormObject"/>  

    protected Object formBackingObject(HttpServletRequest request) throws Exception{
    	// loginFormObject = new LoginFormObject(); If uncommented, code works
    	 HashMap<Object,Object> map = new HashMap<Object,Object>();
    	 Map<String,Integer> securityDigitsToSeclect = new HashMap<String,Integer>();
    	 String suffix = "";
    	 int digitIndexesToMatch = 3;
    	 int []randomSecurityDigits = randomSecurityDigitSelector(digitIndexesToMatch);
    	 for (int i = 0;i<randomSecurityDigits.length;i++){ 
    		 suffix = getSuffix(randomSecurityDigits[i]);
    		 suffix = ((Integer)randomSecurityDigits[i]).toString()+suffix;
    	return loginFormObject;
    protected void onBind(HttpServletRequest request, Object command, BindException errors) {
    		  loginFormObject = (LoginFormObject)command; 
    			String username = loginFormObject.getUsername();
    			String password =  loginFormObject.getPassword();
    			String digits = loginFormObject.getDigits(); 
    			List<SecurityDigit> securityDigits = new ArrayList<SecurityDigit>();
    			securityDigits = loginFormObject.getSecurityDigits();
    			long formLoginTime = loginFormObject.getFormLoginTime();
    			HttpSession session = request.getSession();
    			boolean loggedIn = false; 
    			try {
    				loggedIn= doLogin(username, password, formLoginTime);
    				session.setAttribute("username", username);
    //At this point, this, the call to setUsername returns without 
    //changing the value of "username" (oringinal value being "")to "Annonymous"
    			} catch (ClassCastException e) {
    				// TODO Auto-generated catch block
    			} catch (NamingException e) { 
    				// TODO Auto-generated catch block
    		  session.setAttribute("loggedIn", loggedIn);
    public void setLoginFormObject(LoginFormObject loginFormObject) {

    public boolean supports(Class aClass){
    		return aClass.equals(LoginFormObject.class);
    public void validate(Object obj, Errors err){
    			LoginFormObject lfo = (LoginFormObject)obj;
    			if ("".equals(lfo.getUsername()))
    				err.rejectValue("username", "err.invalid.username", "Username not supplied");
    			if ("".equals(lfo.getPassword()))
    				err.rejectValue("password", "err.invalid.password", "Password not supplied");
    				err.rejectValue("digits", "security.digits.empty");
    				err.rejectValue("digits", "security.digits.length.too_short");
    			if (!((Integer)lfo.getFirstSecurityDigit() instanceof Integer))
    					err.rejectValue("first_security_digit", "err.invalid.first_security_digit", "First security digit not supplied");
    			if (!(((Integer)lfo.getSecondSecurityDigit()) instanceof Integer))
    				err.rejectValue("second_security_digit", "err.invalid.second_security_digit", "Second security digit not supplied");
    			if ((!((String)lfo.getInvalidDetailsSupplied()).equals(""))&&(lfo.getInvalidDetailsSupplied().equalsIgnoreCase("invalid.username.password")))
    			err.rejectValue("invalidDetailsSupplied","invalid.username.password", "Invalid username, password or security digits supplied.\nPlease check these details and try again");
    			if ((!((String)lfo.getInvalidDetailsSupplied()).equals(""))&&(lfo.getInvalidDetailsSupplied().equalsIgnoreCase("user.not.loggedIn")))
    				err.rejectValue("invalidDetailsSupplied","user.not.loggedIn", "You've been brought to this page because you have not logged in or you session has expired.\nPlease login to continue");
    			if (!(((Integer)lfo.getThirdSecurityDigit()) instanceof Integer))
    				err.rejectValue("third_security_digit", "err.invalid.third_security_digit", "Second security digit not supplied");

    private String username; 
    public synchronized String getUsername() {
    		return username;
    public synchronized void setUsername(String username) {
    		this.username = username;
    Last edited by quophyie; Dec 9th, 2009, 08:48 AM.

  • #2
    Hi I have found the answer to part 1 of my question i.e. the Exception. All I had to do was change the supports method to

    	public boolean supports(Class aClass){
    		return LoginFormObject.class.isAssignableFrom( aClass);

    I am not getting the validation errors anymore however, I still dunno why the setter methods dont work. Please help!!