PrimeFaces Ajax调用总是返回一个302状态代码,带有Spring安全性
我正在用Spring3.2.0、PrimeFaces 3.3.1、Mojarra 2.1.11和SpringSecurity 3.1.1创建一个项目 我的问题是,每当PrimeFaces触发ajax调用时,比如在表分页中,屏幕组件都不会刷新 编辑#4 无论何时调用ajax,服务器都会返回状态302,页面也会刷新 我认为问题与Spring security有关,以下是我的设置:PrimeFaces Ajax调用总是返回一个302状态代码,带有Spring安全性,spring,jsf,primefaces,http-status-code-302,Spring,Jsf,Primefaces,Http Status Code 302,我正在用Spring3.2.0、PrimeFaces 3.3.1、Mojarra 2.1.11和SpringSecurity 3.1.1创建一个项目 我的问题是,每当PrimeFaces触发ajax调用时,比如在表分页中,屏幕组件都不会刷新 编辑#4 无论何时调用ajax,服务器都会返回状态302,页面也会刷新 我认为问题与Spring security有关,以下是我的设置: <security:http entry-point-ref="authenticationEntry
<security:http entry-point-ref="authenticationEntryPoint" pattern="/spring/**">
<security:anonymous />
<security:http-basic />
<security:custom-filter position="FORM_LOGIN_FILTER" ref="authenticationProcessingFilter" />
<security:logout logout-url="/spring/logout" logout-success-url="/spring/login?logout=true" />
<security:intercept-url pattern="/spring/login" access="ROLE_ANONYMOUS,ROLE_USER,ROLE_ADMIN" />
<security:intercept-url pattern="/spring/logoutSuccess" access="ROLE_ANONYMOUS,ROLE_USER,ROLE_CLIENT" />
<security:intercept-url pattern="/spring/intro" access="ROLE_ANONYMOUS,ROLE_USER" />
<security:intercept-url pattern="/spring/flows/admin_main_flow/**" access="ROLE_ADMIN" />
<security:intercept-url pattern="/spring/flows/client_main_flow/**" access="ROLE_CLIENT" />
</security:http>
<security:http security="none" pattern="/javax.faces.resource/**" />
<security:http security="none" pattern="/ajax/**" />
<security:http security="none" pattern="/static/**" />
<security:http security="none" pattern="/resources/**" />
我担心这是一个配置问题,我按照基本说明做了一些修改,纠正了一些错误,下面是web.xml中一些不相关的部分
<?xml version = '1.0'?>
<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">
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/log4j.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring_context.xml</param-value>
</context-param>
<servlet>
<servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value></param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
<url-pattern>/spring/*</url-pattern>
</servlet-mapping>
<listener>
<listener-class>org.springframework.security.web.session.HttpSessionEventPublisher</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener </listener-class>
</listener>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.faces</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<context-param>
<param-name>facelets.LIBRARIES</param-name>
<param-value>/WEB-INF/tags/synaptic.taglib.xml</param-value>
</context-param>
<filter>
<filter-name>openSessionInViewFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
<init-param>
<param-name>flushMode</param-name>
<param-value>AUTO</param-value>
</init-param>
</filter>
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Production</param-value>
</context-param>
<context-param>
<param-name>facelets.SKIP_COMMENTS</param-name>
<param-value>true</param-value>
</context-param>
<servlet>
<servlet-name>Resources Servlet</servlet-name>
<servlet-class>org.springframework.js.resource.ResourceServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Resources Servlet</servlet-name>
<url-pattern>/resources/*</url-pattern>
</servlet-mapping>
</web-app>
发送POST后,我首先调试对TestBean.getTest()的调用,然后调用具有正确值的TestBean.setTest(“aaa”)
在这一点上,我希望在生成响应但未发生调用且响应不包含正确值但包含旧值“xxx”时再次调用TestBean.getTest()
如果现在我刷新页面,则调用getter并正确显示新值“aaa”
编辑#3
我仍然可以解决这个问题。我现在注意到firebug有一种意想不到的行为:
当我单击命令按钮时,会向服务器发送两个请求,一个POST和一个GET
首先发送POST并返回状态“302已临时移动”,然后启动并返回没有更新数据的响应。有人知道302状态在这种情况下意味着什么,原因是什么吗
以相同的方式调试primefaces demo,仅触发不返回状态302的POST请求
谢谢当您将JSF与Spring集成时,您的JSF托管bean将成为Spring bean。这就是为什么Spring包含自己的ELResolver实现,以便您可以从EL表达式中引用这些Springbean 不幸的是,Spring只支持@Request、@Session和@Application 幸运的是,与Spring集成的ViewScope的一个简单实现可以集成到您的应用程序中。PrimeFaces的首席开发人员Cagatay Civici撰写了一篇博客文章,展示了一个简单的ViewScope实现示例,该示例可以轻松集成到您的应用程序中
使用视图范围的托管bean,您的bean将有足够的持久性在ajax更新上动态呈现页面元素。当您将JSF与Spring集成时,您的JSF托管bean将成为Spring bean。这就是为什么Spring包含自己的ELResolver实现,以便您可以从EL表达式中引用这些Springbean 不幸的是,Spring只支持@Request、@Session和@Application 幸运的是,与Spring集成的ViewScope的一个简单实现可以集成到您的应用程序中。PrimeFaces的首席开发人员Cagatay Civici撰写了一篇博客文章,展示了一个简单的ViewScope实现示例,该示例可以轻松集成到您的应用程序中
使用视图范围为的托管bean,您的bean将有足够的持久性在ajax更新中动态呈现页面元素。您需要向流执行器添加一个参数,以禁用重定向到相同状态。配置变为:
<webflow:flow-executor id="flowExecutor" flow-registry="flowRegistry">
<webflow:flow-execution-listeners>
<webflow:listener ref="flowExecutionListener" />
<webflow:listener ref="facesContextListener"/>
<!-- <webflow:listener ref="flowFacesContextLifecycleListener" />-->
</webflow:flow-execution-listeners>
<webflow:flow-execution-attributes>
<webflow:redirect-in-same-state value="false"/>
</webflow:flow-execution-attributes>
</webflow:flow-executor>
这将防止流执行器在发送ajax请求后完全刷新页面 您需要向流执行器添加一个参数,以禁用重定向到相同状态。配置变为:
<webflow:flow-executor id="flowExecutor" flow-registry="flowRegistry">
<webflow:flow-execution-listeners>
<webflow:listener ref="flowExecutionListener" />
<webflow:listener ref="facesContextListener"/>
<!-- <webflow:listener ref="flowFacesContextLifecycleListener" />-->
</webflow:flow-execution-listeners>
<webflow:flow-execution-attributes>
<webflow:redirect-in-same-state value="false"/>
</webflow:flow-execution-attributes>
</webflow:flow-executor>
<webflow:flow-execution-attributes>
<webflow:redirect-in-same-state value="false"/>
</webflow:flow-execution-attributes>
这将防止流执行器在发送ajax请求后完全刷新页面
<webflow:flow-execution-attributes>
<webflow:redirect-in-same-state value="false"/>
</webflow:flow-execution-attributes>
解决了我的问题。
我使用org.springframework.web.servlet.handler.simplerlhandlermapping进行JSF 1.x RichFaces 3.x的导航。
当移到JSF 2.x和PrimeFaces/RichFaces 4时,数据表的ajax方面不起作用(例如,显示但不排序)
添加此xml的工作非常神奇(因为我不知道自己在做什么,所以需要这样做)
解决了我的问题。
我使用org.springframework.web.servlet.handler.simplerlhandlermapping进行JSF 1.x RichFaces 3.x的导航。
当移到JSF 2.x和PrimeFaces/RichFaces 4时,数据表的ajax方面不起作用(例如,显示但不排序)
添加此xml的工作非常神奇(因为我不知道我在做什么,所以需要这样做)您在TestBean中使用哪个作用域?我尝试在viewScope中pu该bean,并将其定义为Springbean:在这两种情况下,它都不起作用。请发布支持bean的内容。我怀疑这是由于你的CommandButton的作用域和缺少ID造成的。谢谢你的回复,我编辑了这篇文章。我尝试为命令按钮分配id,但没有成功。我尝试了所有可能的作用域组合,其中一个由web流控制(FlashScope、viewScope、FlowScope),另一个由spring控制(SessionScope、ApplicationScope)您在TestBean中使用哪个作用域?我尝试在viewScope中pu bean,并将其定义为Springbean:在这两种情况下,它都不起作用。请发布支持bean的内容。我怀疑这是由于你的CommandButton的作用域和缺少ID造成的。谢谢你的回复,我编辑了这篇文章。我尝试为命令按钮分配id,但没有成功。我尝试了所有可能的作用域组合,其中一个由web流控制(FlashScope、viewScope、FlowScope),另一个由spring控制(SessionScope、ApplicationScope)。谢谢你的回答,我现在编辑了这篇文章,提供了更多信息。我正在尝试使用SpringWebFL
public class TestBean implements Serializable {
private String test = "xxx";
public String getTest() {
return test;
}
public void setTest(String test) {
this.test = test;
}
}
<view-state id="home" view="../views/adminHome.xhtml">
<on-entry>
<evaluate expression="textManager.getTest()" result="viewScope.test"/>
</on-entry>
</view-state>
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
<webflow:flow-executor id="flowExecutor" flow-registry="flowRegistry">
<webflow:flow-execution-listeners>
<webflow:listener ref="flowExecutionListener" />
<webflow:listener ref="facesContextListener"/>
<!-- <webflow:listener ref="flowFacesContextLifecycleListener" />-->
</webflow:flow-execution-listeners>
<webflow:flow-execution-attributes>
<webflow:redirect-in-same-state value="false"/>
</webflow:flow-execution-attributes>
</webflow:flow-executor>
<webflow:flow-execution-attributes>
<webflow:redirect-in-same-state value="false"/>
</webflow:flow-execution-attributes>