gpt4 book ai didi

jsf - ICEfaces/Seam文件上传组件未上传文件

转载 作者:行者123 更新时间:2023-12-02 06:02:38 28 4
gpt4 key购买 nike

更新资料

我目前正在ICEfaces论坛上解决我的问题-不幸的是,所提供的选项现在都没有导致解决方案,但是它们的确为我提供了对整个JSF主题的更多见解(为此,信贷给BalusC,因为经常:-))。

如果问题最终得到解决,以帮助其他可能遇到的问题,我将尝试使该线程保持最新状态并发布答案。

到目前为止,我的发现是:


需要禁用Seam Multipart Filter,因为它会阻止fileEntry-component正常工作
我的应用程序中仍然存在一些讨厌的库问题,导致(静默的)ClassLoading问题:存在2个icefaces-ace.jar文件,一个在EAR / lib中,一个在EAR / WAR / WEB-INF / lib中。从WEB-INF中删除一个导致组件什么都不做,从EAR / lib中删除一个导致我的应用程序不再部署。


当将所有前端jar(icefaces.jar,icefaces-ace.jar,icefaces-compat.jar)从EAR / lib移动到WEB-INF / lib时,我的EAR的jar部分收到各种ClassNotFoundExceptions:ValueChangeEvent,RowSelectorEvent等找不到。(也就是说,所有这些事件都从视图进入后端)。例:

12:12:42,145 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-16) MSC00001: 
Failed to start service jboss.deployment.subunit."myApp.ear"."myApp.jar".POST_MODULE:
org.jboss.msc.service.StartException in service
jboss.deployment.subunit."myApp.ear"."myApp.jar".POST_MODULE: Failed to process phase
POST_MODULE of subdeployment "myApp.jar" of deployment "myApp.ear"
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:119) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) [rt.jar:1.7.0_06]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) [rt.jar:1.7.0_06]
at java.lang.Thread.run(Thread.java:722) [rt.jar:1.7.0_06]

Caused by: java.lang.RuntimeException: Error getting reflective information for class my.company.myApp.myExampleBean with ClassLoader ModuleClassLoader for Module "deployment.myApp.ear.myApp.jar:main" from Service Module Loader
at org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex.getClassIndex(DeploymentReflectionIndex.java:70) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.as.ee.metadata.MethodAnnotationAggregator.runtimeAnnotationInformation(MethodAnnotationAggregator.java:58)
at org.jboss.as.ee.component.deployers.InterceptorAnnotationProcessor.handleAnnotations(InterceptorAnnotationProcessor.java:85)
at org.jboss.as.ee.component.deployers.InterceptorAnnotationProcessor.processComponentConfig(InterceptorAnnotationProcessor.java:70)
at org.jboss.as.ee.component.deployers.InterceptorAnnotationProcessor.deploy(InterceptorAnnotationProcessor.java:55)
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:113) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
... 5 more

Caused by: java.lang.NoClassDefFoundError: com/icesoft/faces/component/ext/RowSelectorEvent
at java.lang.Class.getDeclaredMethods0(Native Method) [rt.jar:1.7.0_06]
at java.lang.Class.privateGetDeclaredMethods(Class.java:2442) [rt.jar:1.7.0_06]
at java.lang.Class.getDeclaredMethods(Class.java:1808) [rt.jar:1.7.0_06]
at org.jboss.as.server.deployment.reflect.ClassReflectionIndex.<init>(ClassReflectionIndex.java:65) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex.getClassIndex(DeploymentReflectionIndex.java:66) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
... 10 more
Caused by: java.lang.ClassNotFoundException: com.icesoft.faces.component.ext.RowSelectorEvent from [Module "deployment.myApp.ear.myApp.jar:main" from Service Module Loader]
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190) [jboss-modules.jar:1.1.1.GA]
at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:468) [jboss-modules.jar:1.1.1.GA]
at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:456) [jboss-modules.jar:1.1.1.GA]
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398) [jboss-modules.jar:1.1.1.GA]
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:120) [jboss-modules.jar:1.1.1.GA]
... 15 more


整个故事

我正在使用Seam 2.3和ICEfaces 3.1.0开发Web应用程序。这意味着正在使用JSF2。

我的应用程序作为EAR部署在JBoss AS 7.1.0上,包含用于应用程序逻辑的JAR和用于所有与视图相关的东西的WAR。

