Hi,
I'm using the file upload from Tomahawk with spring webflow2.0.2 and Facelets. I don't get any exception and indeed files get uploaded, whatever the size is!
Hi,
I'm using the file upload from Tomahawk with spring webflow2.0.2 and Facelets. I don't get any exception and indeed files get uploaded, whatever the size is!
Your base is JSF with which you are using Spring Webflow, whereas I am using Spring WebMVC as my base and Spring Webflow ion top of that.
The same worked out for me when I was using onle SpringWebMVC, but when I integrated my application with Spring Webflow, the feature is not well supported.
I don't see the view state. My first suggestion is to try to put your custom action state directly in view's transition and see what happens(that way you will process the MultipartFile in the original request):
Anyway, my advice is to get rid of the MultipartFile as soon as you can. So set the MultipartFile as transient in your command object and in the setter extract all the needed properties (originalFileName, content as a byte array) and set other properties in your command with these values.Code:<webflow:view-state id="yourView" model="myBean"> <webflow:on-render> ... your render code </webflow:on-render> <webflow:transition on="uploadEvent" to="success"> <webflow:evaluate expression="myFormAction.fileUpload(flowScope.myBean)" /> </webflow:transition> </webflow:view-state>
I had copied the relevant section from my flow section as in the view-state, I just have a transition which navigates to the action-state,performs the action and on "success" returns back the same view state..
(1)Now as you said, to put the Multipart file as transient, then in doing so,I get a NullPointException.Anyway, my advice is to get rid of the MultipartFile as soon as you can. So set the MultipartFile as transient in your command object and in the setter extract all the needed properties (originalFileName, content as a byte array) and set other properties in your command with these values.
(2) Getting the multipart file and setting to the byte[] is fine, but other properties such as originalFileName,contentType etc. how do you set them.
Is there any other way to implement this, do give some suggestions.
Can we make use of the SimpleFormAction(SpringMVC Controllers) from inside the webflow?
Last edited by DeepEdward; Jul 4th, 2008 at 08:15 AM.
I'm not sure from your post if you tried to eliminate the action state and use only the view state doing the upload logic in the view transition? (see my earlier post).
I don't understand your null pointer exception. It's probably because later you are trying to use the multipart property in your action state. My point is to get rid of the multipart, something like this:
Your upload login from your action method will use the myBean.getFileCOntent, myBean.getOriginalFileName and myBean.getFileContentType() instead of multipart file property which doesn't exist anymore.Code:public class MyBean implements Serializable { private byte[] fileContent; private String fileContentType; private String originalFileName; // getters and setters for filecontent, fileCOntentType, originalFileName public void setFile(MultipartFile file) { this.fileContent = file.getBytes(); this.fileContentType = file.getContentType(); this.originalFileName = file.getOriginalFileName(); } }
When the swf will try to bind the request parameter of type MultipartFile will use the setFile(...) method from your bean.
But I really think you should first try my earlier suggestion: eliminate the action state and put the <evaluate .../> upload logic directly in the view-state transition.
Yeah,
So you created separate properties in the domain object to get hold of the name and type of file.
Good, I tried this and it works fine.
Is it required to wrap my action inside the transition itself?But I really think you should first try my earlier suggestion: eliminate the action state and put the <evaluate .../> upload logic directly in the view-state transition.
As i said in my last post, that from the view-state I navigate to the action-state where I invoke this action to upload my file.
Anyway, it works fine now.. the problem was with the multipart form.
Thanks a lot for the suggestions.
Cheers
DeepEdward
Glad that helped you. What I was suggesting was to use only the view state and put your upload logic in the view state transition subelement:
Doing that way your method fileUpload() will be called after the binding and in the same request so you can use directly the MultipartFile (like you did in your original code). The difference between this approach (with only the view) and your original approach (with a view and an action state) is that when you execute the action state you are in a different request than the first one (because of the redirect after post that the swf is doing under the scene). Because of that the multipartFile member has to be serialized and there appears to be the problem. If you specify it as transient it will not be serialized and when you'll access it in your method you'll get a nullpointer. So in order to get rid of the problem you have to avoid the serialization (specify transient on the multipartFile) and you have to access it when it has the value, in the first request (put your upload code in the view state like I said before).Code:<view-state id="uploadVIew" model="myBean"> <transition on="yourUploadEvent" to="success"> <evaluate expression="myFormAction.fileUpload(myBean)"/> </transition> </view-state>
I have a tendency to be verbose because english is not my native language. Hope that I was clear enough.
I am having the same issue...and like deep says the file still get uploaded.
As seen in the last stacktrace, it looks like there is some kind of error in the org.apache.commons.fileupload.disk.DiskFileItem.re adObject()Code:org.springframework.webflow.execution.repository.FlowExecutionRestorationFailureException: A problem occurred restoring the flow execution with key 'e1s5' at org.springframework.webflow.execution.repository.snapshot.SerializedFlowExecutionSnapshotFactory.restoreExecution(SerializedFlowExecutionSnapshotFactory.java:82) at org.springframework.webflow.execution.repository.snapshot.AbstractSnapshottingFlowExecutionRepository.restoreFlowExecution(AbstractSnapshottingFlowExecutionRepository.java:89) at org.springframework.webflow.execution.repository.impl.DefaultFlowExecutionRepository.getFlowExecution(DefaultFlowExecutionRepository.java:104) at org.springframework.webflow.executor.FlowExecutorImpl.resumeExecution(FlowExecutorImpl.java:152) at org.springframework.webflow.mvc.servlet.FlowHandlerAdapter.handle(FlowHandlerAdapter.java:173) at org.springframework.webflow.mvc.servlet.FlowController.handleRequest(FlowController.java:172) at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:875) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:809) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:571) at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:501) at javax.servlet.http.HttpServlet.service(HttpServlet.java:689) .... Caused by: org.springframework.webflow.execution.repository.snapshot.SnapshotUnmarshalException: IOException thrown deserializing the flow execution stored in this snapshot -- this should not happen! at org.springframework.webflow.execution.repository.snapshot.SerializedFlowExecutionSnapshot.unmarshal(SerializedFlowExecutionSnapshot.java:100) at org.springframework.webflow.execution.repository.snapshot.SerializedFlowExecutionSnapshotFactory.restoreExecution(SerializedFlowExecutionSnapshotFactory.java:80) ... Caused by: java.io.FileNotFoundException: C:\dev\apps\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\work\Catalina\localhost\mobolus\upload_c82342c_11aef8b3cda__8000_00000005.tmp (The system cannot find the file specified) at java.io.FileInputStream.open(Native Method) at java.io.FileInputStream.<init>(FileInputStream.java:106) at org.apache.commons.fileupload.disk.DiskFileItem.readObject(DiskFileItem.java:691) ...
I tried searching for this issue but I it seems its related to webflow in some way. I am not sure how to proceed.
Ok, nevermind...somebody (me) needs to read a little more carefully and not skim so much. I will try it out.