Search code examples
spring-webflow

How to obtain httpServletRequest in validate method of SpringWebFlow


I need to access httpServletRequest in the validate method of spring webflow. Please help me how to do this.

My webflow for view state is:

    <var name="search" class="com.test.form.Search"/>
...................
    <view-state id="search" model="search" view="searchPage"> 
            <transition on="submit" to="searchAction">
            </transition>
        </view-state>
...............

validate method in search model class is:

public void validateLoanSearch(ValidationContext context) {
//I need to get a httpServletRequest here...
}

In action/controller class I can get it thru RequestContext but ValidationContext gives only the messageContext. Any idea? Please help.


Solution

  • I got the solution.

    In the bean class or validator class inside the validate method use this:

    RequestContext rc = RequestContextHolder.getRequestContext();
    

    RequestContextHolder is becoming available inside the validate method.