1
A
回答
1
我覺得你在richfaces
是新的。 Richfaces爲它的Showcase提供瞭如何執行它的源代碼。
結帳richfaces展示,Here。
HTML文件:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:a4j="http://richfaces.org/a4j" xmlns:rich="http://richfaces.org/rich">
<ui:composition>
<h:outputStylesheet>
.top {
vertical-align: top;
}
.info {
height: 202px;
overflow: auto;
}
</h:outputStylesheet>
<h:form>
<h:panelGrid columns="2" columnClasses="top,top">
<rich:fileUpload fileUploadListener="#{fileUploadBean.listener}" id="upload" acceptedTypes="jpg, gif, png, bmp"
ontyperejected="alert('Only JPG, GIF, PNG and BMP files are accepted');" maxFilesQuantity="5">
<a4j:ajax event="uploadcomplete" execute="@none" render="info" />
</rich:fileUpload>
<h:panelGroup id="info" layout="block">
<rich:panel bodyClass="info">
<f:facet name="header">
<h:outputText value="Uploaded Files Info" />
</f:facet>
<h:outputText value="No files currently uploaded" rendered="#{fileUploadBean.size==0}" />
<rich:dataGrid columns="1" value="#{fileUploadBean.files}" var="file" rowKeyVar="row">
<rich:panel bodyClass="rich-laguna-panel-no-header">
<h:panelGrid columns="2">
<a4j:mediaOutput element="img" mimeType="image/jpeg" createContent="#{fileUploadBean.paint}"
value="#{row}" style="width:100px; height:100px;" cacheable="false">
<f:param value="#{fileUploadBean.timeStamp}" name="time" />
</a4j:mediaOutput>
<h:panelGrid columns="2">
<h:outputText value="File Name:" />
<h:outputText value="#{file.name}" />
<h:outputText value="File Length(bytes):" />
<h:outputText value="#{file.length}" />
</h:panelGrid>
</h:panelGrid>
</rich:panel>
</rich:dataGrid>
</rich:panel>
<br />
<a4j:commandButton action="#{fileUploadBean.clearUploadData}" render="info, upload" value="Clear Uploaded Data"
rendered="#{fileUploadBean.size>0}" />
</h:panelGroup>
</h:panelGrid>
</h:form>
</ui:composition>
</html>
Java文件:
package org.richfaces.demo.fileupload;
import java.io.IOException;
import java.io.OutputStream;
import java.io.Serializable;
import java.util.ArrayList;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import org.richfaces.event.FileUploadEvent;
import org.richfaces.model.UploadedFile;
/**
* @author Ilya Shaikovsky
*/
@ManagedBean
@SessionScoped
public class FileUploadBean implements Serializable {
private ArrayList<UploadedImage> files = new ArrayList<UploadedImage>();
public void paint(OutputStream stream, Object object) throws IOException {
stream.write(getFiles().get((Integer) object).getData());
stream.close();
}
public void listener(FileUploadEvent event) throws Exception {
UploadedFile item = event.getUploadedFile();
UploadedImage file = new UploadedImage();
file.setLength(item.getData().length);
file.setName(item.getName());
file.setData(item.getData());
files.add(file);
}
public String clearUploadData() {
files.clear();
return null;
}
public int getSize() {
if (getFiles().size() > 0) {
return getFiles().size();
} else {
return 0;
}
}
public long getTimeStamp() {
return System.currentTimeMillis();
}
public ArrayList<UploadedImage> getFiles() {
return files;
}
public void setFiles(ArrayList<UploadedImage> files) {
this.files = files;
}
}
+0
jubinPatel,我要求一個拖放組件。上面的例子只是一個文件上傳組件,更像是一個瀏覽按鈕的例子。那麼,我已經實施了拖放很久以前,現在它在生產。 – 2013-11-07 14:52:27
0
我公司提供的類UploadedImage這是同一個包不是類的代碼FileUploadBean。 link for getting the code of the class UploadedImage
package org.richfaces.demo.fileupload;
import java.io.Serializable;
public class UploadedImage implements Serializable {
private String name;
private String mime;
private long length;
private byte[] data;
public byte[] getData() {
return data;
}
public void setData(byte[] data) {
this.data = data;
}
public String getName() {
return name;
}
public void setName(String name) {
int extDot = name.lastIndexOf('.');
if (extDot > 0) {
String extension = name.substring(extDot + 1);
if ("bmp".equals(extension)) {
mime = "image/bmp";
} else if ("jpg".equals(extension)) {
mime = "image/jpeg";
} else if ("gif".equals(extension)) {
mime = "image/gif";
} else if ("png".equals(extension)) {
mime = "image/png";
} else {
mime = "image/unknown";
}
}
}
public long getLength() {
return length;
}
public void setLength(long length) {
this.length = length;
}
public String getMime() {
return mime;
}
}
我希望我幫誰想要使用「富:文件上傳」人民組件
相關問題
- 1. HTML5拖放n拖放文件上傳
- 2. 拖放ajax文件上傳
- 3. 拖放文件上傳
- 4. Xpages拖放文件上傳
- 5. 拖放文件上傳
- 6. YI拖放文件上傳
- 7. 拖放jQuery文件上傳
- 8. html5拖放文件上傳
- 9. 在jquery中拖放文件上傳
- 10. 使用RichFaces上傳文件
- 11. 使用RichFaces上傳文件
- 12. 拖放上傳
- 13. jquery文件上傳:單個文件上傳用於拖放
- 14. 拖放文件上傳插件.net?
- 15. jQuery拖放上傳插件
- 16. 拖放上傳插件
- 17. Rails3 +拖放+多個文件上傳
- 18. HTML5拖放和多個文件上傳
- 19. 爲Internet Explorer拖放文件上傳庫
- 20. 拖放文件上傳(挖空+ webapi + asp.net)
- 21. 拖,放和提交的文件上傳
- 22. MySQL/PHP拖放文件上傳
- 23. 拖放文件上傳不起作用
- 24. PHP用拖放方式上傳文件
- 25. 拖放文件上傳asp.net或java
- 26. selenium webdriver:通過拖放上傳文件
- 27. 通過拖放文件上傳
- 28. Gmail像拖放文件上傳
- 29. 拖放文件上傳到.PHP
- 30. jQuery的拖放文件上傳
那麼你爲什麼不打開RichFaces的文檔? – Aquillo 2013-04-22 12:53:47
阿奎洛,我無法找到任何功能。只是尋找某人已經開發出它.. – 2013-04-25 08:22:18
「拖放」是指將它們從本地文件夾中拖出,將「我的文檔」稱爲網站? – Aquillo 2013-04-25 08:25:01