Announcement Announcement Module
Collapse
No announcement yet.
Validation via FormAction problem: Can't access errors bean in jsp Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Validation via FormAction problem: Can't access errors bean in jsp

    Hi!

    I'm using Spring webflow 2.0.5, spring 2.5.6 and ognl 2.7.3. My problem is, that even though the validator throws some errors, the errors aren't displayed in my jsp.

    My viewstate, which displays the form which will be validated, looks like this:
    Code:
    	<view-state id="showSearchForm" view="search/showSearchForm"
    		redirect="false" popup="false" model="searchCriteria" >
    		<on-render >
    			<set name="flowScope.searchCriteria" value="searchFormFlowAction.setupForm()" />
    		</on-render >
    
    		<transition on="search" to="showSearchResult">
    			<evaluate expression="searchFormFlowAction.bindAndValidate">
    				<attribute name="validatorMethod" value="validateShowSearchForm" />
    			</evaluate>
    		</transition >
    	</view-state>
    The form which will be displayed looks like this:
    Code:
    <form:form commandName="searchCriteria" action="${flowExecutionUrl}" >	
    
    	<table>
    		<tr>
    			<td>Price from:</td>
    			<td><form:input path="priceFrom" /></td>
    			<td><form:errors path="priceFrom" /></td>
    		</tr>
    		<!-- The rest of the fields were omitted -->
    		<tr>
    			<td colspan="2"><input type="submit" name="_eventId_search" value="Search"/></td>
    		</tr>
    	</table>
    </form:form>
    The bean searchFormFlowAction, which creates, binds and validates the form is declared like this:
    Code:
    <bean id="searchFormFlowAction" class="search.SearchFlowFormAction">
    		<property name="validator">
    			<bean class="search.SearchCriteriaValidator"/>
    		</property>
    </bean>
    The validator looks like this:
    Code:
    public class SearchCriteriaValidator implements Validator {
            public void validate(Object target, Errors errors) {
    		throw new UnsupportedOperationException("Is never called");
    	}
    
    	public void validateShowSearchForm(SearchCriteria criteria, Errors errors) {
    		if (criteria.getPriceFrom() != null && criteria.getPriceFrom() < 0.0) {
    			errors.rejectValue("priceFrom", "priceFrom.tooLow",
    					"Entered price must ge 0");
    		}
               .....
    If the users enters the form data, the validator gets called and rejects the value (I verified that via remote debugger), the transition to the next state is aborted and the current state ("showSearchForm") and so the form is reentered. So long, everything is fine. The only problem is, that the error messages of the validator aren't displayed :-(. It seems as if it weren't a problem with my jsp because if I declare my validator as a bean like this:
    Code:
    <bean id="searchCriteriaValidator" class="search.SearchCriteriaValidator"/>
    and my viewstate like this:
    Code:
    <view-state id="showSearchForm" view="search/showSearchForm"
    		redirect="false" popup="false" model="searchCriteria" >
    		<on-render >
    			<set name="flowScope.searchCriteria" value="new search.SearchCriteria()" />
    		</on-render >
    
    		<transition on="search" to="showSearchResult" />
    	</view-state>
    the error messages are correctly displayed.

    Does anybody know what the problem is?

    Regards
    Meinert

    P.S.: Maybe someone is able to spot the problem in the log:
    Code:
    ........
    2009-07-05 18:56:19,687 DEBUG [search.SearchFlowFormAction] - <There are [1] errors, details: [Field error in object 'searchCriteria' on field 'priceFrom': rejected value [-10.0]; codes [priceFrom.tolow.searchCriteria.priceFrom,priceFrom.tolow.priceFrom,priceFrom.tolow.java.lang.Double,priceFrom.tolow]; arguments []; default message [Entered price must ge 0]]>
    2009-07-05 18:56:19,687 DEBUG [search.SearchFlowFormAction] - <Putting form errors instance in scope Flow>
    2009-07-05 18:56:19,687 DEBUG [org.springframework.webflow.execution.AnnotatedAction] - <Clearing action execution attributes map['method' -> 'bindAndValidate']>
    2009-07-05 18:56:19,687 DEBUG [org.springframework.webflow.execution.ActionExecutor] - <Finished executing [SearchFlowFormAction@1a93f38 formObjectName = 'searchCriteria', formObjectClass = SearchCriteria, formObjectScope = Flow]; result = error>
    2009-07-05 18:56:19,687 DEBUG [org.springframework.webflow.execution.AnnotatedAction] - <Clearing action execution attributes map['validatorMethod' -> 'validateShowSearchForm']>
    2009-07-05 18:56:19,687 DEBUG [org.springframework.webflow.execution.ActionExecutor] - <Finished executing [EvaluateAction@10872ce expression = searchFormFlowAction.bindAndValidate, resultExposer = [null]]; result = error>
    2009-07-05 18:56:19,687 DEBUG [org.springframework.webflow.execution.repository.impl.DefaultFlowExecutionRepository] - <Putting flow execution '[FlowExecutionImpl@577c5e flow = 'search', flowSessions = list[[FlowSessionImpl@1a631c2 flow = 'search', state = 'showSearchForm', scope = map['org.springframework.validation.BindingResult.searchCriteria' -> org.springframework.validation.BeanPropertyBindingResult: 1 errors
    Field error in object 'searchCriteria' on field 'priceFrom': rejected value [-10.0]; codes [priceFrom.tolow.searchCriteria.priceFrom,priceFrom.tolow.priceFrom,priceFrom.tolow.java.lang.Double,priceFrom.tolow]; arguments []; default message [Entered price must ge 0], 'searchCriteria' -> search.SearchCriteria@6c9ec6, 'org.springframework.validation.BindingResult.currentFormObject' -> org.springframework.validation.BeanPropertyBindingResult: 1 errors
    Field error in object 'searchCriteria' on field 'priceFrom': rejected value [-10.0]; codes [priceFrom.tolow.searchCriteria.priceFrom,priceFrom.tolow.priceFrom,priceFrom.tolow.java.lang.Double,priceFrom.tolow]; arguments []; default message [Entered price must ge 0], 'currentFormObject' -> search.SearchCriteria@6c9ec6, 'viewScope' -> map[[empty]]]]]]' into repository>
    2009-07-05 18:56:19,687 DEBUG [org.springframework.webflow.execution.repository.impl.DefaultFlowExecutionRepository] - <Adding new snapshot to group with id 1>
    2009-07-05 18:56:19,687 DEBUG [org.springframework.webflow.conversation.impl.SessionBindingConversationManager] - <Putting conversation attribute 'scope' with value map['flashScope' -> map['messagesMemento' -> map[[null] -> list[[empty]]], 'webflowViewActionStateHolder' -> [ViewActionStateHolder@7056d5 eventId = 'search', mappingResults = Mapping Results = [[Success@12beeec code = 'success', error = false, originalValue = '-10', mappedValue = '-10'], [Success@152e961 code = 'success', error = false, originalValue = '', mappedValue = ''], [TargetAccessError@57f57f code = 'propertyNotFound', error = true, errorCause = org.springframework.binding.expression.PropertyNotFoundException: Property 'eventId_search' not found on context of class [search.SearchCriteria], originalValue = [null], mappedValue = [null]], [Success@128594c code = 'success', error = false, originalValue = '', mappedValue = ''], [TargetAccessError@194ba17 code = 'propertyNotFound', error = true, errorCause = org.springframework.binding.expression.PropertyNotFoundException: Property 'execution' not found on context of class [search.SearchCriteria], originalValue = 'e2s1', mappedValue = [null]]]]]]>
    2009-07-05 18:56:19,687 DEBUG [org.springframework.webflow.conversation.impl.SessionBindingConversationManager] - <Unlocking conversation 2>
    2009-07-05 18:56:19,687 DEBUG [org.springframework.webflow.mvc.servlet.FlowHandlerAdapter] - <Sending flow execution redirect to '/webflow/search.do?execution=e2s1'>
    ......

  • #2
    Did u get this resolved.

    I am pretty much stuck on the same error. I am using CAS for authentication and i am trying to spit out the validation errors onto the login screen if the user does not enter any required field.

    I see that the validation errors are captured in the error logs, but i don't get any of my form errors.

    My JSP looks like this
    Code:
    <form:form commandName="${commandName}" method="post" id="casLoginForm" class="clearfix">
    
       <div class="form:errors">
            <form:errors path="*" element="div"/>
        </div>
    
        <div class="formRow clearfix">
            <p><spring:theme code="login.description" /></p>
        </div>
        <div class="formRow clearfix">
            <label for="username"><spring:theme code="login.label.username"/></label>
    
            <form:input path="username" id="username" value="" size="25" autocomplete="off"/>
            <form:errors  path="username" />
        </div>
        <div class="formRow clearfix">
            <label for="password"><spring:theme code="login.label.password"/></label>
    
            <form:password path="password" id="password" value="" size="25" accesskey="${passwordAccessKey}" autocomplete="off"/>
    
            <a href="<spring:theme code="meetingsrvc.urls.forgotPassword"/>"><spring:theme code="login.forgotPassword"/></a>
        </div>
    
        <input type="hidden" name="_flowExecutionId" value="${flowExecutionKey}"/>
        <input type="hidden" name="_eventId" value="submit" />
        <input type="hidden" name="lt" value="${flowExecutionKey}" />
    My error log, if thats of any use

    Code:
    '[FlowExecutionImpl@6c9cce54 flow = 'login-webflow', flowSessions = list[[FlowSessionImpl@2aae2481 flow = 'login-webflow', state = 'viewLoginForm', scope = map['usernamePasswordCredentials' -> [username: ], 'service' -> [null], 'currentFormObject' -> [username: ], 'warnCookieValue' -> false, 'ticketGrantingTicketId' -> [null]], flashMap = map['org.springframework.validation.BindException.usernamePasswordCredentials' -> org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 2 errors
    Field error in object 'usernamePasswordCredentials' on field 'username': rejected value []; codes [required.username.usernamePasswordCredentials.username,required.username.username,required.username.java.lang.String,required.username]; arguments []; default message [null]
    Field error in object 'usernamePasswordCredentials' on field 'password': rejected value []; codes [required.password.usernamePasswordCredentials.password,required.password.password,required.password.java.lang.String,required.password]; arguments []; default message [null], 'org.springframework.validation.BindException.currentFormObject' -> org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 2 errors
    Field error in object 'usernamePasswordCredentials' on field 'username': rejected value []; codes [required.username.usernamePasswordCredentials.username,required.username.username,required.username.java.lang.String,required.username]; arguments []; default message [null]
    Field error in object 'usernamePasswordCredentials' on field 'password': rejected value []; codes [required.password.usernamePasswordCredentials.password,required.password.password,required.password.java.lang.String,required.password]; arguments []; default message [null]], status = Paused]]]' into repository with key '_c092C6DBB-CF29-77D1-2E27-EB338CB82BB9_kAF0B9A56-25F8-00B6-550C-2C254B399868'
    [2010-03-25 19:26:09 PDT] <btpool0-1> org.springframework.webflow.conversation.impl.SessionBindingConversationManager - DEBUG: Getting conversation 092C6DBB-CF29-77D1-2E27-EB338CB82BB9
    [2010-03-25 19:26:09 PDT] <btpool0-1> org.springframework.webflow.execution.repository.continuation.ContinuationFlowExecutionRepository - DEBUG: Adding new continuation to group with id AF0B9A56-25F8-00B6-550C-2C254B399868
    [2010-03-25 19:26:09 PDT] <btpool0-1> org.springframework.webflow.conversation.impl.SessionBindingConversationManager - DEBUG: Getting conversation 092C6DBB-CF29-77D1-2E27-EB338CB82BB9
    [2010-03-25 19:26:09 PDT] <btpool0-1> org.springframework.webflow.conversation.impl.SessionBindingConversationManager - DEBUG: Putting conversation attribute 'scope' with value map[[empty]]
    [2010-03-25 19:26:09 PDT] <btpool0-1> org.springframework.webflow.conversation.impl.SessionBindingConversationManager - DEBUG: Unlocking conversation 092C6DBB-CF29-77D1-2E27-EB338CB82BB9
    [2010-03-25 19:26:09 PDT] <btpool0-1> org.springframework.webflow.executor.support.FlowRequestHandler - DEBUG: Returning [resume] [ResponseInstruction@4977e3d4 flowExecutionKey = '_c092C6DBB-CF29-77D1-2E27-EB338CB82BB9_kAF0B9A56-25F8-00B6-550C-2C254B399868', viewSelection = 'casLoginView' [[usernamePasswordCredentials, service, commandName, org.springframework.validation.BindException.usernamePasswordCredentials, currentFormObject, warnCookieValue, ticketGrantingTicketId, org.springframework.validation.BindException.currentFormObject]], flowExecutionContext = [FlowExecutionImpl@6c9cce54 flow = 'login-webflow', flowSessions = list[[FlowSessionImpl@2aae2481 flow = 'login-webflow', state = 'viewLoginForm', scope = map['usernamePasswordCredentials' -> [username: ], 'service' -> [null], 'currentFormObject' -> [username: ], 'warnCookieValue' -> false, 'ticketGrantingTicketId' -> [null]], flashMap = map['org.springframework.validation.BindException.usernamePasswordCredentials' -> org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 2 errors
    Field error in object 'usernamePasswordCredentials' on field 'username': rejected value []; codes [required.username.usernamePasswordCredentials.username,required.username.username,required.username.java.lang.String,required.username]; arguments []; default message [null]
    Field error in object 'usernamePasswordCredentials' on field 'password': rejected value []; codes [required.password.usernamePasswordCredentials.password,required.password.password,required.password.java.lang.String,required.password]; arguments []; default message [null], 'org.springframework.validation.BindException.currentFormObject' -> org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 2 errors
    Field error in object 'usernamePasswordCredentials' on field 'username': rejected value []; codes [required.username.usernamePasswordCredentials.username,required.username.username,required.username.java.lang.String,required.username]; arguments []; default message [null]
    Field error in object 'usernamePasswordCredentials' on field 'password': rejected value []; codes [required.password.usernamePasswordCredentials.password,required.password.password,required.password.java.lang.String,required.password]; arguments []; default message [null]], status = Paused]]]]
    [2010-03-25 19:26:09 PDT] <btpool0-1> org.springframework.web.servlet.DispatcherServlet - DEBUG: Rendering view [org.springframework.web.servlet.view.JstlView: name 'casLoginView'; URL [/WEB-INF/view/jsp/citrix/login-definition.jsp]] in DispatcherServlet with name 'cas'
    [2010-03-25 19:26:09 PDT] <btpool0-1> org.springframework.web.servlet.view.JstlView - DEBUG: Added model object 'usernamePasswordCredentials' of type [org.jasig.cas.authentication.principal.UsernamePasswordCredentials] to request in view with name 'casLoginView'
    [2010-03-25 19:26:09 PDT] <btpool0-1> org.springframework.web.servlet.view.JstlView - DEBUG: Added model object 'flowExecutionContext' of type [org.springframework.webflow.engine.impl.FlowExecutionImpl] to request in view with name 'casLoginView'
    [2010-03-25 19:26:09 PDT] <btpool0-1> org.springframework.web.servlet.view.JstlView - DEBUG: Removed model object 'service' from request in view with name 'casLoginView'
    [2010-03-25 19:26:09 PDT] <btpool0-1> org.springframework.web.servlet.view.JstlView - DEBUG: Added model object 'commandName' of type [java.lang.String] to request in view with name 'casLoginView'
    [2010-03-25 19:26:09 PDT] <btpool0-1> org.springframework.web.servlet.view.JstlView - DEBUG: Added model object 'org.springframework.validation.BindException.usernamePasswordCredentials' of type [org.springframework.validation.BindException] to request in view with name 'casLoginView'
    [2010-03-25 19:26:09 PDT] <btpool0-1> org.springframework.web.servlet.view.JstlView - DEBUG: Added model object 'currentFormObject' of type [org.jasig.cas.authentication.principal.UsernamePasswordCredentials] to request in view with name 'casLoginView'
    [2010-03-25 19:26:09 PDT] <btpool0-1> org.springframework.web.servlet.view.JstlView - DEBUG: Added model object 'flowExecutionKey' of type [java.lang.String] to request in view with name 'casLoginView'
    [2010-03-25 19:26:09 PDT] <btpool0-1> org.springframework.web.servlet.view.JstlView - DEBUG: Added model object 'warnCookieValue' of type [java.lang.Boolean] to request in view with name 'casLoginView'
    [2010-03-25 19:26:09 PDT] <btpool0-1> org.springframework.web.servlet.view.JstlView - DEBUG: Removed model object 'ticketGrantingTicketId' from request in view with name 'casLoginView'
    [2010-03-25 19:26:09 PDT] <btpool0-1> org.springframework.web.servlet.view.JstlView - DEBUG: Added model object 'org.springframework.validation.BindException.currentFormObject' of type [org.springframework.validation.BindException] to request in view with name 'casLoginView'
    [2010-03-25 19:26:09 PDT] <btpool0-1> org.springframework.web.servlet.view.JstlView - DEBUG: Forwarding to resource [/WEB-INF/view/jsp/citrix/login-definition.jsp] in InternalResourceView 'casLoginView'
    [2010-03-25 19:26:09 PDT] <btpool0-1> org.apache.tiles.impl.BasicTilesContainer - DEBUG: Render request recieved for definition 'meeting.login'
    [2010-03-25 19:26:09 PDT] <btpool0-1> org.springframework.web.servlet.DispatcherServlet - DEBUG: Successfully completed request

    Comment

    Working...
    X