Use ImageButtonBean for Image based Form Submits in Struts

By: Lakshmi Emailed: 1645 times Printed: 2119 times    

Latest comments
By: rohit kumar - how this program is work
By: Kirti - Hi..thx for the hadoop in
By: Spijker - I have altered the code a
By: ali mohammed - why we use the java in ne
By: ali mohammed - why we use the java in ne
By: mizhelle - when I exported the data
By: raul - no output as well, i'm ge
By: Rajesh - thanx very much...
By: Suindu De - Suppose we are executing

Whenever a form is submitted via <input type=”image” name=”save” />, two request parameters save.x and save.y – corresponding to x and y coordinates are submitted. We don’t worry about the exact value of the coordinates since we are not using mage maps. Instead the mere presence of save.x and/or save.y indicates that the form was submitted via the save image button. We combine this concept with Struts support for nested properties:

a. Add two fields named save and cancel to CustomerForm. Both fields are of type ImageButtonBean. Add getter methods for each.

b. Remove the step field and its getters and setters. We will not use it anymore.

c. Change the CustomerAction to use the following check in its execute() method, instead of the form.getStep().equals(“Save”):

form.getSave().isSelected()

This method checks if the save button is used for form submission.

d. Similarly the isCancelled() method will not work since the Struts supplied cancel button checks for pre defined request parameter. We now have to replace it with:

form.getCancel().isSelected()

e. Also since we are not using the pre-defined Cancel button anymore, the validate() method in CustomerForm will run for Cancel too. Hence add the code to bypass validation for Form Cancellation.

f. In the CustomerForm.jsp, add the following for the image buttons:
<html:form>
..
..
..

<html:image property="save"
srcKey="image.save"
altKey="image.save.alttext" />
<html:image property="cancel"
srcKey="image.cancel"
altKey="image.cancel.alttext" />

..
</html:form>

g. Define the srcKey and altKey for both images in the Resource Bundles

image.save=images/save.gif
image.save.alttext=Save the Form
image.cancel=images/cancel.gif
image.cancel.alttext=Cancel Submission


Struts Home | All Struts Tutorials | Latest Struts Tutorials

Sponsored Links

If this tutorial doesn't answer your question, or you have a specific question, just ask an expert here. Post your question to get a direct answer.



Bookmark and Share

Comments(0)


Be the first one to add a comment

Your name (required):


Your email(required, will not be shown to the public):


Your sites URL (optional):


Your comments:



More Tutorials by Lakshmi
Exporting a Certificate Authenticating Your Public Key example using keytool in Java
while and do-while example in Java
Common SQL Commands
Data Access Technologies in Java
perror() Function - example program in C
Struts-GUI and Struts Console
Variable-length Argument Lists sample program in C
#if, #elif, #ifndef, #ifdef in C (Conditional Inclusion)
Use ImageButtonBean for Image based Form Submits in Struts
break and continue loops in C
Arguments - Call by Value in C
Using command-line arguments in C++
How to handle Exceptions in C++
Gauge sample program in J2ME
What is Reflection? - getConstructors(), getFields(), and getMethods()

More Tutorials in Struts
Configuring JDBC DataSources in Struts
Struts Classes
FAQ: Why was reload removed from Struts (since 1.1)?
FAQ: Why are my checkboxes not being set from ON to OFF?
Using JavaScript to submit a form in Struts
How to prepopulate a form in Struts
Simple example of using the requiredif Validator rule in Struts
Chaining actions in Struts
When is the best time to validate input in Struts
What is a Plug-in and how to use Java plug-ins with Struts?
7 Best Practices of Struts
Origin and Architecture of Struts
ActionErrors and ActionError in Struts
Tutorial on Struts Configuration File - struts-config.xml in Struts - from the book: Struts Survival Guide. Basics to Best Practices
Handling multiple buttons in HTML Form in Struts

More Latest News
Most Viewed Articles (in Struts )
Tutorial on Struts Configuration File - struts-config.xml in Struts - from the book: Struts Survival Guide. Basics to Best Practices
Struts 1 vs Struts 2
Struts and Tiles - Steps to use Struts and Tiles
ActionErrors and ActionError in Struts
Handling Duplicate Form Submissions in Struts
What is Struts? Which Version of Struts to use?
Model 1 Architecture
Configuring JDBC DataSources in Struts
ForwardAction in Struts
Struts-GUI and Struts Console
Installing and configuring Tomcat and Struts
Creating Struts Modules
Using Multiple Message Resource Bundles in Struts
Use ImageButtonBean for Image based Form Submits in Struts
DispatchAction in Struts
Most Emailed Articles (in Struts)
History of Struts
The directories and files of a Struts application
ActionErrors and ActionError in Struts
Using Checkbox & Radio Tags, html:select, html:options in Struts Forms
What is a Model View Controller (MVC) Model?
Creating the first application using Struts 2
Installing and configuring Tomcat and Struts
Model 1 Architecture
Using Multibox in Struts
ForwardAction in Struts
Using JavaScript to submit a form in Struts
WebWork 2 is now Apache Struts 2
Struts 1 vs Struts 2
Introduction to Struts Architecture
Creating Struts Modules