Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2004-08-25
6
Medium Priority
?
1,527 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 1000 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 1000 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
There can be many situations demanding the conversion of Outlook OST files to PST format and as such, there is no shortage of automated tools to perform this conversion. However, what makes Stellar OST to PST converter stand above the rest? Let us e…
Integration Management Part 2
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month10 days, 9 hours left to enroll

885 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