Results 1 to 4 of 4

Thread: FlowHandler.handleException question

  1. #1
    Join Date
    May 2005
    Location
    California, US
    Posts
    735

    Default FlowHandler.handleException question

    I'm still stumbling around in the dark trying to figure out how to handle NoSuchFlowExecutionException.

    If my FlowHandler.handleException() returns null my browser is sent to

    /swf-example/addUser

    If my FlowHandler.handleException() returns the empty string my browser is sent to

    /swf-example/addUser.zug/

    or, whatever string it returns is appended to the above.

    addUser is the flow identifier. addUser.zug is the start of the flow;
    Code:
        <beans:bean id="flowUrlMappings"
                class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
            <beans:property name="mappings">
                <beans:value>
                    /addUser.zug=addUserFlowHandler
                </beans:value>
            </beans:property>
        </beans:bean>
    And in my web.xml the servlet-mapping section has *.zug for the url-pattern.

    Question 1: why the difference in behavior?

    Question 2: Given this behavior I still don't see how I can display a specific view from the NoSuchFlowExecutionException when the user uses the back button after the flow has finished (or any other exception under other conditions).

  2. #2

    Default

    I have exactly the same problem

    My flow mapping

    /back/product/searchProduct.html=flowController

    And in my web.xml the servlet-mapping section has *.html for the url-pattern

    But when a NoSuchFlowExecutionException is fired the browser is sent to

    /back/product/searchProduct

    instead of

    /back/product/searchProduct.html
    mic

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

    Default

    Did you guys see the JavaDoc for the String returned from handleExecutionOutcome and handleException?

    Code:
    	 * The following prefixes are supported for qualifying the returned location string:
    	 * <ul>
    	 * <li>servletRelative: - the location is relative to the current servlet</li>
    	 * <li>contextRelative: - the location is relative to the current web application</li>
    	 * <li>serverRelative: - the location is relative to the server root</li>
    	 * </ul>
    	 * If the returned location is a path with no prefix, for example "/hotels/index", it is treated as relative to the
    	 * current servlet by default. Fully qualified URLs beginning with http:// or https:// may also be returned.
    	 * <p>
    	 * For servlet-relative, context-relative, and server-relative URLs, a leading slash is optional.
    With that said, it's quite possible there is an issue with *.htm mappings and generating flow definition urls using the available FlowUrlHandlers. These days, we do not generally recommend that style of extension based mapping, but a path-based mapping instead. However, we still should make sure *.htm mappings work completely.

    Have a look at the DefaultFlowUrlHandler or the WebFlow1UrlHandler code if you are using it to see what I mean. You could plug in a custom extension to one of these classes for the time being.

    Keith
    Keith Donald
    Core Spring Development Team

  4. #4

    Default

    Ok thanks

    Here is a fix for flowController mapped to extension :

    Code:
    package com.netapsys.shop.flow.handler;
    
    import javax.servlet.http.HttpServletRequest;
    
    import org.springframework.webflow.context.servlet.DefaultFlowUrlHandler;
    import org.springframework.webflow.core.collection.AttributeMap;
    
    /**
     * An extension of {@link DefaultFlowUrlHandler} to handle
     * the relaunch of flow mapped with extension such "*.html". 
     * 
     * When the swf send a redirect to the browser for an expired flow  
     * the url is simply the id of the flow.
     * 
     * Thus this class is a quick fix and should be deprecated soon.
     * 
     * How to use it ?
     * 
     * In Your dispatcher config :
     *   &lt;bean id="flowController" class="org.springframework.webflow.mvc.servlet.FlowController"&gt;
     *       &lt;constructor-arg ref="flowExecutor" /&gt;
     *       &lt;property name="flowUrlHandler" ref="urlHandler" /&gt;
     *   &lt;/bean&gt; 
     *   &lt;bean id="urlHandler" class="com.netapsys.shop.flow.handler.SimpleExtensionUrlHandler"&gt;
     *       &lt;property name="extension" value="html" /&gt;
     *   &lt;/bean&gt;
     * 
     * @author Michael Courcy
     * @date 4 mai 08
     * @version $Revision$ $Date$
     * 
     */
    public class SimpleExtensionUrlHandler
        extends DefaultFlowUrlHandler
    {
    
        /**
         * The extension we must add at the end of the url when the a redicect is
         * sent to the browser.
         */
        private String extension = "";
    
        /**
         * {@inheritDoc}
         * 
         * @see org.springframework.webflow.context.servlet.DefaultFlowUrlHandler
         * #createFlowDefinitionUrl(java.lang.String,
         * org.springframework.webflow.core.collection.AttributeMap,
         * javax.servlet.http.HttpServletRequest)
         */
        public String createFlowDefinitionUrl(final String flowId,
                final AttributeMap input, final HttpServletRequest request)
        {
            final String initialUrl = super.createFlowDefinitionUrl(flowId, input,
                    request);
            if ("".equals(extension)) {
                return initialUrl;
            }
            else {
                final String urlWithExtension = addExtenstionToUrl(initialUrl,
                        extension);
                return urlWithExtension;
            }
    
        }
    
        /**
         * Add an extension to the url.
         * 
         * @param initialUrl the url we must change with an extra extension
         * @param ext the value of the extension, you have to set this extension
         * with {@link #setExtension(String)}
         * @return the url modified
         */
        public String addExtenstionToUrl(final String initialUrl, final String ext)
        {
            final int posQuestionMark = initialUrl.indexOf("?");
            if (posQuestionMark == -1) {
                return initialUrl + "." + ext;
            }
            else {
                final String firstPartUrl = initialUrl.substring(0, posQuestionMark);
                final String secondPartUrl = initialUrl.substring(posQuestionMark);
                return firstPartUrl + "." + ext + secondPartUrl;
            }
        }
    
        /**
         * Getter for <code>extension</code>.
         * 
         * @return the value of extension.
         */
        public String getExtension()
        {
            return extension;
        }
    
        /**
         * Setter for <code>extension</code>.
         * 
         * @param extension : the value to set in extension.
         */
        public void setExtension(final String extension)
        {
            this.extension = extension;
        }
    
    }
    in your dispatcher config :
    Code:
    <bean id="flowController" class="org.springframework.webflow.mvc.servlet.FlowController">
    		<constructor-arg ref="flowExecutor" />
    		<property name="flowUrlHandler" ref="urlHandler" />
    	</bean>	
    	<bean id="urlHandler" class="com.netapsys.shop.flow.handler.SimpleExtensionUrlHandler">
    		<property name="extension" value="html" />
    	</bean>
    For you lumpynose yo will use "zug" instead of "html".

    Do you want me to propose a fix directly in DefaultFlowUrlHandler ?
    mic

Posting Permissions

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