2017-05-04 16 views
0

你好我上传文件时出现错误,即使我的bean中的方法是空的,我得到错误。h:inputFile和h:commandButton - 空指针异常

这里是我的JSF

<html xmlns="http://www.w3.org/1999/xhtml" 
    xmlns:h="http://xmlns.jcp.org/jsf/html" 
    xmlns:f="http://xmlns.jcp.org/jsf/core"> 
<h:head> 
    <h:outputStylesheet library="css" name="main-admin.css"/> 
</h:head> 
<h:body> 
    <div class="container-fluid"> 
     <div class="row"> 
      <div class="col-sm-12"> 
       <h:form id="form" enctype="multipart/form-data"> 
        <h:inputFile id="file" value="#{userPictureUploadView.file}"/> 
        <h:commandButton value="Upload" 
            action="#{userPictureUploadView.uploadProfilePicture}"> 
        </h:commandButton> 
       </h:form> 
      </div> 
     </div> 
    </div> 

</h:body> 
</html> 

以下是错误我得到

Caused by: java.lang.NullPointerException: Argument Error: Parameter text is null 
    at com.sun.faces.renderkit.html_basic.HtmlResponseWriter.writeText(HtmlResponseWriter.java:949) 
    at javax.faces.context.ResponseWriterWrapper.writeText(ResponseWriterWrapper.java:298) 
    at com.liferay.faces.bridge.renderkit.primefaces.internal.PrimeFacesInlineScript.encodeBegin(PrimeFacesInlineScript.java:51) 
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1854) 
    at com.liferay.faces.bridge.renderkit.html_basic.internal.BodyRendererBridgeImpl.encodeBegin(BodyRendererBridgeImpl.java:117) 
    at javax.faces.component.UIComponentBase.encodeBegin(UIComponentBase.java:865) 
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1854) 
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859) 
    at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:458) 
    at javax.faces.view.ViewDeclarationLanguageWrapper.renderView(ViewDeclarationLanguageWrapper.java:146) 
    at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:134) 
    at com.liferay.faces.bridge.application.internal.ViewHandlerCompatImpl.renderView(ViewHandlerCompatImpl.java:95) 
    at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120) 
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) 
    ... 223 more 

我不知道为什么我得到一个例外,它似乎是错误的方法后解雇被执行,就像在重新加载。

所有这些都在我在Liferay中制作的portlet中。

的更多信息:

  • 我使用这些版本Liferay.faces.bridge 的 'com.liferay.faces:com.liferay.faces.bridge.impl:4.0.0' “COM .liferay.faces:com.liferay.faces.bridge.ext:5.0.0'
+1

你的问题是由于一个错误Liferay Faces Bridge(Impl):[FACES-3031](https://issues.liferay.com/browse/)。 – stiemannkj1

+1

凯尔是正确的。你的问题是由[FACES-3031](https://issues.liferay.com/browse/FACES-3031)造成的。 – Vernon

+0

1.您使用的是哪个版本的Liferay? – Vernon

回答

1

该解决方案将使用AJAX或uploadListener

     <div class="form-group"> 
          <div class="control-label">#{res['userProfilePictureUpload.profilePicture']}</div> 
          <p:fileUpload fileUploadListener="#{userPictureUploadView.handleFileUpload}" mode="advanced" allowTypes="/(\.|\/)(png)$/" auto="true" previewWidth="0" label="#{res['userProfilePictureUpload.upload']}" oncomplete="location.reload();"/> 
         </div>