JSF:使用Icefaces组件进行文件上传的问题

时间:2012-04-05 15:15:05

标签: java jsf file-upload jsf-2 icefaces

我正在尝试让FileUpload功能使用Icefaces ace:fileEntry,但未调用服务器上的fileUploadListener,这里是代码:

xhtml篇:

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ace="http://www.icefaces.org/icefaces/components"
      xmlns:ice-cc="http://www.icesoft.com/icefaces-composite-comps"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ice="http://www.icesoft.com/icefaces/component">
<h:head>
    <link rel="stylesheet" type="text/css" href="/xmlhttp/css/rime/rime.css"/>
</h:head>
<h:body>
    <h:form enctype="multipart/form-data">
        <ace:fileEntry id="fileEntryComp"
                       label="File Entry"
                       relativePath="uploaded"
                       fileEntryListener="#{fileUpload.uploadFile}"/>
        <h:commandButton value="Upload File"/>
    </h:form>
</h:body>
</html>

java piece

public void uploadFile(FileEntryEvent event)
    {
        FileEntry fileEntry = (FileEntry) event.getSource();
        FileEntryResults results = fileEntry.getResults();
        for (FileEntryResults.FileInfo fileInfo : results.getFiles())
        {
            if (fileInfo.isSaved())
            {
                log.debug("########### FILE IS SAVED ########");
            }
        }
    }

日志信息:

    FINE  lifecycle        - Entering RestoreViewPhase
FINE  lifecycle        - New request: creating a view for /trade_entry/UploadBlotter.xhtml
FINE  application      - URL pattern of the FacesServlet executing the current request .jsp
FINE  application      - URL pattern of the FacesServlet executing the current request .jsp
FINE  application      - Created component with component type of 'javax.faces.ViewRoot'
FINE  application      - Created new view for /trade_entry/UploadBlotter.xhtml
FINE  application      - RenderKitId for this view as determined by calculateRenderKitId HTML_BASIC
FINE  lifecycle        - Exiting RestoreViewPhase
FINE  timing           -  [TIMING] - [2ms] : Execution time for phase (including any PhaseListeners) -> RESTORE_VIEW 1
FINE  lifecycle        - render(com.sun.faces.context.FacesContextImpl@1dc6429)
FINE  lifecycle        - Entering RenderResponsePhase
FINE  lifecycle        - About to render view /trade_entry/UploadBlotter.xhtml
FINE  application      - Building View: /trade_entry/UploadBlotter.xhtml
FINE  application      - Created component with component type of 'javax.faces.Output'
FINE  component        - /trade_entry/UploadBlotter.xhtml @7,9 <h:head> Component[-1351329185_508ba5ae] Created: javax
.faces.component.UIOutput
FINE  application      - Created component with component type of 'javax.faces.Output'
FINE  component        - /trade_entry/UploadBlotter.xhtml @10,9 <h:body> Component[-1351329185_508ba588] Created: java
x.faces.component.UIOutput
FINE  application      - Created component with component type of 'javax.faces.HtmlForm'
FINE  component        - /trade_entry/UploadBlotter.xhtml @11,13 <h:form> Component[-1351329185_508ba5e2] Created: jav
ax.faces.component.html.HtmlForm
FINE  application      - Created component with component type of 'org.icefaces.ace.component.FileEntry'
FINE  application      - Created component with component type of 'javax.faces.Output'
FINE  application      - Created component with component type of 'javax.faces.ComponentResourceContainer'
FINE  application      - Created component with component type of 'javax.faces.Output'
FINE  application      - Created component with component type of 'javax.faces.Output'
FINE  component        - /trade_entry/UploadBlotter.xhtml @15,70 <ace:fileEntry> Component[-1351329185_508ba5fc] Creat
ed: org.icefaces.ace.component.fileentry.FileEntry
FINE  application      - Created component with component type of 'javax.faces.HtmlCommandButton'
FINE  component        - /trade_entry/UploadBlotter.xhtml @16,47 <h:commandButton> Component[-1351329185_508ba5c9] Cre
ated: javax.faces.component.html.HtmlCommandButton
FINE  application      - Created component with component type of 'javax.faces.ComponentResourceContainer'
FINE  component        - No renderer-type for component j_id1
FINE  component        - No renderer-type for component javax_faces_location_BODY
FINE  application      - Rendering View: /trade_entry/UploadBlotter.xhtml
FINE  component        - No renderer-type for component javax_faces_location_HEAD
FINE  application      - URL pattern of the FacesServlet executing the current request .jsp
FINE  application      - URL pattern of the FacesServlet executing the current request .jsp
FINE  application      - URL pattern of the FacesServlet executing the current request .jsp
FINE  application      - URL pattern of the FacesServlet executing the current request .jsp
FINE  application      - URL pattern of the FacesServlet executing the current request .jsp
FINE  application      - URL pattern of the FacesServlet executing the current request .jsp
FINE  application      - URL pattern of the FacesServlet executing the current request .jsp
FINE  application      - URL pattern of the FacesServlet executing the current request .jsp
FINE  application      - URL pattern of the FacesServlet executing the current request .jsp
FINE  application      - URL pattern of the FacesServlet executing the current request .jsp
FINE  component        - No renderer-type for component _captureFileOnsubmit
FINE  application      - Begin writing marker for viewId /trade_entry/UploadBlotter.xhtml
FINE  application      - End writing marker for viewId /trade_entry/UploadBlotter.xhtml
FINE  application      - URL pattern of the FacesServlet executing the current request .jsp
FINE  application      - URL pattern of the FacesServlet executing the current request .jsp
FINE  application      - Begin writing marker for viewId /trade_entry/UploadBlotter.xhtml
FINE  application      - End writing marker for viewId /trade_entry/UploadBlotter.xhtml
FINE  lifecycle        - Exiting RenderResponsePhase

