You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Kedar Panse <ke...@gmail.com> on 2005/12/22 12:18:11 UTC

NewB: Struts FormFile and Session scope FormBean

Hello gurus,

I want to use a wizard type of flow where in one screen there is File
Upload.  As  this is wizard, i was using session scoped formbean with one
property formfile.  But seems like formfile is not serializable.  What is
proper way of handling this?


Thanks!

Kedar

Re: NewB: Struts FormFile and Session scope FormBean

Posted by Rahul Akolkar <ra...@gmail.com>.
On 12/24/05, Kedar Panse <ke...@gmail.com> wrote:
> Thanks, That would work.  But still I'll have to have FormFile in to
> ActionForm which is not seriliazable. Giving me error
>
>  IOException while loading persisted sessions: java.io.WriteAbortedException:
> writing aborted; java.io.NotSerializableException:
<snip/>

To use lazy initialization, one tends to declare the corresponding
fields transient. And you should also think about using a real
persistence layer (being in a servlet container environment).

But lets first ask:

 * Is it the intent to serialize? Why do you want FormFile's to
persist? Is this about the server failures/restarts?

 * Does it matter enough for these use cases? What is the end-user
experience that is missing, that you want to achieve?

-Rahul


>
> Kedar
>
>
> On 12/22/05, Laurie Harper <la...@holoweb.net> wrote:
> >
> > Kedar Panse wrote:
> > > Hello gurus,
> > >
> > > I want to use a wizard type of flow where in one screen there is File
> > > Upload.  As  this is wizard, i was using session scoped formbean with
> > one
> > > property formfile.  But seems like formfile is not serializable.  What
> > is
> > > proper way of handling this?
> >
> > Given that a file could be arbitrarily large, is doesn't really make
> > sense to store it in the session. I'd suggest saving it to temporary
> > disk and replacing the reference in the form bean with the path to the
> > temporary file. You can then reload the temp file when your wizard is
> > ready to deal with it.
> >
> > So, in your action when the file upload is received, stream it to a temp
> > file, set the form bean property for the uploaded file to null, and set
> > another property to the path to the temp file. The form bean should then
> > serialize without problem, and you can get at the file later when you
> > need to.
> >
> > L.
> >
<snap/>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: NewB: Struts FormFile and Session scope FormBean

Posted by Kedar Panse <ke...@gmail.com>.
Thanks, That would work.  But still I'll have to have FormFile in to
ActionForm which is not seriliazable. Giving me error

 IOException while loading persisted sessions: java.io.WriteAbortedException:
writing aborted; java.io.NotSerializableException:
org.apache.commons.fileupload.DeferredFileOutputStream
java.io.WriteAbortedException: writing aborted;
java.io.NotSerializableException:
org.apache.commons.fileupload.DeferredFileOutputStream
        at java.io.ObjectInputStream.readObject0(ObjectInputStream.java
:1303)


Kedar


On 12/22/05, Laurie Harper <la...@holoweb.net> wrote:
>
> Kedar Panse wrote:
> > Hello gurus,
> >
> > I want to use a wizard type of flow where in one screen there is File
> > Upload.  As  this is wizard, i was using session scoped formbean with
> one
> > property formfile.  But seems like formfile is not serializable.  What
> is
> > proper way of handling this?
>
> Given that a file could be arbitrarily large, is doesn't really make
> sense to store it in the session. I'd suggest saving it to temporary
> disk and replacing the reference in the form bean with the path to the
> temporary file. You can then reload the temp file when your wizard is
> ready to deal with it.
>
> So, in your action when the file upload is received, stream it to a temp
> file, set the form bean property for the uploaded file to null, and set
> another property to the path to the temp file. The form bean should then
> serialize without problem, and you can get at the file later when you
> need to.
>
> L.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: NewB: Struts FormFile and Session scope FormBean

Posted by Laurie Harper <la...@holoweb.net>.
Kedar Panse wrote:
> Hello gurus,
> 
> I want to use a wizard type of flow where in one screen there is File
> Upload.  As  this is wizard, i was using session scoped formbean with one
> property formfile.  But seems like formfile is not serializable.  What is
> proper way of handling this?

Given that a file could be arbitrarily large, is doesn't really make 
sense to store it in the session. I'd suggest saving it to temporary 
disk and replacing the reference in the form bean with the path to the 
temporary file. You can then reload the temp file when your wizard is 
ready to deal with it.

So, in your action when the file upload is received, stream it to a temp 
file, set the form bean property for the uploaded file to null, and set 
another property to the path to the temp file. The form bean should then 
serialize without problem, and you can get at the file later when you 
need to.

L.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org