ファイルアップロードについて
画像をアップロードしたかったため、調査を開始。
とりあえず、リファレンスを見なければ始まらないので以下を参照しながら実装していきます。
Teeda - JSF meets DI and AOP -
そして、実装したHTMLとPageクラスは以下の通り。
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:te="http://www.seasar.org/teeda/extension" xml:lang="ja" lang="ja"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>ファイルアップロード</title> </head> <body> <form id="Form"> <input type="file" id="uploadFile" /> <input type="button" id="doUplode" value="アップロード" /> <span id="result"></span> </form> </body> </html>
Pageクラス
import java.io.File; import org.seasar.teeda.extension.util.UploadedFile; public class FileUplodePage { public UploadedFile uploadFile; public String result; public Class doUplode() { File filePass = new File("C:\\Work", uploadFile.getName()); try { uploadFile.write(filePass); result = "アップロード完了"; } catch (Exception e) { // TODO 自動生成された catch ブロック e.printStackTrace(); } return null; } initialize()、prerender()省略 }
そして、いざやってみると以下のエラーが出ました。
2009-08-05 12:34:27,109 [http-8080-1] DEBUG org.seasar.framework.container.hotdeploy.HotdeployBehavior - HOT deployを開始します 2009-08-05 12:34:27,234 [http-8080-1] DEBUG org.seasar.framework.container.util.S2ContainerUtil - クラス(jp.web.javafw.web.admin.FileUplodePage[admin_fileUplodePage])のコンポーネント定義を登録します 2009-08-05 12:34:27,265 [http-8080-1] WARN org.seasar.framework.container.assembler.BindingTypeShouldDef - jp.web.javafw.web.admin.FileUplodePage$$EnhancedByS2AOP$$18b073のプロパティ(uploadFile)が見つからないので設定をスキップします 2009-08-05 12:34:27,265 [http-8080-1] DEBUG org.seasar.framework.aop.interceptors.TraceInterceptor - BEGIN jp.web.javafw.web.admin.FileUplodePage#doUplode() 2009-08-05 12:34:27,265 [http-8080-1] DEBUG org.seasar.extension.jta.TransactionImpl - トランザクションを開始しました。tx=[FormatId=4360, GlobalId=1249443131390/8, BranchId=] java.lang.NullPointerException at jp.web.javafw.web.admin.FileUplodePage.doUplode(FileUplodePage.java:15) at jp.web.javafw.web.admin.FileUplodePage$$EnhancedByS2AOP$$18b073.$$doUplode$$invokeSuperMethod$$(FileUplodePage$$EnhancedByS2AOP$$18b073.java) at jp.web.javafw.web.admin.FileUplodePage$$EnhancedByS2AOP$$18b073$$MethodInvocation$$doUplode2.proceed(MethodInvocationClassGenerator.java) at org.seasar.extension.tx.DefaultTransactionCallback.execute(DefaultTransactionCallback.java:58) at org.seasar.extension.tx.adapter.JTATransactionManagerAdapter.required(JTATransactionManagerAdapter.java:65) at org.seasar.extension.tx.RequiredInterceptor.invoke(RequiredInterceptor.java:41) at jp.web.javafw.web.admin.FileUplodePage$$EnhancedByS2AOP$$18b073$$MethodInvocation$$doUplode2.proceed(MethodInvocationClassGenerator.java) at org.seasar.framework.aop.interceptors.ThrowsInterceptor.invoke(ThrowsInterceptor.java:79) at jp.web.javafw.web.admin.FileUplodePage$$EnhancedByS2AOP$$18b073$$MethodInvocation$$doUplode2.proceed(MethodInvocationClassGenerator.java) at org.seasar.framework.aop.interceptors.TraceInterceptor.invoke(TraceInterceptor.java:73) at jp.web.javafw.web.admin.FileUplodePage$$EnhancedByS2AOP$$18b073$$MethodInvocation$$doUplode2.proceed(MethodInvocationClassGenerator.java) at jp.web.javafw.web.admin.FileUplodePage$$EnhancedByS2AOP$$18b073.doUplode(FileUplodePage$$EnhancedByS2AOP$$18b073.java) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.seasar.framework.util.MethodUtil.invoke(MethodUtil.java:96) at org.seasar.framework.beans.impl.BeanDescImpl.invoke(BeanDescImpl.java:218) at org.seasar.teeda.extension.html.impl.HtmlComponentInvokerImpl.invoke(HtmlComponentInvokerImpl.java:163) at org.seasar.teeda.extension.html.impl.HtmlActionListener.processAction(HtmlActionListener.java:71) at javax.faces.component.UICommand.broadcast(UICommand.java:149) at org.seasar.teeda.extension.component.html.THtmlCommandButton.broadcast(THtmlCommandButton.java:78) at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:192) at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:117) at org.seasar.teeda.core.lifecycle.impl.InvokeApplicationPhase.executePhase(InvokeApplicationPhase.java:29) at org.seasar.teeda.core.lifecycle.AbstractPhase.execute(AbstractPhase.java:57) at org.seasar.teeda.core.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:97) at javax.faces.webapp.FacesServlet.service(FacesServlet.java:100) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.seasar.framework.container.filter.S2ContainerFilter.doFilter(S2ContainerFilter.java:79) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.seasar.framework.container.hotdeploy.HotdeployFilter.doHotdeployFilter(HotdeployFilter.java:99) at org.seasar.framework.container.hotdeploy.HotdeployFilter.doFilter(HotdeployFilter.java:67) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.seasar.teeda.extension.filter.MultipartFormDataFilter.doFilter(MultipartFormDataFilter.java:83) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.seasar.extension.filter.EncodingFilter.doFilter(EncodingFilter.java:69) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447) at java.lang.Thread.run(Unknown Source) 2009-08-05 12:34:27,265 [http-8080-1] DEBUG org.seasar.extension.jta.TransactionImpl - トランザクションをコミットしました。tx=[FormatId=4360, GlobalId=1249443131390/8, BranchId=] 2009-08-05 12:34:27,265 [http-8080-1] DEBUG org.seasar.framework.aop.interceptors.TraceInterceptor - END jp.web.javafw.web.admin.FileUplodePage#doUplode() : null 2009-08-05 12:34:27,265 [http-8080-1] DEBUG org.seasar.framework.aop.interceptors.TraceInterceptor - BEGIN jp.web.javafw.web.admin.FileUplodePage#prerender() 2009-08-05 12:34:27,265 [http-8080-1] DEBUG org.seasar.extension.jta.TransactionImpl - トランザクションを開始しました。tx=[FormatId=4360, GlobalId=1249443131390/9, BranchId=] 2009-08-05 12:34:27,265 [http-8080-1] DEBUG org.seasar.extension.jta.TransactionImpl - トランザクションをコミットしました。tx=[FormatId=4360, GlobalId=1249443131390/9, BranchId=] 2009-08-05 12:34:27,265 [http-8080-1] DEBUG org.seasar.framework.aop.interceptors.TraceInterceptor - END jp.web.javafw.web.admin.FileUplodePage#prerender() : null 2009-08-05 12:34:27,296 [http-8080-1] DEBUG org.seasar.framework.container.hotdeploy.HotdeployBehavior - HOT deployを終了しました
Seasarのメーリングリストを見て似たような現象を見ましたが、
Doltengで作ったプロジェクトですし「tomahawk-1.1.1.jar」使ってないしなぁ・・・
と泥沼化している感じです。
もう少し調べてわからなったら、別のところを実装しようっと・・・