Fileupload
現在のTeedaはFileUploadのコンポーネントをまだ作っていない(1.1までには含まれる予定)ので、
TomahawkのFileUploadを使います。
tomahawk-1.1.1.jar、commons-fileupload-1.0.jarを使って動かすようにしましょう。
web.xmlのfileterに設定します。
<filter> <filter-name>extensionsFilter</filter-name> <filter-class>org.apache.myfaces.component.html.util.ExtensionsFilter</filter-class> <init-param> <param-name>uploadMaxFileSize</param-name> <param-value>100m</param-value> <description>Set the size limit for uploaded files. Format: 10 - 10 bytes 10k - 10 KB 10m - 10 MB 1g - 1 GB </description> </init-param> <init-param> <param-name>uploadThresholdSize</param-name> <param-value>100m</param-value> <description>Set the threshold size - files below this limit are stored in memory, files above this limit are stored on disk. Format: 10 - 10 bytes 10k - 10 KB 10m - 10 MB 1g - 1 GB </description> </init-param> <init-param> <param-name>uploadRepositoryPath</param-name> <param-value>/work</param-value> <description>Set the path where the intermediary files will be stored. </description> </init-param> </filter>
param-valueは好きに変更してください。
file.htmlはこんな感じです。基本はHTMLテンプレートですが、JSPライクに記述することが可能です。
<html xmlns:x="http://myfaces.apache.org/tomahawk"> <title>Fileupload</title> <body> <form id="form" enctype="multipart/form-data"> <x:inputFileUpload id="uploadedFile" value="#{tomahawk_filePage.uploadedFile}"/> <input type="submit" id="doUpload" value="UPLOAD"/> </form> </body>
Pageクラスは下記のようにします。
FilePage
package examples.teeda.web.tomahawk; import java.io.Serializable; import org.apache.myfaces.custom.fileupload.UploadedFile; /** * @author shot */ public class FilePage implements Serializable { private static final long serialVersionUID = 1L; private UploadedFile uploadedFile; public UploadedFile getUploadedFile() { return this.uploadedFile; } public void setUploadedFile(UploadedFile uploadedFile) { this.uploadedFile = uploadedFile; System.out.println("#####uploadFileSize[" + uploadedFile.getSize() + "]"); } public String doUpload() { if (uploadedFile != null) { System.out.println("#####uploadFileSize[" + uploadedFile.getSize() + "]"); } return null; } }
これで基本的にはFileが渡されるはずです。
すまん、今はこれ載せるのが限界でっす。
これでどうでしょうか?