Results 1 to 8 of 8

Thread: How can I access a Spring MVC controller in the swf-booking-faces example?

  1. #1
    Join Date
    Oct 2008
    Location
    Cambridge, MA
    Posts
    56

    Default How can I access a Spring MVC controller in the swf-booking-faces example?

    Hello All,
    I have a beginner's question:

    How can I access a Spring MVC controller in the Spring swf-booking-faces sample application?

    I have a facelets/JSF/SWF prototype, much like the swf-booking-faces sample application shipped with Spring Web Flow 2.0.6. I want to remove stateless components from the flow-config both so they can be bookmarked and because my *-flow.xml has view-states which really are standalone rather than part of a cohesive flow.

    To get started, I wrote a helloWorld controller named MyTest.java in the swf-booking-faces app. I want it to print "Hello World" to the console and render enterbookingDetails.xhtml.

    Code:
    package org.springframework.webflow.samples.booking;
    
    import javax.annotation.PostConstruct;
    
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestMethod;
    
    @Controller
    @RequestMapping("/helloWorld")
    public class MyTest {
        @PostConstruct
        public void init() {
    	System.err.println("If you can read me, this is proof I registered my bean correctly");
        }
    
        @RequestMapping(method = RequestMethod.GET)
        public String helloWorld() {
    	System.err.println("Hello World");
    	// not sure if this is the correct path.
    	return "/WEB-INF/flows/booking/enterbookingDetails.xhtml";
        }
    }
    I can confirm via the @PostConstruct init method that the controller is registered as it prints to the console. However, http://localhost:8080/swf-booking-fa...ing/helloWorld returns a 404.

    Can anyone help me figure out how to access the controller?

    Thanks in Advance,
    Steven
    Harvard Children's Hospital Informatics Program

  2. #2
    Join Date
    Aug 2004
    Location
    Melbourne, FL
    Posts
    2,794

    Default

    I would study the swf-booking-mvc example and also the Petclinic example in Spring Framework 2.5. In addition to that, you'll want to read the ref manual on the Spring MVC @Controller model. You might want to start by not using @RequestMapping conventions and specify explicit path mapping values until you understand what's going on. SpringSource also has a really good course on web development with Spring.

    Keith
    Keith Donald
    Core Spring Development Team

  3. #3
    Join Date
    Oct 2008
    Location
    Cambridge, MA
    Posts
    56

    Default

    Hello Keith,
    Thank you for responding so quickly. I did study the pet clinic actually built an MVC application very quickly, but it has a much different Spring config as well as a different web.xml and I am uncertain how to merge them, or even if that's necessary.

    Unfortunately, the pet-clinic uses JSP and our client wants to reuse their JSF/facelets UI. We're actually porting a Seam app to SWF and Spring MVC.

    I'm trying to figure out how to integrate an application like pet-clinic so it can use facelets and coexist in the a war like swf-booking-faces.

    In a post yesterday, you said:
    We always recommend people start with Spring MVC and use that as their base web framework, and use web flow where it is appropriate inside the Spring MVC application for certain stateful resources. It's not an either/or thing, Web Flow builds on and plugs into Spring MVC.
    I'm trying to figure out how to do that.

    Am I using the wrong URL?

    Can a URL pattern, like "spring/*" specified in the web.xml:
    Code:
    	<!-- Map all /spring requests to the Dispatcher Servlet for handling -->
    	<servlet-mapping>
    		<servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
    		<url-pattern>/spring/*</url-pattern>
    	</servlet-mapping>
    ...be serviced by Spring MVC and Spring Web Flow simultaneously?

    In this case, I was trying to get .../spring/helloWorld to hit the Spring MVC @Controller for a simple stateless request that needs to be bookmarked, as you previously recommended and have .../spring/booking handle the more complex flow using regular SWF.

    Can Spring MVC @Controllers co-exist in the same war as Spring Web Flow?

    Can I have them coexist in the same URL pattern or do they need different declarations?

    I really appreciate your help.
    Thanks,
    Steven

  4. #4
    Join Date
    Aug 2004
    Location
    Melbourne, FL
    Posts
    2,794

    Default

    Have a look at the swf-booking-mvc sample which shows Spring MVC Controllers and Web Flow co-existing. The app does use conventions for @RequestMapping so look at how that is enabled in mvc-config.xml and what that means. I know you have JSF views so your view resolver configuration will be different, but the @Controller and web flow layers remain the same. Keep in mind that a stateless MVC Controller cannot drive the stateful JSF component postback lifecycle. In practice this often means you can't use traditional form components on views rendered by stateless MVC controllers.

    Keith
    Keith Donald
    Core Spring Development Team

  5. #5
    Join Date
    Oct 2008
    Location
    Cambridge, MA
    Posts
    56

    Default Can you please provide a hint?

    Hello Keith,
    Thanks for responding so quickly. Can you provide more of a lead on which configs to merge? I am trying to get booking-faces to call a @Controller.

    http://localhost:8080/swf-booking-fa...ing/helloWorld keeps looking for helloWorld.xhtml instead of calling my @Controller. Even when I create helloWorld.xhtml, my @RequestMapping(method = RequestMethod.GET) is definitely not being called.

    I noticed that booking-mvc doesn't add anything to web.xml, so I assume no action is needed.


    I tried merging the webmvc-config.xml by overwriting booking-faces with booking-mvc, dropping tiles, and adding facelets. The original app works perfectly, but the @Component isn't being called.

    Here's my merged webmvc-config.xml:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="
               http://www.springframework.org/schema/beans
               http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
    
    	<!-- Maps request paths to flows in the flowRegistry; e.g. a path of /hotels/booking looks for a flow with id "hotels/booking" -->
    	<bean class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping">
    		<property name="order" value="0" />
    		<property name="flowRegistry" ref="flowRegistry" />
    	</bean>
    
    	<!-- Maps request paths to @Controller classes; e.g. a path of /hotels looks for a controller named HotelsController -->
    	<bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping">
    		<property name="order" value="1" />
    		<property name="defaultHandler">
    			<!-- If no @Controller match, map path to a view to render; e.g. the "/intro" path would map to the view named "intro" -->	
    			<bean class="org.springframework.web.servlet.mvc.UrlFilenameViewController" />
    		</property>
    	</bean>
    
    	<!-- Maps logical view names to Facelet templates in /WEB-INF (e.g. 'search' to '/WEB-INF/search.xhtml' -->
    	<bean id="faceletsViewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
    		<property name="viewClass" value="org.springframework.faces.mvc.JsfView"/>
    		<property name="prefix" value="/WEB-INF/" />
    		<property name="suffix" value=".xhtml" />
    	</bean>
    
    	<!-- Dispatches requests mapped to POJO @Controllers implementations -->
    	<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
    
    	<!-- Dispatches requests mapped to org.springframework.web.servlet.mvc.Controller implementations -->
    	<bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter" />
    
    	<!-- Dispatches requests mapped to flows to FlowHandler implementations -->
    	<bean class="org.springframework.webflow.mvc.servlet.FlowHandlerAdapter">
    		<property name="flowExecutor" ref="flowExecutor"/>
    	</bean>
    </beans>


    Here's the additions from booking-mvc:
    Code:
    	
    	<!-- Maps request paths to @Controller classes; e.g. a path of /hotels looks for a controller named HotelsController -->
    	<bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping">
    		<property name="order" value="1" />
    		<property name="defaultHandler">
    			<!-- If no @Controller match, map path to a view to render; e.g. the "/intro" path would map to the view named "intro" -->	
    			<bean class="org.springframework.web.servlet.mvc.UrlFilenameViewController" />
    		</property>
    	</bean>
    	<!-- Dispatches requests mapped to POJO @Controllers implementations -->
    	<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />

    I noticed that:
    Code:
    	<!-- Plugs in a custom creator for Web Flow views -->
    	<webflow:flow-builder-services id="flowBuilderServices" view-factory-creator="mvcViewFactoryCreator" conversion-service="conversionService" development="true" />
    ...in booking-mvc's webflow-config.xml is different than booking-faces's webflow-config.xml:
    Code:
    	<!-- Configures the Spring Web Flow JSF integration -->
    	<faces:flow-builder-services id="facesFlowBuilderServices" development="true" />
    Do you have any leads on which configs should change to integrate Spring MVC and facelets so that an @Controller can be called in an SWF/JSF/facelets app, like booking-mvc? I wanted the MyTest.java @Controller class to be called for /spring/helloWorld and return a properly rendered facelets view.

    Thanks again,
    Steven

  6. #6
    Join Date
    Feb 2010
    Posts
    5

    Default Hotel Booking Example - Tooltip

    I have studied the Hotel booking example and now i found,
    <context:component-scan base-package="org.springframework.webflow.samples.booki ng" />

    is responsible for smooth execution of booking example,
    i can see tooltip for search textbox for entering search criteria,

    i want to use that in my application,
    That is another application that i have created inspired from booking hotel example,

    i just want to use tooltip from that project and for that,
    what i need to do is not known to me,
    kindly help me to find out the solution.

    Thank you in advance.

  7. #7
    Join Date
    Aug 2006
    Location
    Brooklyn
    Posts
    556

    Default

    Quote Originally Posted by JavaGeek_Boston View Post
    Can a URL pattern, like "spring/*" specified in the web.xml:
    Code:
    	<!-- Map all /spring requests to the Dispatcher Servlet for handling -->
    	<servlet-mapping>
    		<servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
    		<url-pattern>/spring/*</url-pattern>
    	</servlet-mapping>
    ...be serviced by Spring MVC and Spring Web Flow simultaneously?
    Yes it can. Here are two sample URLs from swf-booking-mvc:

    /swf-booking-mvc/spring/hotels/index
    /swf-booking-mvc/spring/hotels/booking?execution=e1s1

    One is handled by the Hotel controller's index method and the other by the booking flow.

  8. #8
    Join Date
    Feb 2010
    Posts
    5

    Default Thank you

    Thank you sir for your valuable reply.
    i understood what u want to say,
    but the my intention for asking question was,

    how DOJO toolkit used of creating tooltip themes?

    and that i found in one of the theme "tundra" for DOJO class.
    and i got the ToolTip.

    Thank you very much for your reply.
    Good Night.
    - Sandy<INDIA>

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •