Announcement Announcement Module
Collapse

Spring Modules forum decommissioned in favor of Spring Extensions

As the Spring Modules project has been replaced by the Spring Extensions (http://www.springsource.org/extensions) project, this forum has been decommissioned in favour of Spring Extensions one at:
http://forum.springsource.org/forumdisplay.php?f=44

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.

Cheers,
Costin Leau
SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
http://twitter.com/costinl
See more
See less
Ajax Validation / ajax:redirect and Spring ViewResolver Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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.
    Code:
    <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" />
    </bean>
    The AjaxHandler and ValidationHandler mapping:
    Code:
    <bean id="ajaxInterceptor" class="org.springmodules.xt.ajax.AjaxInterceptor">
    	<property name="handlerMappings">
    		<props>
    			<prop key="/*.htm">ajaxHandler,ajaxValidationHandler</prop>
    		</props>
    	</property>
    </bean>
    <bean id="ajaxHandler" class="org.mmycompany.web.ajax.AjaxHandler" />
    <bean id="ajaxValidationHandler" class="org.springmodules.xt.ajax.validation.DefaultValidationHandler"/>
    My AjaxHandler called method:
    Code:
    public AjaxResponse submitTrancheEau(AjaxSubmitEvent ajxSubmEvt){
    	logger.debug("## SUBMIT TRANCHE EAU##");
    	AjaxResponse response = new AjaxResponseImpl();
    			
    	if(ajxSubmEvt.getValidationErrors().getErrorCount()==0){
    		ReplaceContentAction setTrancheEauValue = new ReplaceContentAction( "trancheeauStatic", new SimpleText(Double.toString(((LithoForm)ajxSubmEvt.getCommandObject()).getWaterdepth())));
    		response.addAction(setTrancheEauValue);        
    	}
    
        return response;
    }
    When the form validation fails, I just want the page to be displayed, including the error messages on the form:errors tags.

    Code:
    <form:form id="waterdepthform" commandName="LithoForm"> 
    	<table>
    		<tr>			
    			<td><b>Epaisseur de la tranche d'eau:</b></td>
    			<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>
    			<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(); ">
    			</td>
    			<td></td>
    		</tr>
    	</table>
    </form:form>
    The Javascript Function:
    Code:
    function submitTrancheEau(){
    			XT.doAjaxSubmit('submitTrancheEau', this, {'trancheeauEdit' : document.getElementById('waterdepth').value }, {'formId' : 'waterdepthform'});
    			hideElementById('validateTrancheEauBtn');
    			showElementById('editTrancheEauBtn');
    			showElementById('trancheeauStatic');
    			hideElementById('waterdepth');
    		}
    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:
    Code:
    <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>
    </bean>
    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 : )
    Thanks.

    MiK
Working...
X