Subject: Image button documentation
From: "Monker" <[EMAIL PROTECTED]>
 ===
I was asked by my company to create some documents on 'hints and tricks' for
Struts...The first thing that came to mind was image buttons since that was
the first stumbling block I hit when writing my first JSP in Struts...

I was wondering if I could get some feedback on this, and maybe verify that
what I say is accurate since I have not been using Struts for very long...

Image Buttons

An image button is a graphic on a JSP which has a link attached to it.  In
HTML, it would look something like this:

<A href="http://www.somepage/";><IMG src="somepath/someimage.jpg" width="113"
height="27" border="0"></A>

The above code will display the someimage.jpg graphic.  When you click on
it, the browser is forwarded to http://www.somepage/

To use Struts correctly, this should be handled in a similar way to a submit
button.  When you click on the graphic, it should go back to the server and
to the action class.  The action class should determine what button was
clicked and what specific action to take, including forwarding to a new
page.

When the code above is written using the Struts image button tag, it will
look like this:

<html:image src="somepath/someimage.jpg" property="imagebutton"
value="go"></html:image>

In your action class you then need to check to see if the button was
clicked.  If you are familiar with how Struts uses submit buttons you may
assume you check the value of the property "imagebutton", and if it is "go",
the button was clicked.   This is a logical assumption, but an image button
works slightly differently then a submit button.

An image button does not return a value.  Instead, it returns the x/y
coordinates of the mouse click.  To do this Struts will create two
properties using the property name you gave in the image tag in the JSP.  In
the above example "imagebutton.x" and "imagebutton.y" are created.  By
default, these properties will not exist until the image button is clicked.
So, to check to see if the above image button was clicked, you would add
this code to your action class:

    if (request.getParameter("imagebutton.x") != null) {
       return (mapping.findForward("buttonclicked"));
    }

The above code will check to see if the "imagebutton.x" property was
created, if so it will return to the struts-config.xml file and forward to
whatever path is under the forward name of "buttonclicked".




--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to