Results 1 to 10 of 10

Thread: Richfaces and Ajax returns redirect?

  1. #1

    Default Richfaces and Ajax returns redirect?

    Hi,

    I am trying to use a4j and richfaces so I can render part of the page in response to an ajax call. I am able to render fragments using sf:commandLink, passing an action and using <render fragments=activeStateOutput/> in my transitions but I cannot acheive the same using A4J (I need this to support richfaces ajax functionality - i.e. rich:dataScroller).

    Perhaps I am not correctly understanding the process but after I click on my a4j enabled link, the ajax call is made, the correct transition is called (using action=showActiveState) but the response coming back from the server contains nothing except an ajax redirect instruction. This causes the brower window to redirect to the url returned by the server.

    Here is my transition

    Code:
    <transition on="showActiveState">
    			<evaluate expression="proposal.addPublication(null)"/>
    			<render fragments="activeStateOutput"/>
    		</transition>
    Here is my xhtml definition
    Code:
    <a4j:outputPanel id="activeStateOutput">
    			<div id="activeStateDiv">
    				<h:form id="activeStateForm">
    					<h:outputText value="#{proposal.activeState}"/>
    					<h:inputText value="#{proposal.activeState}"/>
    					<a4j:commandLink id="update" value="Update" reRender="#{flowRenderFragments}" action="showActiveState"/>
    				</h:form>	
    			</div>
    		</a4j:outputPanel>
    Here is the generated javascript on my link
    Code:
    A4J.AJAX.Submit('_viewRoot','activeStateForm',event,{'similarityGroupingId':'activeStateForm:update','parameters':{'activeStateForm:update':'activeStateForm:update'} ,'actionUrl':'/duo/proposal/create?execution=e12s1'} );return false;
    Here is the response:

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <html xmlns="http://www.w3.org/1999/xhtml"><head><meta name="Ajax-Response" content="redirect" /><meta
     name="Location" content="/duo/proposal/create?execution=e12s1" /></head></html>
    Is this the expected response?

    I was hoping to be able to partially replace the page according to #{flowRenderFragments}. In this instance it should reRender activeStateOutput

    I am using Richfaces 3.3.1 and webflow 2.0.7.

  2. #2

    Default

    Ok well I just fixed this. I had both

    HTML Code:
    <bean class="org.springframework.webflow.mvc.servlet.FlowHandlerAdapter">
            <property name="flowExecutor" ref="flowExecutor"/>
    <property name="ajaxHandler">
                <bean class="org.springframework.faces.richfaces.RichFacesAjaxHandler"/>
            </property>
        </bean>
    and

    HTML Code:
    <bean id="flowController" class="org.springframework.webflow.mvc.servlet.FlowController">
            <property name="flowExecutor" ref="flowExecutor" />
            <property name="ajaxHandler">
                <bean class="org.springframework.faces.richfaces.RichFacesAjaxHandler"/>
            </property>
        </bean>
    So my ajax request was not being identified. I removed the controller (not sure where that came from) and added the ajax handler to the flowhandleradaptor.

    HTML Code:
    <bean class="org.springframework.webflow.mvc.servlet.FlowHandlerAdapter">
            <property name="flowExecutor" ref="flowExecutor"/>
    <property name="ajaxHandler">
                <bean class="org.springframework.faces.richfaces.RichFacesAjaxHandler"/>
            </property>
        </bean>
    The thread below gave me the hint.

    http://forum.springsource.org/showthread.php?t=74388

  3. #3
    Join Date
    Mar 2009
    Posts
    8

    Default Got same problem

    Hi mrpack,

    I've got same problem.
    I've checked my bean config to see if same fix can be applied , but I have only one FlowController defined. I tried to change it to FlowHandlerAdapter like you, but the problem still exists.
    Could you post your sample application/setting here?

    Thanks in advance,

    --
    Nguyen Anh Phu

  4. #4

    Default

    Hi Phuna,

    Here is my webflow config... The only non-standard bit (that i know of) is the SharedHibernateFlowExecutionListener which is not relevant to this problem anyway.

    Code:
    <!-- Enables FlowHandler URL mapping -->
        <bean class="org.springframework.webflow.mvc.servlet.FlowHandlerAdapter">
            <property name="flowExecutor" ref="flowExecutor"/>
            <property name="ajaxHandler" ref="ajaxHandler"/>
        </bean>
        
        <bean id="ajaxHandler" class="org.springframework.faces.richfaces.RichFacesAjaxHandler"/>
    
    <!-- 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="flowRegistry" ref="flowRegistry"/>
            <property name="order" value="2"/>
            <property name="defaultHandler">
    			<!-- If no flow match, map path to a view to render; e.g. the "/home" path would map to the view named "home" -->	
    			<bean class="org.springframework.web.servlet.mvc.UrlFilenameViewController" />
    		</property>
        </bean>
    
    <!-- Maps logical view names to Facelet templates in /WEB-INF (e.g. 'home' to '/WEB-INF/home.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/faces/" />
    		<property name="suffix" value=".xhtml" />
    	</bean>
    
    <!-- Dispatches requests mapped to org.springframework.web.servlet.mvc.Controller implementations -->
    	<!-- Used to handle requests that do not use a flow -->
    	<bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter" />
    
    
        <!-- Setup Web Flow here -->
        <!-- Executes flows: the central entry point into the Spring Web Flow system -->
        <webflow:flow-executor id="flowExecutor">
        	<webflow:flow-execution-listeners>
            	<webflow:listener ref="hibernateFlowExecutionListener" />
            	<webflow:listener ref="securityFlowExecutionListener" />
        	</webflow:flow-execution-listeners>    	
        </webflow:flow-executor>
        
        <bean id="hibernateFlowExecutionListener" class="uk.ac.diamond.duo.common.webui.web.hibernate.SharedHibernateFlowExecutionListener">
        	<constructor-arg ref="sessionFactory" />
        	<constructor-arg ref="transactionManager" />
    	</bean>
        <!-- <bean id="hibernateFlowExecutionListener" class="org.springframework.webflow.persistence.HibernateFlowExecutionListener">
        	<constructor-arg ref="sessionFactory" />
        	<constructor-arg ref="transactionManager" />
    	</bean> -->
        
        <!-- The registry of executable flow definitions -->
        <webflow:flow-registry id="flowRegistry" flow-builder-services="facesFlowBuilderServices" base-path="/WEB-INF/flows">
            <webflow:flow-location-pattern value="/**/*-flow.xml"/>
        </webflow:flow-registry>
    
        <!-- Configures the Spring Web Flow JSF integration -->
        <faces:flow-builder-services id="facesFlowBuilderServices"  development="true"/>
        
        <!-- Installs a listener to apply Spring Security authorities -->
    	<bean id="securityFlowExecutionListener" class="org.springframework.webflow.security.SecurityFlowExecutionListener" />
    I think some of web.xml was also relevant...
    Code:
    <filter>
      <display-name>RichFaces Filter</display-name>
      <filter-name>richfaces</filter-name>
      <filter-class>org.ajax4jsf.Filter</filter-class>
     </filter>
    
     <servlet>
      <servlet-name>dispatcher</servlet-name>
      <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
      <init-param>
       <param-name>contextConfigLocation</param-name>
       <param-value/>
      </init-param>
      <load-on-startup>2</load-on-startup>
     </servlet>
    
    
     <filter-mapping>
      <filter-name>richfaces</filter-name>
      <servlet-name>dispatcher</servlet-name>
      <dispatcher>REQUEST</dispatcher>
      <dispatcher>FORWARD</dispatcher>
      <dispatcher>INCLUDE</dispatcher>
     </filter-mapping>

  5. #5
    Join Date
    Mar 2009
    Posts
    8

    Default Thank you :)

    Thank you mrpack,

    Looking at your configuration, I found that I have 2 FlowHandlerAdapter actually! One in bean config and one in webflow config. I removed one of them and it works fine now.

    Thank you very much for your help.

  6. #6
    Join Date
    Aug 2009
    Posts
    19

    Default

    After searching in google I found that this one is the most related to my problem.

    I'm using webflow 2.0.7, richfaces 3.3.1 and spring security 2.0.5

    When I make an ajax request and the user session is expired I'm redirected to the login page (custom one), I'm able to login but after that the html I receive is

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <html xmlns="http://www.w3.org/1999/xhtml"><head><meta name="Ajax-Response" content="redirect" /><meta name="Location" content="/Schoolix/groups/new.sp" /></head></html>
    So my page is white and I have to make f5 refresh to see my application (because the url in the browser is the right one).

    Here is my webflow configuration
    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" xmlns:webflow="http://www.springframework.org/schema/webflow-config"
    	xmlns:faces="http://www.springframework.org/schema/faces"
    	xsi:schemaLocation="
               http://www.springframework.org/schema/beans
               http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
               http://www.springframework.org/schema/webflow-config
               http://www.springframework.org/schema/webflow-config/spring-webflow-config-2.0.xsd
               http://www.springframework.org/schema/faces
               http://www.springframework.org/schema/faces/spring-faces-2.0.xsd"
    
    	default-autowire="byName">
    
    
    	<!--
    		Executes flows: the central entry point into the Spring Web Flow
    		system
    	-->
    	<webflow:flow-executor id="flowExecutor">
    		<webflow:flow-execution-listeners>
    			<webflow:listener ref="jpaFlowExecutionListener" />
    			<webflow:listener ref="securityFlowExecutionListener" />
    		</webflow:flow-execution-listeners>
    	</webflow:flow-executor>
    
    	<!-- The registry of executable flow definitions -->
    	<webflow:flow-registry id="flowRegistry"
    		flow-builder-services="facesFlowBuilderServices" base-path="/WEB-INF/flows">
    		<webflow:flow-location-pattern value="/**/*-flow.xml" />
    	</webflow:flow-registry>
    
    	<!-- Configures the Spring Web Flow JSF integration -->
    	<bean id="selectItemsConversionService"
    		class="eu.dreamix.schoolix.view.swf.SelectItemsConversionService">
    	</bean>
    
    	<faces:flow-builder-services id="facesFlowBuilderServices"
    		development="true" expression-parser="expressionParser"
    		conversion-service="selectItemsConversionService" />
    
    	<bean id="expressionParser"
    		class="org.springframework.webflow.expression.WebFlowOgnlExpressionParser">
    		<property name="conversionService" ref="selectItemsConversionService" />
    	</bean>
    
    	<!--
    		Installs a listener that manages JPA persistence contexts for flows
    		that require them
    	-->
    	<bean id="jpaFlowExecutionListener"
    		class="org.springframework.webflow.persistence.JpaFlowExecutionListener">
    		<constructor-arg ref="entityManagerFactory" />
    		<constructor-arg ref="transactionManager" />
    	</bean>
    
    	<!-- Installs a listener to apply Spring Security authorities -->
    	<bean id="securityFlowExecutionListener"
    		class="org.springframework.webflow.security.SecurityFlowExecutionListener" />
    
    	<bean id="ajaxHandler"
    		class="org.springframework.faces.richfaces.RichFacesAjaxHandler" />
    
    	<bean class="org.springframework.webflow.mvc.servlet.FlowHandlerAdapter" />
    
    
    
    </beans>
    Anyone solution?

  7. #7

    Default

    Your problem sounds similar to this..

    http://forum.springsource.org/showthread.php?t=56772&highlight=session+timeout+a jax+commence&page=3

    I never got a login screen in my case but I think thats because I was using CAS security.

  8. #8
    Join Date
    Aug 2009
    Posts
    19

    Default

    Here I found the reason and the solution http://forum.springsource.org/showthread.php?t=76771

  9. #9
    Join Date
    Sep 2009
    Posts
    26

    Default

    Quote Originally Posted by phuna View Post
    Thank you mrpack,

    Looking at your configuration, I found that I have 2 FlowHandlerAdapter actually! One in bean config and one in webflow config. I removed one of them and it works fine now.

    Thank you very much for your help.
    Thanks man i had the same problem, having 2 flowhandleradapter too!!!!!!!!!!!!!!!!!!!
    Now my richface integration is fully functional!! nice!!

    Cheers

  10. #10
    Join Date
    Nov 2010
    Location
    Johannesburg, South Africa
    Posts
    11

    Default Thanks!

    Thanks to all the contributors to this thread. I had the same problem until I read 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
  •