您好我在上传文件时遇到错误,即使我的bean中的方法为空,我也会收到错误。
这是我的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中。
更多信息:
答案 0 :(得分: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>