Announcement Announcement Module

Spring Modules forum decommissioned in favor of Spring Extensions

As the Spring Modules project has been replaced by the Spring Extensions ( project, this forum has been decommissioned in favour of Spring Extensions one at:

Please see the Spring Extensions home page for a complete list of current projects in Java, .NET and ActionScript. You can also propose one if you want.

Costin Leau
SpringSource - Spring Training, Consulting, and Support - "From the Source"
See more
See less
Ajax Validation / ajax:redirect and Spring ViewResolver Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Ajax Validation / ajax:redirect and Spring ViewResolver

    I've read a lot of post about ajax validation on Spring Modules forum and I havn't yet understood how to make it working in my situation.

    I'm using 2 forms on a page, submited through AjaxSubmitAction. Those forms are spring <form:form ...>.

    He is how it's working:

    This controller extends SimpleFormControler. The formBean is validated.
    <bean name="lithoFormValidator" class="org.mycompany.web.validation.LithoFormValidator"></bean>
    <bean name="/litho/litho.htm" class="org.mycompany.web.controlers.LithoFormController" autowire="byName">
    	<property name="sessionForm" value="true" />
    	<property name="commandName" value="LithoForm" />
    	<property name="commandClass" value="org.mycompany.web.form.LithoForm" />
    	<property name="formView" value="litho/litho" />
    	<property name="successView" value="datation.htm" />
    	<property name="validator"  ref="lithoFormValidator" />
    The AjaxHandler and ValidationHandler mapping:
    <bean id="ajaxInterceptor" class="org.springmodules.xt.ajax.AjaxInterceptor">
    	<property name="handlerMappings">
    			<prop key="/*.htm">ajaxHandler,ajaxValidationHandler</prop>
    <bean id="ajaxHandler" class="org.mmycompany.web.ajax.AjaxHandler" />
    <bean id="ajaxValidationHandler" class="org.springmodules.xt.ajax.validation.DefaultValidationHandler"/>
    My AjaxHandler called method:
    public AjaxResponse submitTrancheEau(AjaxSubmitEvent ajxSubmEvt){
    	logger.debug("## SUBMIT TRANCHE EAU##");
    	AjaxResponse response = new AjaxResponseImpl();
    		ReplaceContentAction setTrancheEauValue = new ReplaceContentAction( "trancheeauStatic", new SimpleText(Double.toString(((LithoForm)ajxSubmEvt.getCommandObject()).getWaterdepth())));
        return response;
    When the form validation fails, I just want the page to be displayed, including the error messages on the form:errors tags.

    <form:form id="waterdepthform" commandName="LithoForm"> 
    			<td><b>Epaisseur de la tranche d'eau:</b></td>
    				<input id="trancheeauEdit" style="display:none;" type="text" size="4" value="<c:out value='${LithoFormTmp.waterdepth}'/>"/>
    				<span id="trancheeauStatic" style="display:none;"><c:out value='${LithoFormTmp.waterdepth}'/></span>
    				<form:errors id="error.waterdepth" path="waterdepth" cssClass="error" />
    				<form:input id="waterdepth" path="waterdepth" cssStyle="display:none;" size="4"/>
    			<td><input id="editTrancheEauBtn" type="button" value="Editer" style="display:block;" onclick="editTrancheEau(); ">
    				<input id="validateTrancheEauBtn" type="button" value="Valider" style="display:none;" onclick="submitTrancheEau(); ">
    The Javascript Function:
    function submitTrancheEau(){
    			XT.doAjaxSubmit('submitTrancheEau', this, {'trancheeauEdit' : document.getElementById('waterdepth').value }, {'formId' : 'waterdepthform'});
    When I submit whith a valid information, everything's working fine, but when I not entering any value, the validator detect it, the controler onSubmit isn't called, the AjaxHandler take the hand, and isn't doing anything because he'll update the textfield only if there arn't any errors, so the flow is redirected to the form view.
    The problem is that my view isn't "ajax-redirect:litho/litho" but "litho/litho", so an exception occurs.
    I don't understand the behavior of the ajax-redirect and how to make it working when using a ViewResolver as I am:
    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    	<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"></property>
    	<property name="prefix" value="/WEB-INF/pages/"></property>
    	<property name="suffix" value=".jsp"></property>
    Of course when I'm using "ajax-redirect:litho/litho" as the formView, it tries to fin "/WEB-INF/pages/ajax-redirect:litho/litho.jsp".

    Any help on understanding how it works and how to make it working will be apprecied : )