我最近从Seam 2.1.2迁移到Seam 2.3,从ICEfaces 1.8.2迁移到3.1.0。这一步很可怕,但是现在一切正常,撇开了一些小问题。

唯一的大问题是,当我使用组件上载文件时,无论使用Seam组件还是ICEfaces组件-在Seam中,上载的文件始终为null,而在ICEfaces中,永远不会调用我的fileEntryListener-Method。

使用ICEfaces:

在2.X之前的ICEfaces版本中,存在 ice:inputFile组件,该组件已由2.X删除并由 ace:fileEntry代替。

InputFile运作良好,但FileEntry却无法运作。我的问题与中所述完全相同
JSF : Issues with File Upload using Icefaces component-从不调用fileEntryListener。我在那里尝试了建议(在周围的表单上使用enctype =“ multipart / form-data”,在表单上使用 h:commandButton提交),但是没有用。提供的唯一解决方案是切换到Richfaces,这对我来说不是一个选择。

带缝:

很高兴,Seam拥有自己的内置fileUpload-component, s:fileUpload

它也不起作用,但至少向我展示了一个可以进一步查找的地方。在调试该组件的doDecode-Methods时,我发现我的请求不是MultipartRequest。疯了!用于上传文件的所有表单都将Enctype声明为multipart / form-data。我认为,当我尝试使用ICEfaces组件时,也会发生同样的情况-没有多部分请求,因此不会调用任何侦听器。

所以:我该如何工作?没有请求作为MultipartRequest出现的意义是什么?我会错过web / components.xml中的某些内容吗?

web.xml:

<web-app 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/xmlns/
javaee/web-app_3_0.xsd"
version="3.0">
<listener>
<listener-class>org.jboss.seam.servlet.SeamListener</listener-class>
</listener>

<filter>
<filter-name>Seam Filter</filter-name>
<filter-class>org.jboss.seam.servlet.SeamFilter</filter-class>
</filter>

<filter-mapping>
<filter-name>Seam Filter</filter-name>
<url-pattern>*.seam</url-pattern>
</filter-mapping>

<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
</servlet>

