【发布时间】:2015-07-22 14:20:38
【问题描述】:
我正在使用 Primefaces 5.2 和 Spring-security 4.0.1 并使用 NetBeans IDE(所以 GlassFish 4.1),我尝试制作仪表板并动态添加 wiget。
为了将它部署在服务器上,感谢 Spring Security,我添加了一些安全性。目前,它是非常基本的,使用身份验证和默认过滤器。
因此,当我启动它(项目)时,我被正确重定向到默认登录页面(我已将 Spring 配置为使用 8181 端口,该端口用于 GlassFish https 默认端口),并且我正常登录.
但是,从现在开始,当我将一个小部件从库区域拖放到仪表板(实际上是字段集内的输出面板内的数据网格)区域时,什么也没有发生。有和往常一样的动画(它消失了,没有回到图书馆区),但仪表板上没有小部件,即使我刷新页面。
如果我在 web.xml 上注释 filter 和 filter-mapping 部分,当然不会重定向到登录页面和 https 协议,但是 widget drop 可以正常工作。
也可能是Ajax和Spring之间的问题(p:ajax里面的函数没有被调用)。有人有办法解决这个问题吗?
这里有不同的代码部分(可能就足够了,如果缺少某些内容,请告诉我)
web.xml 文件
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<context-param>
<param-name>primefaces.THEME</param-name>
<param-value>#{themeSwitcherBean.theme}</param-value>
</context-param>
<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>*.jsf</url-pattern>
</servlet-mapping>
<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>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>dashboard.xhtml</welcome-file>
</welcome-file-list>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<!-- Loads Spring Security config file -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/applicationContext-security.xml
</param-value>
</context-param>
<!-- Spring Security (Disable drop????) -->
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
applicationContext-security.xml
<?xml version="1.0" encoding="UTF-8"?>
<!-- - Sample namespace-based configuration - -->
<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-4.0.xsd">
<http auto-config="true" use-expressions="true">
<intercept-url pattern="/**" access="authenticated" requires-channel="https"/>
<intercept-url pattern="/resources/css" access="permitAll"/>
<!-- Page level Spring Security : Enable Primefaces -->
<intercept-url pattern="/javax.faces.resource/**" access="permitAll"/>
<!-- Default Configuration: Https port for Glassfish is 8181 and not 8443 like Tomcat (http:8080, administration:4848-->
<port-mappings>
<port-mapping http="8080" https="8181"/>
</port-mappings>
<form-login />
<logout />
<remember-me />
<!-- Uncomment to enable X509 client authentication support <x509 /> -->
<!-- Uncomment to limit the number of sessions a user can have -->
<session-management>
<concurrency-control max-sessions="100"
error-if-maximum-exceeded="true" />
</session-management>
</http>
<authentication-manager>
<authentication-provider>
<password-encoder hash="md5" />
<user-service>
<!-- Some users -->
</user-service>
</authentication-provider>
</authentication-manager>
</beans:beans>
我的 xhtml 页面中的可放置标签
<p:droppable id ="d1" for="selectedWidgets" tolerance="touch" activeStyleClass="ui-state-highlight" datasource=":#{p:component('groupWidgets')}">
<p:ajax listener="#{widgetsTableBean.onDrop}" update="dropArea"/>
</p:droppable>
(selectedWidgets是仪表板的fieldset,dropArea是outputPanel)
p:ajax 的函数调用
public void onDrop(DragDropEvent ddEvent) {
Widget widget = ((Widget) ddEvent.getData());
this.selectedWidget = widget;
droppedWidgets.add(this.selectedWidget);
/*Test*/
System.out.println("drop: ");
for (int i = 0; i < droppedWidgets.size(); i++) {
System.out.println(droppedWidgets.get(i).getId());
}
}
我希望我已经说清楚了,并提前感谢您的回答
【问题讨论】:
-
你能详细说明你在说什么这也可能是Ajax和Spring之间的问题。 Ajax 对 Spring 来说可能是个问题吗?
-
我真的不知道,我只是猜想。我可以拖动我的小部件,正如您在 onDrop 函数中看到的那样,我使用 System.out.println 但是当我将它放到 DropArea 中时,Netbeans 的日志中没有它。所以我假设 Ajaxlistener 没有完成这项工作......正如我所说,当我评论过滤器时,它可以工作。所以它可能与弹簧或其配置有关。但如果你有其他理论,我会仔细阅读
-
首先在搜索引擎中搜索有关 ajax、jsf 和 web 的基本调试知识。 '不起作用'是模糊地能够提供帮助。
-
感谢您的回答,但如果我在这里发帖,那是因为我还没有找到解决该问题的解决方案/方法。 “它不起作用”是我唯一能说的,没有抛出异常或任何东西。就像我之前说的,我唯一确定的是,如果过滤器在这里,函数 onDrop 不会被调用。我和你一样对这个问题和缺乏信息感到厌烦......
-
未调用可能意味着没有发生 ajax 事件,没有通过网络传输任何内容,传输了某些内容但发生了仅在浏览器网络选项卡中可见的意外错误。你可以而且应该发现很多很多东西。这是基本的调试
标签: ajax spring security primefaces actionlistener