/
HtmlInputFile.java
72 lines (59 loc) · 2.22 KB
/
HtmlInputFile.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/**
* Copyright (c) 2000-2014 Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
package com.liferay.faces.bridge.component;
import javax.el.MethodExpression;
import javax.faces.context.FacesContext;
import javax.faces.event.AbortProcessingException;
import javax.faces.event.FacesEvent;
import com.liferay.faces.bridge.event.FileUploadEvent;
import com.liferay.faces.bridge.model.UploadedFile;
/**
* @author Neil Griffin
*/
public class HtmlInputFile extends HtmlInputFileCompat {
// Private Data Members
private UploadedFile uploadedFile;
public HtmlInputFile() {
super();
setRendererType("com.liferay.faces.bridge.renderkit.bridge.InputFileRenderer");
}
@Override
public void broadcast(FacesEvent facesEvent) throws AbortProcessingException {
super.broadcast(facesEvent);
FacesContext facesContext = FacesContext.getCurrentInstance();
try {
MethodExpression methodExpression = getFileUploadListener();
if ((methodExpression != null) && (facesEvent instanceof FileUploadEvent)) {
methodExpression.invoke(facesContext.getELContext(), new Object[] { facesEvent });
}
}
catch (Exception e) {
throw new AbortProcessingException(e);
}
}
/**
* @deprecated Instead of calling this method which only returns the first uploaded file, create a value-expression
* to a model bean like <bridge:inputFile value="#{modelBean.uploadedFiles} /> or use the
* event-based approach: <bridge:inputFile fileUploadListener="#{backingBean.handleFileUpload} />
*
* @return The first uploaded file.
*/
@Deprecated
public UploadedFile getUploadedFile() {
return uploadedFile;
}
public void setUploadedFile(UploadedFile uploadedFile) {
this.uploadedFile = uploadedFile;
}
}