[
https://issues.jboss.org/browse/RF-13712?page=com.atlassian.jira.plugin.s...
]
Byambaa MD commented on RF-13712:
---------------------------------
MY FILEUPLOAD MBEAN CODE
---------------------------------------------------------------------------------------------
package mdb.dev.ZMN.core.mbean.UF;
import java.io.File;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.imageio.stream.FileImageOutputStream;
import mdb.cmn.base.configure.utilities.CMNBaseConfigureUtilities;
import mdb.cmn.base.mbean.CMNBaseMBean;
import mdb.cmn.utilities.log.CMNLogUtilities;
import mdb.cmn.utilities.system.CMNSystemUtilities;
import mdb.dev.ZMN.core.constants.ZMNCoreConstants;
import mdb.dev.ZMN.core.mbean.UF.DTO.ZMNCoreUFDTO;
import mdb.dev.ZMN.core.mbean.utilities.ZMNCoreMBeanUtilities;
import mdb.dev.ZMN.core.utilities.configure.ZMNCoreConfigureUtilities;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.primefaces.event.CaptureEvent;
import org.richfaces.event.FileUploadEvent;
/**
*
* @author Byambasuren.MD
*
**/
@SuppressWarnings("serial")
@SessionScoped
@ManagedBean(name = "CoreUFMBean")
public class ZMNCoreUFMBean extends CMNBaseMBean implements Serializable, ZMNCoreConstants
{
private boolean immediateUpload = false, allowFlash = false, autoClose = false,
generateName = true, useData = false, autoFinish = false, baseTemporary = false;
private Integer maxFilesQuantity;
private String acceptedTypes, destination;
private String render, desName, namePrefix;
private Collection<ZMNCoreUFDTO> files;
private boolean visible;
public ZMNCoreUFMBean() {
super();
}
/** MBean Utilities **/
public void doSetXUIMaintenance() {
}
public void doRTEMaintenance(String desName) {
}
public void doUploadMaintenance(String desName) {
}
public CMNBaseConfigureUtilities getConfigure() {
return ZMNCoreConfigureUtilities.getInstance();
}
/** Utilities **/
public void onCapture(CaptureEvent captureEvent) {
try {
ZMNCoreUFDTO uFile = new ZMNCoreUFDTO(null, null, null, captureEvent.getData().length,
(this.isUseData() ? captureEvent.getData() : null));
if (this.isGenerateName()) {
uFile.doGenerateName(this.getHasNamePrefix() ? (this.getNamePrefix()) : null,
"png");
} else if (this.getHasNamePrefix()) {
uFile.setName(this.getNamePrefix() + "_" + uFile.getName());
}
if (!new File(this.getBaseDestination() + this.getDestination()).exists())
CMNSystemUtilities.createDir(this.getBaseDestination() + this.getDestination());
FileImageOutputStream imageOutput;
imageOutput = new FileImageOutputStream(new File(this.getBaseDestination() +
this.getDestination() + uFile.getName()));
imageOutput.write(captureEvent.getData(), 0, captureEvent.getData().length);
imageOutput.close();
this.getFiles().add(uFile);
} catch (Exception ex) {
CMNLogUtilities.fatal("core", "UnSuccessful Upload File", ex);
}
}
public void listener(FileUploadEvent event) {
try {
ZMNCoreUFDTO uFile = new ZMNCoreUFDTO(event.getUploadedFile().getName(),
event.getUploadedFile().getName(), event.getUploadedFile().getContentType(),
event.getUploadedFile().getSize(), (this.isUseData() ? event.getUploadedFile().getData() :
null));
if (this.isGenerateName()) {
uFile.doGenerateName(this.getHasNamePrefix() ? (this.getNamePrefix()) : null);
} else if (this.getHasNamePrefix()) {
uFile.setName(this.getNamePrefix() + "_" + uFile.getName());
}
if (!new File(this.getBaseDestination() + this.getDestination()).exists())
CMNSystemUtilities.createDir(this.getBaseDestination() + this.getDestination());
FileUtils.writeByteArrayToFile(new File(this.getBaseDestination() +
this.getDestination() + uFile.getName()), event.getUploadedFile().getData());
this.getFiles().add(uFile);
this.setMaxFilesQuantity(this.getMaxFilesQuantity() - 1);
} catch (Exception ex) {
ex.printStackTrace();
CMNLogUtilities.fatal("core", "UnSuccessful Upload File", ex);
}
}
public void doShow() {
this.setVisible(true);
}
public void doClear() {
this.setVisible(false);
this.setImmediateUpload(false);
this.setAllowFlash(false);
this.setAutoFinish(false);
this.setAutoClose(false);
this.setGenerateName(true);
this.setUseData(false);
this.setAcceptedTypes(null);
this.setMaxFilesQuantity(null);
this.setDestination(null);
this.setNamePrefix(null);
this.setFiles(null);
}
public void doUpload() {
if (this.getHasFiles()) {
ZMNCoreMBeanUtilities.getCoreSUMBean().doUploadMaintenance(this.getDesName());
this.doClear();
} else {
FacesContext.getCurrentInstance().addMessage(null, new
FacesMessage(FacesMessage.SEVERITY_INFO,
ZMNCoreMBeanUtilities.getBundleMessage("cmn",
"lbl.operation.warning"),
ZMNCoreMBeanUtilities.getBundleMessage("cmn",
"msg.operation.canceled")));
}
}
/** Managed Getters **/
public String getBaseDestination() {
return this.isBaseTemporary() ?
ZMNCoreConfigureUtilities.getInstance().getCMNSetting(CMN.SETTING.PATH.TEMPORARY).getValue()
:
ZMNCoreConfigureUtilities.getInstance().getCMNSetting(CMN.SETTING.PATH.RESOURCES).getValue();
}
/** Getters **/
public ZMNCoreUFDTO getFile(int index) {
return this.getHasFiles() ? ((ArrayList<ZMNCoreUFDTO>) this.getFiles()).get(index)
: null;
}
public boolean getHasFiles() {
return this.getFiles().size() > 0;
}
public boolean getHasRender() {
return StringUtils.isNotBlank(this.getRender());
}
public boolean getHasNamePrefix() {
return StringUtils.isNotBlank(this.getNamePrefix());
}
/** Getters Setters **/
public boolean isImmediateUpload() {
return immediateUpload;
}
public void setImmediateUpload(boolean immediateUpload) {
this.immediateUpload = immediateUpload;
}
public boolean isAllowFlash() {
return allowFlash;
}
public void setAllowFlash(boolean allowFlash) {
this.allowFlash = allowFlash;
}
public boolean isGenerateName() {
return generateName;
}
public void setGenerateName(boolean generateName) {
this.generateName = generateName;
}
public boolean isUseData() {
return useData;
}
public void setUseData(boolean useData) {
this.useData = useData;
}
public Integer getMaxFilesQuantity() {
return maxFilesQuantity != null ? maxFilesQuantity : (maxFilesQuantity = 1);
}
public void setMaxFilesQuantity(Integer maxFilesQuantity) {
this.maxFilesQuantity = maxFilesQuantity;
}
public String getNamePrefix() {
return namePrefix;
}
public void setNamePrefix(String namePrefix) {
this.namePrefix = namePrefix;
}
public String getAcceptedTypes() {
return acceptedTypes != null ? acceptedTypes : (acceptedTypes = "jpg, gif,
png");
}
public void setAcceptedTypes(String acceptedTypes) {
this.acceptedTypes = acceptedTypes;
}
public String getDestination() {
return destination != null ? (destination + "/") : (destination =
"");
}
public void setDestination(String destination) {
this.destination = destination;
}
public Collection<ZMNCoreUFDTO> getFiles() {
return files != null ? files : (files = new ArrayList<ZMNCoreUFDTO>());
}
public void setFiles(Collection<ZMNCoreUFDTO> files) {
this.files = files;
}
public boolean isBaseTemporary() {
return baseTemporary;
}
public void setBaseTemporary(boolean baseTemporary) {
this.baseTemporary = baseTemporary;
}
public boolean isVisible() {
return visible;
}
public void setVisible(boolean visible) {
this.visible = visible;
}
public boolean isAutoClose() {
return autoClose;
}
public void setAutoClose(boolean autoClose) {
this.autoClose = autoClose;
}
public String getRender() {
return render;
}
public void setRender(String render) {
this.render = render;
}
public boolean isAutoFinish() {
return autoFinish;
}
public void setAutoFinish(boolean autoFinish) {
this.autoFinish = autoFinish;
}
public String getDesName() {
return desName;
}
public void setDesName(String desName) {
this.desName = desName;
}
}
FileUpload does not work on Wildfly 8.0 and Wildfly 8.1
-------------------------------------------------------
Key: RF-13712
URL:
https://issues.jboss.org/browse/RF-13712
Project: RichFaces
Issue Type: Feature Request
Security Level: Public(Everyone can see)
Components: component-input
Affects Versions: 4.3.7
Environment: 4.3.7 FileUpload does not work on wildfly
Reporter: Byambaa MD
Attachments: AS error log.png, can't Render.png, chrome js error log.png,
file upload done !.png, fileupload error on wildfly.png, Render code.png, Web application
libraries and main page structure.png
--
This message was sent by Atlassian JIRA
(v6.2.6#6264)