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

  • Spring webflow & @ControllerAdvice

    Hello,

    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 :

    Code:
    <flow:flow-builder-services id="flowBuilderService" view-factory-creator="viewFactoryCreator"/>
    	
    	<!-- configure the mobile device view resolver -->
    	<!-- viewResolver bean is a org.springframework.mobile.device.view.LiteDeviceDelegatingViewResolver -->
    	<beans:bean id="viewFactoryCreator" class="org.springframework.webflow.mvc.builder.MvcViewFactoryCreator">  
    		<beans:property name="viewResolvers">  
    			<beans:list>  
    				<beans:ref bean="viewResolver"/>  
    			</beans:list>  
    		</beans:property>  
    	</beans:bean>
    
    	<flow:flow-registry id="flowRegistry" base-path="/WEB-INF/flows" flow-builder-services="flowBuilderService">
        		<flow:flow-location-pattern value="/**/*.xml" />
    	</flow:flow-registry>
    	
    	<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>
    	
    	<beans:bean class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping">
       		<beans:property name="flowRegistry" ref="flowRegistry"/>
      		<beans:property name="order" value="-1"/>
    	</beans:bean>
    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.

    MyControllerAdvice.java
    Code:
    @ControllerAdvice
    public class MycontrollerAdvice {
    	@Autowired
    	AdviceService adviceService;
    
    	@ModelAttribute("myAttribute")
    	public String setMyAttribute(){
    		return adviceService.getMyAttribute();
    	}
    }
    AdviceServiceImpl.java
    Code:
    @Service
    public class AdviceService(){
    	@Override
    	public String getMyAttribute(){
    		... some code here ...
    	}
    }
    webflow-context.xml
    Code:
    <on-start>
         	<evaluate expression="AdviceService.getMyAttribute()" result="flowScope.myAttribute" />
    </on-start>
    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.

    Comment

    Working...
    X