Re: [Wicket-user] best practice for uploading and using content (images) with wicket?

2006-08-23 Thread Sebastian Pflugbeil

Well, thanks a lot, thats really much more simple then i figured =P. Maybe
any pointers why the stream from the file system doesnt work? ;)


igor.vaynberg wrote:
 
 your problem is not retreiving the data from the db - it is the weird
 stuff
 you try to do when stream it back to the browser. why all the awt image
 stuff? all you have to do is read the byte array from the db and stream it
 back to the browser.
 
 here is some pseudo code
 
 add(new Image(myimage) {
   Resource getResource() { return new ByteArrayResource(getBytesFromDb());
 }
 }
 
  
 
 if you really want to resize the image to 200x200 before storing it in the
 db or creating a thumbnail then i would look over that wiki example and
 extract the resizing logic - but if all you want to do is stream it back
 then the above will do.
 
 -Igor
 
 
 On 8/22/06, Sebastian Pflugbeil 
 [EMAIL PROTECTED] wrote:

  Hi Wicket Team and Wicket Mailinglist!



 As this is my first post on this list, I would like to introduce myself.
 My name is Sebastian and I am working on a university project, comparing
 Java web frameworks. As you might guess, my primary topic is the Wicket
 framework ;). I am not what one would call a programmer or coder, I
 guess.
 Rather someone familiar with the underling concepts, but sometimes a bit
 lots with the actual implementations of a certain language. So please
 excuse
 me, if my questions are stupid ;).



 My problem at this moment is the following. I need to implement a feature
 in wicket that lets me upload images to a webpage and then use those
 images
 to be displayed on certain pages. It doesn't really matter if the images
 are
 stored on the file system or in a database. I am not looking for a
 solution
 to an explicit problem but rather for a best practice that shows how the
 wicket framework supports such a feature.



 I have tried to read up on anything I could find addressing such a
 feature. But everything I got so far is either way beyond my scope of
 understanding, not offering enough to archive the goal or just not
 working
 as I understand it should.



 I have tried to read the example in the wiki (
 http://www.wicket-wiki.org.uk/wiki/index.php/*UploadDownload*http://www.wicket-wiki.org.uk/wiki/index.php/UploadDownload),
 but I can not really follow it. Too many libraries used that are not
 included and overall to confusing for a non professional like myself.

 I did understand the example for the upload in the wikiexamples though.
 No
 problems writing files to disk or even to database, following that
 example
 code.



 My attempt to store images in the Database is looking something like
 this:



 To write to the Database, I use this code sniped:



 public final void onSubmit()

 {

   try

   {

 // get the content of the upload field

 final FileUpload upload_image =
 upload.getFileUpload();



 // create a byte array of the uploaded item

 byte[] bild = upload_image.getBytes();



 if(upload_image != null)

 {

   **write byte[] to database**

 }

   }

   catch (Exception e) { }

 }



 So far so good. Got my byte array stored. The source file is a jpeg
 image.
 I am not sure if I miss some kind cast here to let the system know what
 *sort* of byte array it should use.



 When I try to retrieve the image from the database, I use the following
 code:



   public ResourceReference getImage()

   {

 return new ResourceReference(some.class, bild)

 {

   public BufferedDynamicImageResource newResource()

   {

 try

 {

 // get the byte[] from DB

  byte[] bild = a.getBild();



 // create a buffered image template

  BufferedDynamicImageResource resource = new
 BufferedDynamicImageResource();

  BufferedImage image = new BufferedImage(200,
 200, BufferedImage.TYPE_INT_RGB);



 // transform the byte[] back to an image (does it work that way? How does

 // java know it was a jpeg before and not a gif for example?)

  java.awt.Image i = Toolkit.getDefaultToolkit
 ().createImage(bild);



  // convert image to buffered image

  image.getGraphics().drawImage(i, 0, 0,
 null);



  Graphics g = image.getGraphics();

  g.drawImage(i, 0, 0, null);

  g.dispose();



 // return the image

  resource.setImage(image);

  return resource;

 }

 catch 

Re: [Wicket-user] best practice for uploading and using content (images) with wicket?

2006-08-23 Thread Korbinian Bachl
this is Java - we have no pointers :P 

basically, if you want to get the data from a file you do it a bit different
as from a DB stream, if you look here, youll see the basic behind IO here:
http://www.physik.uni-muenchen.de/kurs/Computing/java/node36.html
(its german, so u will understand it easily)

Regards,

Korbinian




 -Ursprüngliche Nachricht-
 Von: [EMAIL PROTECTED] 
 [mailto:[EMAIL PROTECTED] Im Auftrag 
 von Sebastian Pflugbeil
 Gesendet: Mittwoch, 23. August 2006 11:24
 An: wicket-user@lists.sourceforge.net
 Betreff: Re: [Wicket-user] best practice for uploading and 
 using content (images) with wicket?
 
 
 Well, thanks a lot, thats really much more simple then i 
 figured =P. Maybe any pointers why the stream from the file 
 system doesnt work? ;)
 
 
 igor.vaynberg wrote:
  
  your problem is not retreiving the data from the db - it is 
 the weird 
  stuff you try to do when stream it back to the browser. why all the 
  awt image stuff? all you have to do is read the byte array 
 from the db 
  and stream it back to the browser.
  
  here is some pseudo code
  
  add(new Image(myimage) {
Resource getResource() { return new 
  ByteArrayResource(getBytesFromDb());
  }
  }
  
   
  
  if you really want to resize the image to 200x200 before 
 storing it in 
  the db or creating a thumbnail then i would look over that wiki 
  example and extract the resizing logic - but if all you 
 want to do is 
  stream it back then the above will do.
  
  -Igor
  
  
  On 8/22/06, Sebastian Pflugbeil 
  [EMAIL PROTECTED] wrote:
 
   Hi Wicket Team and Wicket Mailinglist!
 
 
 
  As this is my first post on this list, I would like to 
 introduce myself.
  My name is Sebastian and I am working on a university project, 
  comparing Java web frameworks. As you might guess, my 
 primary topic 
  is the Wicket framework ;). I am not what one would call a 
 programmer 
  or coder, I guess.
  Rather someone familiar with the underling concepts, but 
 sometimes a 
  bit lots with the actual implementations of a certain language. So 
  please excuse me, if my questions are stupid ;).
 
 
 
  My problem at this moment is the following. I need to implement a 
  feature in wicket that lets me upload images to a webpage and then 
  use those images to be displayed on certain pages. It 
 doesn't really 
  matter if the images are stored on the file system or in a 
 database. 
  I am not looking for a solution to an explicit problem but 
 rather for 
  a best practice that shows how the wicket framework 
 supports such a 
  feature.
 
 
 
  I have tried to read up on anything I could find addressing such a 
  feature. But everything I got so far is either way beyond 
 my scope of 
  understanding, not offering enough to archive the goal or just not 
  working as I understand it should.
 
 
 
  I have tried to read the example in the wiki ( 
  
 http://www.wicket-wiki.org.uk/wiki/index.php/*UploadDownload*http://
  www.wicket-wiki.org.uk/wiki/index.php/UploadDownload),
  but I can not really follow it. Too many libraries used 
 that are not 
  included and overall to confusing for a non professional 
 like myself.
 
  I did understand the example for the upload in the 
 wikiexamples though.
  No
  problems writing files to disk or even to database, following that 
  example code.
 
 
 
  My attempt to store images in the Database is looking 
 something like
  this:
 
 
 
  To write to the Database, I use this code sniped:
 
 
 
  public final void onSubmit()
 
  {
 
try
 
{
 
  // get the content of the upload field
 
  final FileUpload upload_image = 
  upload.getFileUpload();
 
 
 
  // create a byte array of the uploaded item
 
  byte[] bild = upload_image.getBytes();
 
 
 
  if(upload_image != null)
 
  {
 
**write byte[] to database**
 
  }
 
}
 
catch (Exception e) { }
 
  }
 
 
 
  So far so good. Got my byte array stored. The source file 
 is a jpeg 
  image.
  I am not sure if I miss some kind cast here to let the system know 
  what
  *sort* of byte array it should use.
 
 
 
  When I try to retrieve the image from the database, I use the 
  following
  code:
 
 
 
public ResourceReference getImage()
 
{
 
  return new ResourceReference(some.class, bild)
 
  {
 
public BufferedDynamicImageResource newResource()
 
{
 
  try
 
  {
 
  // get the byte[] from DB
 
   byte[] bild = a.getBild();
 
 
 
  // create a buffered image template
 
   BufferedDynamicImageResource 
 resource = 
  new BufferedDynamicImageResource

Re: [Wicket-user] best practice for uploading and using content (images) with wicket?

2006-08-23 Thread Igor Vaynberg
or look at the source of DownloadLink as it streams a file from disk-IgorOn 8/23/06, Korbinian Bachl 
[EMAIL PROTECTED] wrote:this is Java - we have no pointers :Pbasically, if you want to get the data from a file you do it a bit different
as from a DB stream, if you look here, youll see the basic behind IO here:http://www.physik.uni-muenchen.de/kurs/Computing/java/node36.html
(its german, so u will understand it easily)Regards,Korbinian -Ursprüngliche Nachricht- Von: [EMAIL PROTECTED]
 [mailto:[EMAIL PROTECTED]] Im Auftrag von Sebastian Pflugbeil Gesendet: Mittwoch, 23. August 2006 11:24
 An: wicket-user@lists.sourceforge.net Betreff: Re: [Wicket-user] best practice for uploading and using content (images) with wicket?
 Well, thanks a lot, thats really much more simple then i figured =P. Maybe any pointers why the stream from the file system doesnt work? ;) igor.vaynberg wrote: 
  your problem is not retreiving the data from the db - it is the weird  stuff you try to do when stream it back to the browser. why all the  awt image stuff? all you have to do is read the byte array
 from the db  and stream it back to the browser.   here is some pseudo code   add(new Image(myimage) {  Resource getResource() { return new
  ByteArrayResource(getBytesFromDb());  }  } if you really want to resize the image to 200x200 before storing it in  the db or creating a thumbnail then i would look over that wiki
  example and extract the resizing logic - but if all you want to do is  stream it back then the above will do.   -IgorOn 8/22/06, Sebastian Pflugbeil 
  [EMAIL PROTECTED] wrote:  Hi Wicket Team and Wicket Mailinglist! 
As this is my first post on this list, I would like to introduce myself.  My name is Sebastian and I am working on a university project,  comparing Java web frameworks. As you might guess, my
 primary topic  is the Wicket framework ;). I am not what one would call a programmer  or coder, I guess.  Rather someone familiar with the underling concepts, but
 sometimes a  bit lots with the actual implementations of a certain language. So  please excuse me, if my questions are stupid ;).   
  My problem at this moment is the following. I need to implement a  feature in wicket that lets me upload images to a webpage and then  use those images to be displayed on certain pages. It
 doesn't really  matter if the images are stored on the file system or in a database.  I am not looking for a solution to an explicit problem but rather for  a best practice that shows how the wicket framework
 supports such a  feature. I have tried to read up on anything I could find addressing such a  feature. But everything I got so far is either way beyond
 my scope of  understanding, not offering enough to archive the goal or just not  working as I understand it should. I have tried to read the example in the wiki (
  http://www.wicket-wiki.org.uk/wiki/index.php/*UploadDownload*http://  
www.wicket-wiki.org.uk/wiki/index.php/UploadDownload),  but I can not really follow it. Too many libraries used that are not  included and overall to confusing for a non professional
 like myself.   I did understand the example for the upload in the wikiexamples though.  No  problems writing files to disk or even to database, following that
  example code. My attempt to store images in the Database is looking something like  this:  
   To write to the Database, I use this code sniped: public final void onSubmit()   {
   try   {   // get the content of the upload field 
  final FileUpload upload_image =  upload.getFileUpload(); // create a byte array of the uploaded item
   byte[] bild = upload_image.getBytes(); if(upload_image != null) 
  {   **write byte[] to database**   }   }
   catch (Exception e) { }   } So far so good. Got my byte array stored. The source file
 is a jpeg  image.  I am not sure if I miss some kind cast here to let the system know  what  *sort* of byte array it should use. 
When I try to retrieve the image from the database, I use the  following  code: public ResourceReference getImage()
   {   return new ResourceReference(some.class, bild)   {   public BufferedDynamicImageResource newResource()
   {   try   {   // get the byte[] from DB
  byte[] bild = a.getBild(); // create a buffered image template  BufferedDynamicImageResource
 resource =  new BufferedDynamicImageResource();  BufferedImage image = new  BufferedImage(200, 200, BufferedImage.TYPE_INT_RGB
); // transform the byte[] back to an image (does it work that way? How  does   // java know it was a jpeg before and not a gif for example?)
  java.awt.Image i =  Toolkit.getDefaultToolkit ().createImage(bild);// convert image to buffered image
   image.getGraphics().drawImage(i, 0, 0,  null);Graphics g = image.getGraphics
();  g.drawImage(i, 0, 0, null);  g.dispose();   
  // return the image  resource.setImage(image);  return resource; 
  }   catch (Exception e) { }   }   };
   } This leads

Re: [Wicket-user] best practice for uploading and using content (images) with wicket?

2006-08-22 Thread Eelco Hillenius
Hi,

I haven't read through your whole email, but the cdapp example in
wicket-contrib-examples which you can find in the wicket-stuff
repository has functionality for uploading an image (edit details of a
cd), which is then stored in the database. That image is then
displayed as a thumbnail and the full image is displayed in a popup
when you click on the image.

I suggest you check that example out and see whether that helps you.

Rgds,

Eelco

-
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnkkid=120709bid=263057dat=121642
___
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user


Re: [Wicket-user] best practice for uploading and using content (images) with wicket?

2006-08-22 Thread Igor Vaynberg
your problem is not retreiving the data from the db - it is the weird stuff you try to do when stream it back to the browser. why all the awt image stuff? all you have to do is read the byte array from the db and stream it back to the browser.
here is some pseudo codeadd(new Image(myimage) { Resource getResource() { return new ByteArrayResource(getBytesFromDb()); }}img wicket:id=myimage width=200 height=200/
if you really want to resize the image to 200x200 before storing it in the db or creating a thumbnail then i would look over that wiki example and extract the resizing logic - but if all you want to do is stream it back then the above will do.
-IgorOn 8/22/06, Sebastian Pflugbeil [EMAIL PROTECTED]
 wrote:












Hi Wicket Team and Wicket Mailinglist!



As this is my first post on this list, I would like
to introduce myself. My name is Sebastian and I am working on a university
project, comparing Java web frameworks. As you might guess, my primary topic is
the Wicket framework ;). I am not what one would call a programmer or coder, I guess.
Rather someone familiar with the underling concepts, but sometimes a bit lots
with the actual implementations of a certain language. So please excuse me, if
my questions are stupid ;).



My problem at this moment is the following. I need to
implement a feature in wicket that lets me upload images to a webpage and then
use those images to be displayed on certain pages. It doesn't really
matter if the images are stored on the file system or in a database. I am not looking
for a solution to an explicit problem but rather for a best practice that shows
how the wicket framework supports such a feature.



I have tried to read up on anything I could find addressing
such a feature. But everything I got so far is either way beyond my scope of
understanding, not offering enough to archive the goal or just not working as I
understand it should. 



I have tried to read the example in the wiki (
http://www.wicket-wiki.org.uk/wiki/index.php/
UploadDownload),
but I can not really follow it. Too many libraries used that are not included
and overall to confusing for a non professional like myself.

I did understand the example for the upload in the
wikiexamples though. No problems writing files to disk or even to database,
following that example code. 



My attempt to store images in the Database is looking
something like this:



To write to the Database, I use this code sniped:



 public
final void onSubmit()

 {

 try

 {

 //
get the content of the upload field

 final
FileUpload upload_image = upload.getFileUpload();

 

 //
create a byte array of the uploaded item

 byte[]
bild = upload_image.getBytes(); 

 

 if(upload_image
!= null)

 {

 
*write byte[] to database* 

 }

 }

 catch
(Exception e) { }

 }



So far so good. Got my byte array stored. The source
file is a jpeg image. I am not sure if I miss some kind cast here to let the
system know what *sort* of byte array it should use.



When I try to retrieve the image from the database, I
use the following code:



 public
ResourceReference getImage()

 {

 return
new ResourceReference(some.class, bild)

 {

 public
BufferedDynamicImageResource newResource() 

 {

 try

 {

// get
the byte[] from DB

 byte[]
bild = a.getBild();

 

// create
a buffered image template

 BufferedDynamicImageResource resource = new
BufferedDynamicImageResource();

 BufferedImage
image = new BufferedImage(200, 200, BufferedImage.TYPE_INT_RGB);

 

//
transform the byte[] back to an image (does it work that way? How does

//
java know it was a jpeg before and not a gif for example?)

 java.awt.Image
i = Toolkit.getDefaultToolkit().createImage(bild);

 

 //
convert image to buffered image

 image.getGraphics().drawImage(i,
0, 0, null);

 

 Graphics
g = image.getGraphics();

 g.drawImage(i,
0, 0, null);

 g.dispose();

 

//
return the image

 resource.setImage(image);

 return
resource;

 }

 catch
(Exception e) { }

 }

 };

 }



This leads to a black box in the place my image is
supposed to be. So I guess somewhere along the way I lose my image information.
My best guess is, that the problem lies in the image conversion. Jpeg isn't
a java.awt.image, I suppose.



But still leaves the question, does wicket offer
anything more to me to help me here? To make things (even) simpler for me?





The next attempt I took was storing images on the
file system. This went pretty well, as it pretty much is covered by the upload
example from the wicket examples. I was able to put the files in pretty much
any directory I liked, following that code. The problems started once again,
when I tried to retrieve and reuse the stored data. In the past I did a bit of PHP
programming and was used to just store my things anywhere on the web server as
a file and access them again via URL. This doesn't really work for me in the
java world (using jboss application server, ejb3, wicket), as the resources are
stored in archives and not easily written to