Announcement Announcement Module
Collapse
No announcement yet.
Apache Trinidad ajax requests don't work with SWF version 2.0.7. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Apache Trinidad ajax requests don't work with SWF version 2.0.7.

    In doResume method (ViewState.class), isAjaxRequest always returns false, SWF executes a redirect and PPR requests fail.

    To solve this I create and configure a new ajaxHandler:

    Code:
    package com.mycompany.spring;
    
    import java.io.IOException;
    
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    import org.springframework.js.ajax.AjaxHandler;
    
    /**
     * Ajax handler for Apache Trinidad.
     * 
     */
    public class ApacheTrinidadAjaxHandler implements AjaxHandler {
    
    	/**
    	 * The response header to be set on an Ajax redirect
    	 */
    	public static final String REDIRECT_URL_HEADER = "Spring-Redirect-URL";
    
    	/**
    	 * The response header to be set on an redirect that should be issued from a popup window.
    	 */
    	public static final String POPUP_VIEW_HEADER = "Spring-Modal-View";
    
    	
    	public boolean isAjaxRequest(HttpServletRequest request, HttpServletResponse response) {
    		String trXHRMessageHeader = request.getHeader("Tr-XHR-Message");
    		
    		return (trXHRMessageHeader!=null && trXHRMessageHeader.equals("true"));
    
    	}
    
    	public void sendAjaxRedirect(String targetUrl, HttpServletRequest request, HttpServletResponse response,
    			boolean popup) throws IOException {
    		if (popup) {
    			response.setHeader(POPUP_VIEW_HEADER, "true");
    		}
    		response.setHeader(REDIRECT_URL_HEADER, response.encodeRedirectURL(targetUrl));
    	}
    
    }

    Code:
    <!-- Handles requests mapped to the Spring Web Flow system -->
    	<bean id="flowController" class="org.springframework.webflow.mvc.servlet.FlowController">
    		<property name="flowExecutor" ref="flowExecutor" />
    		<property name="ajaxHandler">
    			<bean class="com.mycompany.spring.ApacheTrinidadAjaxHandler" />
    		</property>
    	</bean>
    My workaround works well. But please tell me if there is another way to make it.
    Last edited by msosvi; Sep 27th, 2011, 08:10 AM.

  • #2
    Clever. I've tried to keep SWF separate from Trinidad's PPR, so Trinidad's AJAX doesn't even hit SWF. I may give this a try.

    Comment


    • #3
      Originally posted by msosvi View Post
      In doResume method (ViewState.class), isAjaxRequest always returns false, SWF executes a redirect and PPR requests fail.

      To solve this I create and configure a new ajaxHandler:

      Code:
      package com.mycompany.spring;
      
      import java.io.IOException;
      
      import javax.servlet.http.HttpServletRequest;
      import javax.servlet.http.HttpServletResponse;
      
      import org.springframework.js.ajax.AjaxHandler;
      
      /**
       * Ajax handler for Apache Trinidad.
       * 
       */
      public class ApacheTrinidadAjaxHandler implements AjaxHandler {
      
      	/**
      	 * The response header to be set on an Ajax redirect
      	 */
      	public static final String REDIRECT_URL_HEADER = "Spring-Redirect-URL";
      
      	/**
      	 * The response header to be set on an redirect that should be issued from a popup window.
      	 */
      	public static final String POPUP_VIEW_HEADER = "Spring-Modal-View";
      
      	
      	public boolean isAjaxRequest(HttpServletRequest request, HttpServletResponse response) {
      		String trXHRMessageHeader = request.getHeader("Tr-XHR-Message");
      		
      		if (trXHRMessageHeader!=null && trXHRMessageHeader.equals("true")) {
      			return true;
      		} else {
      			return false;
      		}
      	}
      
      	public void sendAjaxRedirect(String targetUrl, HttpServletRequest request, HttpServletResponse response,
      			boolean popup) throws IOException {
      		if (popup) {
      			response.setHeader(POPUP_VIEW_HEADER, "true");
      		}
      		response.setHeader(REDIRECT_URL_HEADER, response.encodeRedirectURL(targetUrl));
      	}
      
      }

      Code:
      <!-- Handles requests mapped to the Spring Web Flow system -->
      	<bean id="flowController" class="org.springframework.webflow.mvc.servlet.FlowController">
      		<property name="flowExecutor" ref="flowExecutor" />
      		<property name="ajaxHandler">
      			<bean class="com.mycompany.spring.ApacheTrinidadAjaxHandler" />
      		</property>
      	</bean>
      My workaround works well. But please tell me if there is another way to make it.
      Thanks msosvi
      For me the myFaces Trinidad Poll Element (http://myfaces.apache.org/trinidad/t...c/tr_poll.html) worked for me with with following modifications

      environment:
      • Tomcat 6.0.18
      • JDK 1.6.0_16
      • Spring Core 2.5.6
      • Spring Webflow 2.0.8 BUILD-20091109151627
      • trinidad 1.2.12


      Code:
      import javax.servlet.http.HttpServletRequest;
      import javax.servlet.http.HttpServletResponse;
      
      import org.springframework.js.ajax.SpringJavascriptAjaxHandler;
      
      /**
       * Ajax handler for Apache Trinidad. http://jira.springframework.org/browse/SWF-1160
       */
      public class ApacheTrinidadAjaxHandler extends SpringJavascriptAjaxHandler {
      
          @Override
          public boolean isAjaxRequest(HttpServletRequest request, HttpServletResponse response) {
      	boolean isAjax = super.isAjaxRequest(request, response);
      	if (!isAjax) {
      	    String trXHRMessageHeader = request.getHeader("Tr-XHR-Message");
      	    isAjax = trXHRMessageHeader != null && trXHRMessageHeader.equals("true");
      	}
      	return isAjax;
          }
      }
      config:
      Code:
      <!-- Dispatches requests mapped to flows to FlowHandler implementations -->
      	<bean class="org.springframework.webflow.mvc.servlet.FlowHandlerAdapter">
      		<property name="flowExecutor" ref="flowExecutor" />
      		<property name="ajaxHandler">
      			<bean class="my.company.faces.handler.ApacheTrinidadAjaxHandler"/>
      		</property>
      	</bean>

      Comment

      Working...
      X