Solved

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

Posted on 2004-08-25
6
1,453 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
xjc and jaxb 2 95
java.util.concurrent.locks in java 3 204
servlet cookie finding by name 1 90
SimpleDateFormat.parse examples 19 113
Facebook has became the #1 social media platform. People share many funny videos there, yet you don't know how to download them? Now you can download Videos from Facebook in just 3 simple steps.
Azure Functions is a solution for easily running small pieces of code, or "functions," in the cloud. This article shows how to create one of these functions to write directly to Azure Table Storage.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

756 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