Announcement Announcement Module
No announcement yet.
Spring webflow & @ControllerAdvice Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring webflow & @ControllerAdvice


    I'm trying to create a splited registration form with spring webflow.
    I'm also using the annotation @ControllerAdvice to create some kind of placeholder in my MVC views.

    @ControllerAdvice is called on every RequestMapping to add some data to all view. After testing, my @ControllerAdvices class is called when i hit an URL managed by spring webflow, but webflow don't use ModelAndView, so @ControllerAdvices can't add model attribute to webflow rendred view.

    Please, how can i re-use my already existing @ControllerAdvice class to add model attribute to all webflow's rendered views ?

    Here my webflow-context.xml :

    <flow:flow-builder-services id="flowBuilderService" view-factory-creator="viewFactoryCreator"/>
    	<!-- configure the mobile device view resolver -->
    	<!-- viewResolver bean is a -->
    	<beans:bean id="viewFactoryCreator" class="org.springframework.webflow.mvc.builder.MvcViewFactoryCreator">  
    		<beans:property name="viewResolvers">  
    				<beans:ref bean="viewResolver"/>  
    	<flow:flow-registry id="flowRegistry" base-path="/WEB-INF/flows" flow-builder-services="flowBuilderService">
        		<flow:flow-location-pattern value="/**/*.xml" />
    	<flow:flow-executor id="flowExecutor" flow-registry="flowRegistry"/>
    	<beans:bean class="org.springframework.webflow.mvc.servlet.FlowHandlerAdapter">
        		<beans:property name="flowExecutor" ref="flowExecutor" />
    	<beans:bean class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping">
       		<beans:property name="flowRegistry" ref="flowRegistry"/>
      		<beans:property name="order" value="-1"/>
    Thanks for any help.

  • #2
    So i comeback with a solution i just found. It's not the more elegant stuff i made in my life, but it work, but i share it if nobody find something more efficient.
    public class MycontrollerAdvice {
    	AdviceService adviceService;
    	public String setMyAttribute(){
    		return adviceService.getMyAttribute();
    public class AdviceService(){
    	public String getMyAttribute(){
    		... some code here ...
         	<evaluate expression="AdviceService.getMyAttribute()" result="flowScope.myAttribute" />
    The trick is to use a Service (or any other autowire-able component, i stupidly used a Service), proving the functionality to the other components needing it.

    It's definitively not optimized. @ControllerAdvice's @ModelAttribute is still called, because it's called with each request, at the end of the request processing AdviceService.getMyAttribute() is called at least two time.

    I'm still looking for any help to improve this.