This content has been marked as final.
Show 3 replies
-
1. Re: <s:fileUpload> problem
shane.bryzak Apr 17, 2007 9:34 PM (in response to jquery)I recommend not binding directly to your entity, because the InputStream binding is by far the most resource efficient and obviously you can't have an InputStream property on your entity bean. Instead I recommend you bind the file data to an InputStream field on a (session bean) component, and then use that to populate your entity.
-
2. Re: <s:fileUpload> problem
jquery Apr 18, 2007 5:27 PM (in response to jquery)Hi,
thanks for the recommendation but suppose that we have the following classes:public class Document implements Serializable{ InputStream file; public InputStream getFile() { return file; } public void setFile(InputStream file) { this.file = file; } } @Name("documentHome") public class DocumentHome extends EntityHome<Document>{ @Override protected Document createInstance(){ Document document = new Document(); return document; } } @Entity @Table(name = "PROFILE_APPENDIX", schema = "DB2USER") public class ProfileAppendix implements java.io.Serializable { private long id; private Profile profile; private String name; private String description; private Blob appendix; (...) } @Name("profileAppendixHome") public class ProfileAppendixHome1 extends EntityHome<ProfileAppendix1> { @In(create = true) ProfileHome profileHome; @In(create=true) EntityManager entityManager; @In(create=true) DocumentHome documentHome; public void saveProfileAppendix(){} }
When the form is submitted "file" variable from Document class is populated but I don't know how
to populate Blob appendix variable in saveProfileAppendix() function using
documentHome.instance.getFile(). How to cast InputStream to Blob?
Any help appreciated.
Best regards,
jquery -
3. Re: <s:fileUpload> problem
shane.bryzak Apr 18, 2007 7:15 PM (in response to jquery)I believe that you'd use Blob.setBinaryStream() to get the blob's OutputStream, then write the data from the file's InputStream to that. Maybe someone more knowledgeable about using blob fields can comment on this?