我使用的是p:fileUpload
,但如果我使用mode="simple"
,則fileUploadListener不會被調用。有沒有什麼辦法在簡單模式下使用fileUploadListener。PrimeFaces p:fileUpload監聽器方法永遠不會調用mode =「simple」
<p:fileUpload id ="uploading"
fileUploadListener="#{workflowActionTemplate.handleFileUpload}"
mode="simple"
update="messages"
sizeLimit="100000"
allowTypes="/(\.|\/)(gif|jpe?g|png|pdf)$/"
multiple="true"/>
總理面臨:3.2
我做了如下配置,請讓我知道如果我錯過什麼。
的web.xml:
<!-- File Upload filter -->
<filter>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
的pom.xml:
<!-- Dependancy for file upload -->
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>3.2</version>
</dependency>
監聽方法:
public void handleFileUpload(FileUploadEvent event) {
FacesMessage msg = new FacesMessage("Succesful", event.getFile().getFileName() + " is uploaded."); System.out.println("msg : "+ msg);
uploadedFile = event.getFile();
}
-
如果我使用屬性值fileUploadListener代替如果我不上前廣告文件,然後 fileUpload屬性沒有得到設置,所以它給出了以下錯誤。
javax.faces.component.UpdateModelException: javax.el.ELException: /search/workflowAction.xhtml @181,104 value="#{workflowActionTemplate.uploadedFile}": Can't set property 'uploadedFile' of type 'org.primefaces.model.UploadedFile' on class 'com.principal.nq.statements.search.WorkflowActionTemplate$$EnhancerByCGLIB$$6ebcb7eb' to value ''
更新
由於fileUploadListener不工作我也嘗試使用Ajax調用以下列方式更新文件的價值。但f:ajax
無法執行Primefaces p:fileUpload
組件。我也試過p:ajax
,但那也行不通。
<p:fileUpload id="uploading"
value="#{workflowActionTemplate.uploadedFile}"
mode="simple"
update="messages"
sizeLimit="100000"
allowTypes="/(\.|\/)(gif|jpe?g|png|pdf)$/"
auto="true"/>
<p:growl id="messages" showDetail="true"/>
<h:commandButton id="uploadDocument" styleClass="continuebutton" value="#{msg.upload}" action="#{workflowActionTemplate.uploadParticipantCustomDoc}">
<f:ajax execute="uploading" render="uploadDocumentDlg" onevent="onAjaxUploadCustomDoc"/>
</h:commandButton>
你的問題是重複的:http://stackoverflow.com/questions/8875818/how-t o-use-primefaces-pfileupload-listener-method-is-never-invoked – 2013-05-02 16:00:21
@RongNK:OP意味着在使用'mode =「advanced」時它工作正常。 @Arpit:你是否在嵌套表單? – BalusC 2013-05-02 18:22:42
@BalusC你是對的,它不適用於簡單模式。不,我不是嵌套形式。我也嘗試使用ajax,以便我可以實現相同的功能,但f:ajax&p:ajax都無法執行primeface p:fileUpload組件。 – Arpit 2013-05-03 07:07:41