Note that there are some explanatory texts on larger screens.

plurals
  1. POPrimeFaces Ajax calls always return a 302 error code
    primarykey
    data
    text
    <p>I'm creating a project with Spring 3.2.0, PrimeFaces 3.3.1, Mojarra 2.1.11 and then Spring Security 3.1.1.</p> <p>My problem is the whenever an ajax call is fired by PrimeFaces, like for example in table pagination, the screen components are not refreshed.</p> <p><strong>EDIT #4</strong></p> <p><strong>Whenever an ajax called is fired, an error 302 is returned from the server and the page is refreshed</strong></p> <p>I think the problem is related to Spring security, this are my settings:</p> <pre><code> &lt;security:http entry-point-ref="authenticationEntryPoint" pattern="/spring/**"&gt; &lt;security:anonymous /&gt; &lt;security:http-basic /&gt; &lt;security:custom-filter position="FORM_LOGIN_FILTER" ref="authenticationProcessingFilter" /&gt; &lt;security:logout logout-url="/spring/logout" logout-success-url="/spring/login?logout=true" /&gt; &lt;security:intercept-url pattern="/spring/login" access="ROLE_ANONYMOUS,ROLE_USER,ROLE_ADMIN" /&gt; &lt;security:intercept-url pattern="/spring/logoutSuccess" access="ROLE_ANONYMOUS,ROLE_USER,ROLE_CLIENT" /&gt; &lt;security:intercept-url pattern="/spring/intro" access="ROLE_ANONYMOUS,ROLE_USER" /&gt; &lt;security:intercept-url pattern="/spring/flows/admin_main_flow/**" access="ROLE_ADMIN" /&gt; &lt;security:intercept-url pattern="/spring/flows/client_main_flow/**" access="ROLE_CLIENT" /&gt; &lt;/security:http&gt; &lt;security:http security="none" pattern="/javax.faces.resource/**" /&gt; &lt;security:http security="none" pattern="/ajax/**" /&gt; &lt;security:http security="none" pattern="/static/**" /&gt; &lt;security:http security="none" pattern="/resources/**" /&gt; </code></pre> <p>This happen just after the login so I don't think the session should be already expired.</p> <p><strong>EDIT #4 end</strong></p> <p>I stripped down the application to a minimum and tried this code:</p> <pre><code>&lt;h:form id="testAjax" &gt; &lt;h:panelGrid columns="4" cellpadding="5"&gt; &lt;h:outputLabel for="test" value="test:" style="font-weight:bold"/&gt; &lt;p:inputText id="test" value="#{testBean.test}" /&gt; &lt;p:commandButton value="Submit" update="@form"/&gt; &lt;h:outputText value="#{testBean.test}" id="display" /&gt; &lt;/h:panelGrid&gt; &lt;/h:form&gt; </code></pre> <p>note that I double checked that no forms are nested, I tried both "process" and "update" with @form or the elements id.</p> <p>What happens is that the setter of TestBean is called, the attribute setted, but then the getter is never called again to display the new value. This are the logs on server side:</p> <pre><code>org.springframework.web.servlet.DispatcherServlet - DispatcherServlet with name 'Spring MVC Dispatcher Servlet' processing POST request for [/TryAjax/spring/WEB-INF/login.xhtml] org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - Mapping [/WEB-INF/login.xhtml] to HandlerExecutionChain with handler [org.springframework.web.servlet.mvc.UrlFilenameViewController@2f46ccac] and 1 interceptor org.springframework.web.servlet.mvc.UrlFilenameViewController - Returning view name 'WEB-INF/login' for lookup path [/WEB-INF/login.xhtml] org.springframework.web.servlet.DispatcherServlet - Rendering view [org.springframework.faces.mvc.JsfView: name 'WEB-INF/login'; URL [/WEB-INF/WEB-INF/login.xhtml]] in DispatcherServlet with name 'Spring MVC Dispatcher Servlet' org.springframework.faces.support.RequestLoggingPhaseListener - Entering JSF Phase: RESTORE_VIEW 1 org.springframework.faces.mvc.JsfView - Asking faces lifecycle to render org.springframework.faces.support.RequestLoggingPhaseListener - Entering JSF Phase: RENDER_RESPONSE 6 org.springframework.faces.mvc.JsfView - View rendering complete org.springframework.web.servlet.DispatcherServlet - Successfully completed request </code></pre> <p>I fear is a problem of configuration, I followed the basic instruction but then made some modifications to correct some errors, here's the web.xml stripped of some not relevant part</p> <pre><code>&lt;?xml version = '1.0'?&gt; &lt;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"&gt; &lt;context-param&gt; &lt;param-name&gt;log4jConfigLocation&lt;/param-name&gt; &lt;param-value&gt;/WEB-INF/log4j.xml&lt;/param-value&gt; &lt;/context-param&gt; &lt;listener&gt; &lt;listener-class&gt;org.springframework.web.util.Log4jConfigListener&lt;/listener-class&gt; &lt;/listener&gt; &lt;context-param&gt; &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt; &lt;param-value&gt;/WEB-INF/spring_context.xml&lt;/param-value&gt; &lt;/context-param&gt; &lt;servlet&gt; &lt;servlet-name&gt;Spring MVC Dispatcher Servlet&lt;/servlet-name&gt; &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt; &lt;init-param&gt; &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt; &lt;param-value&gt;&lt;/param-value&gt; &lt;/init-param&gt; &lt;load-on-startup&gt;1&lt;/load-on-startup&gt; &lt;/servlet&gt; &lt;servlet-mapping&gt; &lt;servlet-name&gt;Spring MVC Dispatcher Servlet&lt;/servlet-name&gt; &lt;url-pattern&gt;/spring/*&lt;/url-pattern&gt; &lt;/servlet-mapping&gt; &lt;listener&gt; &lt;listener-class&gt;org.springframework.security.web.session.HttpSessionEventPublisher&lt;/listener-class&gt; &lt;/listener&gt; &lt;listener&gt; &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt; &lt;/listener&gt; &lt;listener&gt; &lt;listener-class&gt;org.springframework.web.context.request.RequestContextListener &lt;/listener-class&gt; &lt;/listener&gt; &lt;servlet&gt; &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt; &lt;servlet-class&gt;javax.faces.webapp.FacesServlet&lt;/servlet-class&gt; &lt;load-on-startup&gt;1&lt;/load-on-startup&gt; &lt;/servlet&gt; &lt;servlet-mapping&gt; &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt; &lt;url-pattern&gt;*.faces&lt;/url-pattern&gt; &lt;/servlet-mapping&gt; &lt;servlet-mapping&gt; &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt; &lt;url-pattern&gt;*.xhtml&lt;/url-pattern&gt; &lt;/servlet-mapping&gt; &lt;context-param&gt; &lt;param-name&gt;facelets.LIBRARIES&lt;/param-name&gt; &lt;param-value&gt;/WEB-INF/tags/synaptic.taglib.xml&lt;/param-value&gt; &lt;/context-param&gt; &lt;filter&gt; &lt;filter-name&gt;openSessionInViewFilter&lt;/filter-name&gt; &lt;filter-class&gt;org.springframework.orm.hibernate3.support.OpenSessionInViewFilter&lt;/filter-class&gt; &lt;init-param&gt; &lt;param-name&gt;flushMode&lt;/param-name&gt; &lt;param-value&gt;AUTO&lt;/param-value&gt; &lt;/init-param&gt; &lt;/filter&gt; &lt;context-param&gt; &lt;param-name&gt;javax.faces.DEFAULT_SUFFIX&lt;/param-name&gt; &lt;param-value&gt;.xhtml&lt;/param-value&gt; &lt;/context-param&gt; &lt;context-param&gt; &lt;param-name&gt;javax.faces.PROJECT_STAGE&lt;/param-name&gt; &lt;param-value&gt;Production&lt;/param-value&gt; &lt;/context-param&gt; &lt;context-param&gt; &lt;param-name&gt;facelets.SKIP_COMMENTS&lt;/param-name&gt; &lt;param-value&gt;true&lt;/param-value&gt; &lt;/context-param&gt; &lt;servlet&gt; &lt;servlet-name&gt;Resources Servlet&lt;/servlet-name&gt; &lt;servlet-class&gt;org.springframework.js.resource.ResourceServlet&lt;/servlet-class&gt; &lt;load-on-startup&gt;1&lt;/load-on-startup&gt; &lt;/servlet&gt; &lt;servlet-mapping&gt; &lt;servlet-name&gt;Resources Servlet&lt;/servlet-name&gt; &lt;url-pattern&gt;/resources/*&lt;/url-pattern&gt; &lt;/servlet-mapping&gt; &lt;/web-app&gt; </code></pre> <p>Faces config</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;faces-config xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd" version="2.0"&gt; &lt;application&gt; &lt;el-resolver&gt;org.springframework.web.jsf.el.SpringBeanFacesELResolver&lt;/el-resolver&gt; &lt;/application&gt; &lt;/faces-config&gt; </code></pre> <p>other spring flow configuration</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:mvc="http://www.springframework.org/schema/mvc" 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-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/webflow-config http://www.springframework.org/schema/webflow-config/spring-webflow-config-2.3.xsd http://www.springframework.org/schema/faces http://www.springframework.org/schema/faces/spring-faces-2.2.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd"&gt; &lt;faces:resources /&gt; &lt;context:annotation-config /&gt; &lt;context:component-scan base-package="com.synaptic"/&gt; &lt;bean class="org.springframework.faces.webflow.JsfFlowHandlerAdapter"&gt; &lt;property name="flowExecutor" ref="flowExecutor" /&gt; &lt;/bean&gt; &lt;bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"&gt; &lt;property name="mappings"&gt; &lt;value&gt; /flows/*=flowController &lt;/value&gt; &lt;/property&gt; &lt;property name="defaultHandler"&gt; &lt;bean class="org.springframework.web.servlet.mvc.UrlFilenameViewController"/&gt; &lt;/property&gt; &lt;/bean&gt; &lt;bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter"&gt; &lt;/bean&gt; &lt;bean id="faceletsViewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver"&gt; &lt;property name="viewClass" value="org.springframework.faces.mvc.JsfView"/&gt; &lt;property name="prefix" value="/WEB-INF/"/&gt; &lt;property name="suffix" value=".xhtml"/&gt; &lt;/bean&gt; &lt;bean id="flowController" class="org.springframework.webflow.mvc.servlet.FlowController"&gt; &lt;property name="flowExecutor" ref="flowExecutor"/&gt; &lt;/bean&gt; &lt;webflow:flow-executor id="flowExecutor" flow-registry="flowRegistry"&gt; &lt;webflow:flow-execution-listeners&gt; &lt;webflow:listener ref="flowFacesContextLifecycleListener" /&gt; &lt;!-- &lt;webflow:listener ref="facesContextListener"/&gt;--&gt; &lt;/webflow:flow-execution-listeners&gt; &lt;/webflow:flow-executor&gt; &lt;bean id="flowFacesContextLifecycleListener" class="org.springframework.faces.webflow.FlowFacesContextLifecycleListener" /&gt; &lt;webflow:flow-registry id="flowRegistry" flow-builder-services="facesFlowBuilderServices"&gt; &lt;webflow:flow-location-pattern value="/WEB-INF/flows/**/*.xml"/&gt; &lt;/webflow:flow-registry&gt; &lt;bean id="conversionService" class="org.springframework.faces.model.converter.FacesConversionService"/&gt; &lt;bean id="expressionParser" class="org.springframework.webflow.expression.el.WebFlowELExpressionParser"&gt; &lt;constructor-arg&gt; &lt;bean class="org.jboss.el.ExpressionFactoryImpl"/&gt; &lt;/constructor-arg&gt; &lt;property name="conversionService" ref="conversionService"/&gt; &lt;/bean&gt; &lt;faces:flow-builder-services id="facesFlowBuilderServices" expression-parser="expressionParser" conversion-service="conversionService"/&gt; &lt;/beans&gt; </code></pre> <p>Please if you see anything wrong or you have any idea help me, this issue is bugging me from days. Thank you!</p> <p><strong>EDIT #1</strong></p> <p>I add the code for the backing bean and the webflow code where I declare it:</p> <pre><code>public class TestBean implements Serializable { private String test = "xxx"; public String getTest() { return test; } public void setTest(String test) { this.test = test; } } &lt;view-state id="home" view="../views/adminHome.xhtml"&gt; &lt;on-entry&gt; &lt;evaluate expression="textManager.getTest()" result="viewScope.test"/&gt; &lt;/on-entry&gt; &lt;/view-state&gt; </code></pre> <p>Now this of testBean is just the simplest test case I can make that doesn't work, the main problem I have is that no ajax call works, for example pagination for tables, adding or removing or modifying an element of a datatable, tabView etc.</p> <p>I generally create the beans for the page and put them in the viewScope or flowScope, this also for lists of data coming from the database. I tryed also having the bean managed by Spring with scope Session but it doesn't work neither. Another note is that the default value display on the page correctly.</p> <p><strong>EDIT #2</strong></p> <p>using firebug and the eclipse debug i see this:</p> <p>Initial value of TestBean.test is "xxx", I change to aaa and press submit.</p> <p>An ajax post request is sent to the server:</p> <pre><code>javax.faces.ViewState e2s1 javax.faces.partial.ajax true javax.faces.partial.execu... @all javax.faces.partial.rende... testAjax testAjax:display javax.faces.source testAjax:testButton testAjax testAjax testAjax:test aaa testAjax:testButton testAjax:testButton </code></pre> <p>When the POST is sent I firt debug a call to TestBean.getTest() and then a call to TestBean.setTest("aaa") that has the correct value.</p> <p>At this point I would expect another call to TestBean.getTest() when the response is built but the call does not happens and the response does not contain the correct value but the old value "xxx".</p> <p>If now I refresh the page the getter is called and the new value "aaa" is displayed correctly.</p> <p><strong>EDIT #3</strong></p> <p>I still can sort this out. I noticed now with firebug an unexpected behaviour:</p> <p>when I click the command button 2 requests are sent to the server, a POST and a GET.</p> <p>The POST is sent first and return an error "302 Moved Temporarily", then the GET start and return a response without the updated data. Anyone knows what error 302 means in this case and what could be the cause?</p> <p>Debugging in the same way the primefaces demo only a POST request is fired that return no errors</p> <p>Thank you</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload