Solved

Struts 1.1 - Problem with html:cancel tag and using graphic button

Posted on 2004-08-25
6
1,420 Views
Last Modified: 2008-01-09
I am creating a web app using Tomcat v3.3 (forced to use this version), JDK v 1.3, and Struts v1.1.  I have a JSP that uses both a Form class/object and Action class/object .  The JSP also does Struts validation via the validation.xml file, so the Form class extends ValidatorForm.  The JSP has both a Submit and Cancel button.

I want to use a custom graphic button for both the Submit and Cancel button.  The Submit button was easy.  We just used this statement:

<html:image property="submit" src="images/button-submit.gif" />

The Cancel button isn't turning out to be so easy.  Here is our current statement:

<html:cancel><bean:message key="button.cancel" /></html:cancel>

So I am using the html:cancel tag to disable the Struts validation check on a cancel (this works fine).  Now I want to add a graphic button, BUT still be able handle the cancel and disable the Struts validation check.  Ideally, I would like to keep the cancel tag and just add an image (or img) tag or attribute to add the graphic button but I can't seem to get this to work (it echos the HTML text on the JSP display).  So for example I have tried:

<html:cancel><img src="images/button-cancel.gif" /></html:cancel>

and using the <html:image...> tag but these do not seem to work.  Has anyone come up with a solution for this?

Thanks!
0
Comment
Question by:mbeede
  • 3
  • 2
6 Comments
 
LVL 35

Assisted Solution

by:TimYates
TimYates earned 250 total points
ID: 11900261
Ooooooh!  From:  http://cvs.theospi.org:12443/viewrep/~raw,r=1.7.2.4/cvs/portfolio/web/shareDeleteConfirm.jsp

<input type="image" src="images/button-cancel.gif" name="org.apache.struts.taglib.html.CANCEL" value="submit" alt="Cancel this action">

Apparently, setting the name to that, makes struts treat it as a cancel action...

Apparently... :-/

Hope it works!

Tim
0
 
LVL 14

Accepted Solution

by:
boonleng earned 250 total points
ID: 11900438
To disable to struts javascript validator, you need to add 'bCancel=true' to onclick event.
you can try the following codes:-

<html:image property="<%=org.apache.struts.taglib.html.Constants.CANCEL_PROPERTY%>" onclick="bCancel=true" src="images/button-cancel.gif"/>

or

<html:image property="org.apache.struts.taglib.html.CANCEL" onclick="bCancel=true" src="images/button-cancel.gif"/>


Regards,
Boon Leng
0
 
LVL 35

Expert Comment

by:TimYates
ID: 11900463
> <html:image property="org.apache.struts.taglib.html.CANCEL" onclick="bCancel=true" src="images/button-cancel.gif"/>

should be

<html:image name="org.apache.struts.taglib.html.CANCEL" onclick="bCancel=true" src="images/button-cancel.gif"/>

surely?  (name, not property)
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 14

Expert Comment

by:boonleng
ID: 11900861
Attribute 'name' is refering to the bean name.
Attribute 'property' is the refering to input name.

0
 

Author Comment

by:mbeede
ID: 11917779
FINALLY got this working.  Thanks for your help guys!  

NOTE TO OTHERS: If you use the <html:image...> tag to resolve this, the request parameter that Struts sends to your action is actually "org.apache.struts.taglib.html.CANCEL.x" (note the .x tacked on to the end).  They do this because apparently the parameter value holds the x-coordinate of the mouse position on the button that was selected.  A (.y) parameter is sent as well to hold the y-coordinate.  This was what was causing our code not to work.  Once we added the graphic image the request parameter changed on us.    

We extend the Action class (our class is called AbstractClass) to handle processing that is common to all actions, including cancel processing BUT were only checking if the parameter was "org.apache.struts.taglib.html.CANCEL".  

Thanks again for your help!
0
 
LVL 35

Expert Comment

by:TimYates
ID: 11939552
Yeah...the .x and .y is part of the HTML specification (and a real pain in the butt) :-(

Glad you got this working!!!

Good luck!!

Tim
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

A Short Story about the Best File Recovery Software – Acronis True Image 2017
In this article, I will show you HOW TO: Perform a Physical to Virtual (P2V) Conversion the easy way from a computer backup (image).
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now