Results 1 to 5 of 5

Thread: Problem with <spring:bind> Error on "getActualFieldValue"

  1. #1
    Join Date
    Jul 2008
    Posts
    3

    Default Problem with <spring:bind> Error on "getActualFieldValue"

    Hi,
    I m trying to create my own web application using Spring MVC. All goes well until i use <spring:bind> to validate a form. I have followed a tutorial, and i think i did the equivalent of the content of the tutorial, but...
    I have an error:
    javax.servlet.ServletException: tried to access method org.springframework.validation.AbstractPropertyBin dingResult.getActualFieldValue
    This is a part of createApplication-servlet.xml:
    Code:
    <beans>
    	<!-- les mappings de l'application-->
    	<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
    		<property name="mappings">
    			<props>
    				<prop key="/createApplication.html">CreateApplicationController</prop>
    			</props>
    		</property>
    	</bean>
    	<!-- les contrôleurs de l'application-->
    	<bean id="CreateApplicationController"
    		class="controller.CreateApplicationController" autowire="byName">
    		<property name="sessionForm">
    			<value>true</value>
    		</property>
    		<property name="commandName">
    			<value>createApplicationForm</value>
    		</property>
    		<property name="formView">
    			<value>createApplication</value>
    		</property>
    		<property name="successView">
    			<value>confirmCreateApplication</value>
    		</property>
    		<property name="validator">
    			<ref bean="createApplicationFormValidator"/>
    		</property>
    	</bean>
    	<!-- le validateur de formulaire -->
    	<bean id="createApplicationFormValidator" 
    		class="controller.validator.ValidateCreateApplicationForm"/>
    A part of my Controller:
    Code:
    public class CreateApplicationController extends SimpleFormController {
    
    	private ApplicationManager applicationManager;
    
    	public ApplicationManager getApplicationManager() {
    		return applicationManager;
    	}
    
    	public void setApplicationManager(ApplicationManager applicationManager) {
    		this.applicationManager = applicationManager;
    	}
    
    	private ModelAndView create(HttpServletRequest request,
    			HttpServletResponse response) {
    		CreateApplicationForm createApplicationForm = (CreateApplicationForm) request.getSession().getAttribute(
    		"createApplicationForm");
    		Application app = new Application();
    		app.setComment(createApplicationForm.getComment());
    		app.setName(createApplicationForm.getName());
    		app.setTrigram(createApplicationForm.getTrigram());
    		applicationManager.add(app);
    		// on rend un [ModelAndView]
    		return new ModelAndView("confirmCreateApplication", null);
    	}
    
    	protected Object formBackingObject(HttpServletRequest request) {
    		// on récupère le formulaire dans la session s'il existe
    		CreateApplicationForm createApplicationForm = (CreateApplicationForm) request.getSession().getAttribute(
    				"createApplicationForm");
    		if (createApplicationForm == null) {	
    			createApplicationForm = new CreateApplicationForm();
    		}
    		// on rend le formulaire
    		return createApplicationForm;
    	}
    
    	// traitement du POST
    	protected ModelAndView onSubmit(HttpServletRequest request,
    			HttpServletResponse response, Object createApplicationForm,
    			BindException errors) {
    		// on met le formulaire dans la session
    		request.getSession().setAttribute("createApplicationForm",
    				createApplicationForm);
    		// on rend un [ModelAndView]
    		return create(request, response);
    	}
    
    }
    My form object:
    Code:
    public class CreateApplicationForm {
    	
    	/**
    	 * Le nom de l'application
    	 */
    	private String name;
    	
    	public String getName() {
    		return name;
    	}
    	
    	public void setName(String name) {
    		this.name = name;
    	}
    and hte jsp i cannot display:
    Code:
    <body>
    createApplication
    	<form method="post">
    		<table>
    			<tr>
    				<spring:bind path="createApplicationForm.name">
    					<td><input type="text" name="${status.expression}" value="${status.value}" /></td>
    					<td>${status.errorMessage}</td>
    				</spring:bind>
    			</tr>
    		</table>
    	</form>
    </body>
    It looks that the bolded part is a problem: when i try to display my form, instead of display the empty input field, i have:
    Code:
    org.apache.jasper.JasperException: Exception in JSP: /views/createApplication.jsp:17
    
    14: 	<form method="post">
    15: 		<table>
    16: 			<tr>
    17: 				<spring:bind path="createApplicationForm.name">
    18: 					
    19: 					<td><input type="text" name="${status.expression}" value="${status.value}" /></td>
    20: 					<td>${status.errorMessage}</td>
    
    
    Stacktrace:
    	org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:451)
    	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:355)
    	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
    	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    	org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:171)
    	org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:251)
    	org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1160)
    	org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:901)
    	org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:809)
    	org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:476)
    	org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:431)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    
    root cause
    
    javax.servlet.ServletException: tried to access method org.springframework.validation.AbstractPropertyBindingResult.getActualFieldValue(Ljava/lang/String;)Ljava/lang/Object; from class org.springframework.web.servlet.support.BindStatus
    	org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:841)
    	org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:774)
    	org.apache.jsp.views.createApplication_jsp._jspService(createApplication_jsp.java:135)
    	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
    	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
    	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    	org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:171)
    	org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:251)
    	org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1160)
    	org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:901)
    	org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:809)
    	org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:476)
    	org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:431)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    The only difference with the tuto i followed is that an instance of the form object is created in its business interface (= applicationManager for me) to init the attributes. I tried it too but it didnt change anything. So i desperatly ask for your help

    Thanks in advance

  2. #2
    Join Date
    Oct 2006
    Posts
    100

    Default

    I think the problem is with your controller config where you have not set the commandClass property on the Controller
    Code:
    <bean id="CreateApplicationController"
    		class="controller.CreateApplicationController" autowire="byName">
    		<property name="sessionForm">
    			<value>true</value>
    		</property>
    		<property name="commandName">
    			<value>createApplicationForm</value>
    		</property>
                    <!-- Set the exact path to the CreateApplicationForm -->
    		<property name="commandClass">
    			<value>model.CreateApplicationForm </value>
    		</property>
    		<property name="formView">
    			<value>createApplication</value>
    		</property>
    		<property name="successView">
    			<value>confirmCreateApplication</value>
    		</property>
    		<property name="validator">
    			<ref bean="createApplicationFormValidator"/>
    		</property>
    	</bean>

  3. #3
    Join Date
    Jul 2008
    Posts
    3

    Default

    Thank you for your answer, but i have already tried to use the commandClass property with explicit classpath, and the same error is present.
    I dont know why the "path" attribute is wrong... when i use
    Code:
    <spring:bind path="createApplicationForm.*">
    my jsp is displayed well, but of course i cannot do the things i want with the input text (its "name" attribute becomes "*")

    Why the method getActualFieldValue is throwing that kind of error ? I m really confused...


    I give you my log on console, if it can help you to help me ^^
    2008-07-04 10:03:29,915 [http-8080-Processor24] DEBUG - Displaying new form
    2008-07-04 10:03:29,978 [http-8080-Processor24] DEBUG - Setting form session attribute [com.sgcib.ouvea.controller.CreateApplicationContro ller.FORM.createApplicationForm] to: name null
    2008-07-04 10:03:30,025 [http-8080-Processor24] WARN - Use of 'class' property in [org.springframework.beans.factory.support.Properti esBeanDefinitionReader] is deprecated in favor of '(class)'
    2008-07-04 10:03:30,025 [http-8080-Processor24] WARN - Use of 'class' property in [org.springframework.beans.factory.support.Properti esBeanDefinitionReader] is deprecated in favor of '(class)'
    2008-07-04 10:03:30,025 [http-8080-Processor24] WARN - Use of 'class' property in [org.springframework.beans.factory.support.Properti esBeanDefinitionReader] is deprecated in favor of '(class)'
    2008-07-04 10:03:30,025 [http-8080-Processor24] WARN - Use of 'class' property in [org.springframework.beans.factory.support.Properti esBeanDefinitionReader] is deprecated in favor of '(class)'
    2008-07-04 10:03:30,025 [http-8080-Processor24] WARN - Use of 'class' property in [org.springframework.beans.factory.support.Properti esBeanDefinitionReader] is deprecated in favor of '(class)'
    I used the debug to see the way of execution: formBackingObject, initBinder, showForm,referenceData are executed, the exception is thrown after all this, i dont know exactly when... Could it be a probleme in my config files ?
    Last edited by Widiwi; Jul 4th, 2008 at 03:16 AM.

  4. #4

    Default

    I faced the same issue when I used 2.5.5 but, it got resolved when I started using the 2.0.7 version. Still trying to figure out the actual issue, but you can try 2.0.7 and see

  5. #5
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    I would say it is an classloading issue. Check your classpath make sure that there is only 1 spring.jar or specific spring-[module].jar in your classpath. Server, shared and application. Also make sure that all the spring-[module].jar come from the same version of spring. Next to that you are using spring 2.5 why use spring:bind why not use the simpler form tags? saves you a lot of typing especially with a lot of spring:bind tags.

    Code:
    <body>
    createApplication
    	<form:form method="post" commandName="createApplicationForm">
    		<table>
    			<tr>
    				<td><form:input path="name"/></td>
    				<td><form:errors path="name"/></td>
    			</tr>
    		</table>
    	</form>
    </body>
    Just on another note, I think your controller can use some improvement to, why pass around an object in the session, first putting it there, leaving it in (unnecessary session clutering). For some reason it heavily looks like you are battling against the framework.
    Last edited by Marten Deinum; Aug 25th, 2008 at 05:44 AM.
    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
  •