How to add an image to a Component

Version 5.1 by Lachlan Scott on 2007/07/12 19:05

Problem: you want to add an image to the HTML page of a Component; being an highly skilled application developer with the good sense to apply your talents with WebObjects emoticon_grin , you expect to do this by using the <img src=" "> tag in the HTML, and are confused as to how to achieve it in WebObjects.

Discussion: WebObjects provides the WOImage tag to manage images in component pages which obviates the 'img' tag, and which can be somewhat unintuitive for the beginning WO developer. The tag supports all the expected HTML img attributes as far as I can tell; needs checking and the 'filename' attribute which references the location of the image to WebObjects. The images themselves must

Question: Yeah, but why can't I just make a static reference in the usual way? Well actually, you can link required, but you don't really want to explanation required: load balancing, web server resources, etc, and the WOImage tag is an elegant solution that you will come to appreciate in time; trust us, we're doctors. Well, some of us are, anyway.&nbsp;;-)

Solution:

  1. Create a suitable image directory structure in your project
  2. Import the image into the directory of your choice
  3. Add the WOImage tag to your page
  4. Reference the image using the 'filename' attribute


  1. Create a suitable image directory structure in your project
    1. In Eclipse Package Explorer, right-click the project and select&nbsp; New > Folder (see image) and name the folder something appropriate such as 'images'
    2. Proceed in this way, building the structure you want

In the WOLips perspective, double-click the component to which you want to add the image