<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>/icefaces/*</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.seam</url-pattern>
</servlet-mapping>

<servlet>
<servlet-name>Seam Resource Servlet</servlet-name>
<servlet-class>org.jboss.seam.servlet.SeamResourceServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>Seam Resource Servlet</servlet-name>
<url-pattern>/seam/resource/*</url-pattern>
</servlet-mapping>

<servlet>
<servlet-name>Resource Servlet</servlet-name>
<servlet-class>com.icesoft.faces.webapp.CompatResourceServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>Resource Servlet</servlet-name>
<url-pattern>/xmlhttp/*</url-pattern>
</servlet-mapping>

<session-config>
<session-timeout>60</session-timeout>
</session-config>

<context-param>
<param-name>javax.faces.FACELETS_SKIP_COMMENTS</param-name>
<param-value>true</param-value>
</context-param>

<context-param>
<param-name>facelets.DEVELOPMENT</param-name>
<param-value>true</param-value>
</context-param>

<context-param>
<param-name>com.icesoft.faces.actionURLSuffix</param-name>
<param-value>.seam</param-value>
</context-param>

<context-param>
<param-name>javax.faces.FACELETS_REFRESH_PERIOD</param-name>
<param-value>-1</param-value>
</context-param>

<context-param>
<param-name>com.icesoft.faces.synchronousUpdate</param-name>
<param-value>false</param-value>
</context-param>

<context-param>
<param-name>com.icesoft.faces.doJSFStateManagement</param-name>
<param-value>true</param-value>
</context-param>

<context-param>
<param-name>com.icesoft.faces.standardRequestScope</param-name>
<param-value>true</param-value>
</context-param>

<context-param>
<param-name>com.icesoft.faces.uploadDirectory</param-name>
<param-value>upload</param-value>
</context-param>

<context-param>
<param-name>javax.faces.VALIDATE_EMPTY_FIELDS</param-name>
<param-value>false</param-value>
</context-param>


components.xml(省略了Seam 2.3名称空间声明

<core:init jndi-pattern="java:app/myApp/#{ejbName}" debug="false"
distributable="false" />


<component class="org.jboss.seam.transaction.EjbSynchronizations"
jndi-name="java:app/jboss-seam/EjbSynchronizations" />

<core:manager concurrent-request-timeout="500"
conversation-timeout="90000000" conversation-id-parameter="cid"
parent-conversation-id-parameter="pid" />

<web:hot-deploy-filter url-pattern="*.seam" />

<web:multipart-filter create-temp-files="true"
max-request-size="1000000"
url-pattern="/*"/>


<persistence:managed-persistence-context
name="entityManager" auto-create="true" persistence-unit-jndi-name="java:/myAppEntityManagerFactory" />

<security:identity authenticate-method="#{authenticator.authenticate}" />
<security:remember-me enabled="true" />

<security:rule-based-permission-resolver
security-rules="#{securityRules}" />

<drools:rule-base name="securityRules">
<drools:rule-files>
<value>/security.drl</value>
</drools:rule-files>
</drools:rule-base>

<async:quartz-dispatcher />

<factory name="sessionTimeoutSeconds" scope="SESSION"
value="#{facesContext.externalContext.getSession(true).getMaxInactiveInterval()}" />

<factory name="basePath"
value="#{facesContext.externalContext.request.scheme}://#{facesContext.externalContext.request.serverName}:
#{facesContext.externalContext.request.serverPort}#{facesContext.externalContext.request.contextPath}" />

<factory name="contextPath"
value="#{facesContext.externalContext.request.contextPath}" />


示例JSF源(接缝)

<h:form enctype="multipart/form-data">
<s:decorate>
<s:fileUpload data="#{uploadBean.fileData}"
contentType="#{uploadBean.contentType}"
fileName="#{uploadBean.fileName}" />
<h:commandButton value="Upload File" type="submit" />
</s:decorate>
</h:form>


JSF源示例(ICEfaces)

<h:form enctype="multipart/form-data">
<ace:fileEntry id="file-entry" relativePath="/files/"
fileEntryListener="#{uploadBean.uploadFile}"
useSessionSubdir="true" />

<h:commandButton id="submit" type="submit" value="Send File" />
</h:form>


JSF映射到一个Seam组件,其中fileData的字节[]和fileName和contentType的字符串为String。 fileEntryListener映射到一个以 FileEntryEvent作为输入的void方法。



更新资料

为了让您了解最新信息,到目前为止我的发现:

考虑到BalusC的回答,我更深入地研究了过滤器内容。我已经尝试添加/删除Seam Multipart Filter,但是现在我发现,当我将其添加到components.xml中并通过显式禁用它时


<web:multipart-filter disabled="true"/>


ICEfaces至少发生了一些事情:FileEntryPhaseListener引发了异常,以前从未发生过:

09:26:19,124 SEVERE [javax.enterprise.resource.webcontainer.jsf.context] (http-localhost-127.0.0.1-8080-2) JSF1071: javax.faces.event.AbortProcessingException erfasst während beforePhase()-Verarbeitung von RENDER_RESPONSE 6 : UIComponent-ClientId=, Message=/template/patient/documents/instantiation/documentInsertPopup.xhtml @135,98 fileEntryListener="#{uploadBean.fileUploadListener}": Method not found: my.company.package.stuff.UploadBean@313d62f1.fileUploadListener(org.icefaces.ace.component.fileentry.FileEntryEvent)09:26:19,126 SEVERE [javax.enterprise.resource.webcontainer.jsf.context] (http-localhost-127.0.0.1-8080-2) /template/upload.xhtml @135,98 fileEntryListener="#{uploadBean.fileUploadListener}": Method not found: my.company.package.stuff.UploadBean@313d62f1.fileUploadListener(org.icefaces.ace.component.fileentry.FileEntryEvent): javax.faces.event.AbortProcessingException: /upload.xhtml @135,98 fileEntryListener="#{uploadBean.fileUploadListener}": Method not found: my.company.package.stuff.UploadBean@313d62f1.fileUploadListener(org.icefaces.ace.component.fileentry.FileEntryEvent)    at org.icefaces.ace.component.fileentry.FileEntry.broadcast(FileEntry.java:350) [icefaces-ace.jar:]    at org.icefaces.ace.component.fileentry.FileEntryPhaseListener$1.visit(FileEntryPhaseListener.java:95) [icefaces-ace.jar:]    at com.sun.faces.component.visit.PartialVisitContext.invokeVisitCallback(PartialVisitContext.java:183) [javax.faces.jar:2.1.4-FCS]    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1612) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]    at javax.faces.component.UIForm.visitTree(UIForm.java:371) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]    at org.icefaces.ace.component.fileentry.FileEntryPhaseListener.beforePhase(FileEntryPhaseListener.java:100) [icefaces-ace.jar:]    at com.sun.faces.lifecycle.Phase.handleBeforePhase(Phase.java:228) [javax.faces.jar:2.1.4-FCS]    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:99) [javax.faces.jar:2.1.4-FCS]    at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139) [javax.faces.jar:2.1.4-FCS]    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.13.Final.jar:]    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]    at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83) [jboss-seam.jar:2.3.0.Final]    at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:60) [jboss-seam.jar:2.3.0.Final]    at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69) [jboss-seam.jar:2.3.0.Final]    at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64) [jboss-seam.jar:2.3.0.Final]    at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69) [jboss-seam.jar:2.3.0.Final]    at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45) [jboss-seam.jar:2.3.0.Final]    at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69) [jboss-seam.jar:2.3.0.Final]    at org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:40) [jboss-seam.jar:2.3.0.Final]    at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69) [jboss-seam.jar:2.3.0.Final]    at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158) [jboss-seam.jar:2.3.0.Final]    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.13.Final.jar:]    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.13.Final.jar:]    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.13.Final.jar:]    at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50) [jboss-as-jpa-7.1.1.Final.jar:7.1.1.Final]    at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.13.Final.jar:]    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.13.Final.jar:]    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.13.Final.jar:]    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.13.Final.jar:]    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.13.Final.jar:]    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671) [jbossweb-7.0.13.Final.jar:]    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) [jbossweb-7.0.13.Final.jar:]    at java.lang.Thread.run(Thread.java:722) [rt.jar:1.7.0_06]

At least this is something to look at. If I use the fileEntryListener like

fileEntryListener="#{uploadBean.fileUploadListener}"


如果使用以下方法,则会引发上述异常:

fileEntryListener="#{uploadBean.fileUploadListener()}"


它抱怨该方法需要参数,如果我像这样使用它:

fileEntryListener="#{uploadBean.fileUploadListener(null)}"


没有引发异常,但是由于事件为null,所以没有文件到达我的UploadBean。闻起来像图书馆的一些问题,但至少还有其他需要看的地方。

上载bean

这里发生的事情不多,只是:

@Stateful
@Name("uploadBean")
@Scope(ScopeType.SESSION)
@JndiName(value = "java:app/myApp.jar/UploadBean")
public class UploadBean implements IUploadBean
{
public void fileUploadListener(FileEntryEvent event)
{
System.out.println("listener called!");
}
}


侦听器也在bean的接口中声明。

最佳答案

首先介绍一些技术背景信息:在即将发布的JSF 2.2之前,JSF本身并不支持multipart/form-data请求。因此,提供文件上传组件的组件库必须自己提供一个自定义Filter。这应该正确解析multipart/form-data请求并将所有必需的常规数据存储在HTTP请求参数映射中,并将上载的文件存储为请求属性。这样,JSF可以继续以常规方式将request.getParameter()用作常规数据,并且组件库本身可以获取上载的文件作为请求属性。

对于Seam的<s:fileUpload>,您需要org.jboss.seam.web.MultipartFilter来执行multipart/form-data解析作业。我从未使用过Seam(也不使用ICEfaces),但是Google向我展示了您基本上在webapp的web.xml中需要此功能

<filter>
<filter-name>Seam Multipart Filter</filter-name>
<filter-class>org.jboss.seam.web.MultipartFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>Seam Multipart Filter</filter-name>
<url-pattern>*.seam</url-pattern>
</filter-mapping>


或在Seam components.xml中:

<web:multipart-filter url-pattern="*.seam" />


ICEfaces组件必须配置类似的过滤器。缺少ICEfaces 3.x文档(或者我的Google / icefaces.com的搜索技能很差),因此我无法对此进行详细介绍。

请记住,重要的是HTTP请求只能被解析一次(客户端仅发送一次,而不是多次发送),因此您不能在同一请求上同时使用两个 multipart/form-data解析器。在第一个请求之后插入的请求将获得一个空的请求正文,该请求正文无法解析为任何明智的内容。因此,如果您使用的是使用后一个过滤器的组件,那么模型中什么也不会得到。确保您并非偶然或通过实验配置两者。

关于jsf - ICEfaces/Seam文件上传组件未上传文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13008943/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com