|
|
I'm looking at the fileupload example and I'm having a little trouble figuring out how to process the file from within ProcessUploadAction.java. Can someone give me a brief example of how to get at the file from within ProcessUploadAction.java?
Thanks for the pointers.
Since the ProcessUploadAction puts the FileUploadBean in REQUEST scope (the default), you would do something like this:Code:
public Event processFile#40;RequestContext context#41; throws Exception #123; FileUploadBean fub=#40;FileUploadBean#41;context.getRequestScope#40;#41;.getAttribute#40;quot;filequot;#41;; byte#91;#93; fileData=fub.getFile#40;#41;; ... //process file data return success#40;#41;;
#125;
You would then need to invoke this processFile() method from an action state, something like this:Code:
lt;action-state id=quot;processFilequot;gt; lt;action bean=quot;upload.processquot;/gt; lt;transition on=quot;successquot; to=quot;...quot;/gt;
lt;/action-stategt;That's exactly what I've done. The only problem is that fub ends up being null.
This did the trick.Code:
public Event processFile#40;RequestContext context#41; throws Exception #123; bindAndValidate#40;context#41;; FileUploadBean fub=#40;FileUploadBean#41;context.getRequestScope#40;#41;.getAttribute#40;quot;filequot;#41;; byte#91;#93; fileData=fub.getFile#40;#41;; ... //process file data return success#40;#41;;
#125; |
|