现在,在当前状态下,我可以打开文件系统导航弹出窗口,我可以选择文件但是fileUploadListener应该被点击但是现在它没有,我也能够得到一些我设置的数据在服务器端,所以服务器旅行只有问题我有fileUploadListener未命中,有任何建议吗?

更新 我仍然在寻找答案,因为我无法将文件成功上传到服务器。

更新2 现在我得到Content is not allowed in prolog异常,不确定究竟是什么意思,这里是stacktrace:

    ERROR [Faces Servlet]  - Servlet.service() for servlet Faces Servlet threw exception: javax.faces.view.facelets.Facele
tException: Error Parsing /trade_entry/UploadBlotter.xhtml: Error Traced[line: 2] Content is not allowed in prolog.
        at com.sun.faces.facelets.compiler.SAXCompiler.doCompile(SAXCompiler.java:417) [:2.1.7-SNAPSHOT]
        at com.sun.faces.facelets.compiler.SAXCompiler.doMetadataCompile(SAXCompiler.java:400) [:2.1.7-SNAPSHOT]
        at com.sun.faces.facelets.compiler.Compiler.metadataCompile(Compiler.java:130) [:2.1.7-SNAPSHOT]
        at com.sun.faces.facelets.impl.DefaultFaceletFactory.createMetadataFacelet(DefaultFaceletFactory.java:327) [:2.1.7-SNAPSHOT]
        at com.sun.faces.facelets.impl.DefaultFaceletFactory.access$200(DefaultFaceletFactory.java:93) [:2.1.7-SNAPSHOT]
        at com.sun.faces.facelets.impl.DefaultFaceletFactory$2.newInstance(DefaultFaceletFactory.java:166) [:2.1.7-SNAPSHOT]
        at com.sun.faces.facelets.impl.DefaultFaceletFactory$2.newInstance(DefaultFaceletFactory.java:164) [:2.1.7-SNAPSHOT]
        at com.sun.faces.facelets.impl.DefaultFaceletCache$2.newInstance(DefaultFaceletCache.java:94) [:2.1.7-SNAPSHOT]
        at com.sun.faces.facelets.impl.DefaultFaceletCache$2.newInstance(DefaultFaceletCache.java:89) [:2.1.7-SNAPSHOT]
        at com.sun.faces.util.ExpiringConcurrentCache$1.call(ExpiringConcurrentCache.java:99) [:2.1.7-SNAPSHOT]

4 个答案:

答案 0 :(得分:2)

我的组件周围没有<h:form>,代码中是否有任何内容? 我对icefaces没有任何经验,但我正在使用richFaces。 用

<rich:fileUpload immediate="true" id="fileUploadId" 
                        ajaxSingle="true" listHeight="70px" listWidth="500px"
                        uploadButtonClass="otherButton" styleClass="backgroundColorInput"
                        addButtonClass="otherButton"
                        fileUploadListener="#{paramActions.fileUploadListener}">
                        <a:support event="onuploadcomplete" reRender="paramsForm" />
                    </rich:fileUpload>

需要将其括在

<h:form id="paramsForm" enctype="multipart/form-data">
fileUpload需要

multipart / form-data enctype

答案 1 :(得分:1)

大多数时候未关闭的标签会导致该异常。检查xhtml,你可能会找到任何打开的标签。

例如:任何开放的div或span ..

答案 2 :(得分:0)

enctype="multipart/form-data"移除h:form,如果没有它,它应该可以正常工作。

答案 3 :(得分:0)

我在JBoss 7.1服务器上遇到了这个问题。我有一个EAR项目,一些EJB项目和几个WAR项目。当我遇到问题时,我在EAR库中部署了icefaces jar,但当我将它们移动到使用ace:fileentry的WAR项目时,它开始工作。