Author: konstantin.mishin
Date: 2010-12-09 13:53:59 -0500 (Thu, 09 Dec 2010)
New Revision: 20487
Modified:
trunk/examples/input-demo/src/main/java/org/richfaces/demo/FileUploadBean.java
trunk/ui/input/ui/src/main/java/org/richfaces/context/FileUploadPartialViewContextFactory.java
trunk/ui/input/ui/src/main/java/org/richfaces/request/FileParam.java
Log:
RF-9972
Modified: trunk/examples/input-demo/src/main/java/org/richfaces/demo/FileUploadBean.java
===================================================================
---
trunk/examples/input-demo/src/main/java/org/richfaces/demo/FileUploadBean.java 2010-12-09
18:51:56 UTC (rev 20486)
+++
trunk/examples/input-demo/src/main/java/org/richfaces/demo/FileUploadBean.java 2010-12-09
18:53:59 UTC (rev 20487)
@@ -53,9 +53,6 @@
public void listener(UploadEvent event) throws Exception {
item = event.getUploadItem();
- if (item != null) {
- item.getFile().delete();
- }
}
public void setEnabled(boolean enabled) {
Modified:
trunk/ui/input/ui/src/main/java/org/richfaces/context/FileUploadPartialViewContextFactory.java
===================================================================
---
trunk/ui/input/ui/src/main/java/org/richfaces/context/FileUploadPartialViewContextFactory.java 2010-12-09
18:51:56 UTC (rev 20486)
+++
trunk/ui/input/ui/src/main/java/org/richfaces/context/FileUploadPartialViewContextFactory.java 2010-12-09
18:53:59 UTC (rev 20487)
@@ -34,6 +34,8 @@
import javax.faces.context.FacesContext;
import javax.faces.context.PartialViewContext;
import javax.faces.context.PartialViewContextFactory;
+import javax.faces.context.PartialViewContextWrapper;
+import javax.faces.event.PhaseId;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -85,6 +87,7 @@
@Override
public PartialViewContext getPartialViewContext(FacesContext facesContext) {
+ PartialViewContext partialViewContext =
parentFactory.getPartialViewContext(facesContext);
ExternalContext externalContext = facesContext.getExternalContext();
HttpServletRequest request = (HttpServletRequest) externalContext.getRequest();
Map<String, String> queryParamMap =
parseQueryString(request.getQueryString());
@@ -93,9 +96,35 @@
if (maxRequestSize != 0 && externalContext.getRequestContentLength()
> maxRequestSize) {
printResponse(facesContext, uid, ResponseState.sizeExceeded);
} else {
- MultipartRequest multipartRequest = new MultipartRequest(request,
createTempFiles, tempFilesDirectory,
- uid);
+ final MultipartRequest multipartRequest = new MultipartRequest(request,
createTempFiles,
+ tempFilesDirectory, uid);
try {
+ final PartialViewContext viewContext = partialViewContext;
+ partialViewContext = new PartialViewContextWrapper() {
+ @Override
+ public void processPartial(PhaseId phaseId) {
+ try {
+ super.processPartial(phaseId);
+ } finally {
+ if (PhaseId.RENDER_RESPONSE.equals(phaseId)) {
+ multipartRequest.cancel();
+ //TODO PartialViewContext.release isn't invoked
by JSF. Maybe it's a bug.
+ //So we should use PartialViewContext.processPartial
instead of.
+ }
+ }
+ };
+
+ //TODO This method can be removed from here when
PartialViewContextWrapper will implement it.
+ @Override
+ public void setPartialRequest(boolean isPartialRequest) {
+ viewContext.setPartialRequest(isPartialRequest);
+ }
+
+ @Override
+ public PartialViewContext getWrapped() {
+ return viewContext;
+ }
+ };
multipartRequest.parseRequest();
if (!multipartRequest.isDone()) {
printResponse(facesContext, uid, ResponseState.stopped);
@@ -109,7 +138,7 @@
}
}
}
- return parentFactory.getPartialViewContext(facesContext);
+ return partialViewContext;
}
private Map<String, String> parseQueryString(String queryString) {
Modified: trunk/ui/input/ui/src/main/java/org/richfaces/request/FileParam.java
===================================================================
--- trunk/ui/input/ui/src/main/java/org/richfaces/request/FileParam.java 2010-12-09
18:51:56 UTC (rev 20486)
+++ trunk/ui/input/ui/src/main/java/org/richfaces/request/FileParam.java 2010-12-09
18:53:59 UTC (rev 20487)
@@ -87,6 +87,7 @@
dir = new File(tempFilesDirectory);
}
tempFile = File.createTempFile(UUID.randomUUID().toString(),
".upload", dir);
+ tempFile.deleteOnExit();
fOut = new FileOutputStream(tempFile);
} catch (IOException ex) {
if (fOut != null) {