advertisement
javaboutique
Search Tips
Articles  |   Tutorials  |   Reviews  |   Tools  |   by Category  |   by Date  |   by Name  |   Submit  |   Source  |   Forums  |  
javaboutique
Browse DevX


Partners & Affiliates











advertisement

Tutorials : Advanced Forms Handling in Struts 1.1 :

Advanced Forms Handling in Struts 1.1

by Keld H. Hansen

Introduction

This article is about the more advanced features Jakarta Struts offers in building HTML forms. If you know how to create forms in plain HTML then the step to building simple forms in Struts with, for example, a couple of input text fields, a checkbox or a radio button is not very complicated. When it comes to the more complex controls like the multi-valued selection list or a variable length list of input fields it gets more challenging. This is especially true when the possible selections are not fixed, but taken from some external source like a database instead. I've too often found myself struggling with the syntax and semantics of the HTML-tags when the forms get complex, and if you search the web for advice, you'll soon see that you have to collect information from many sources.

In this article I've tried to collect solutions to the most common non-trivial cases. Every case, of course, is not covered here. Remember to also read Struts' own documentation, starting with the documentation for the HTML-tags. You might find what you need there.

At the end of the article is a table with an overview of the solutions. I'm sure you'll find it useful when coding your Struts applications.

Here's a link to a zip file containing all the examples shown in the article.

The controls in a form

Here is a list of the most commonly used input controls:

Type Look Values
1. Text field Anything that can be typed in.
One line
2. Text area field Anything that can be typed in.
Several lines.
3. Checkbox 1 of 2 (yes/no - on/off)
4. Radio button 1 of many fixed values
5. Selection list -
single type
1 of many fixed values.
Gives you the same functionality as the radio buttons, only the presentation differs.
 
6. Selection list -
multiple type
Several of many fixed values
7. List of checkboxes Several of many fixed values.
Gives you the same functionality as the multi selection list, only the presentation differs.  

In Struts you define a control with a tag from Struts' HTML- library. The next table shows how these are mapped to the old, well-known HTML tags:

Type Struts html-tag HTML tag
1. Text field <html:text property="firstname"/> <input type="text" name="firstname">
2. Text area field <html:textarea property="address"/> <textarea name="address">
3. Checkbox <html:checkbox property="married" value="yes"/> <input type="checkbox" name="married" value="yes">
4. Radio button <html:radio property="card"
value="Diners"/> . . .
<input type="radio" name="card" value="Diners"> . . .
5. Selection list -
single type
<html:select property="country"> and
<html:option value="F"/> . . .
<select name="country">
<option value="F"> . . .
6. Selection list -
multiple type
<html:select property="food" multiple="true"> and
<html:option value="milk"/> . . .
<select name="food" multiple>
<option value="milk"> . . .
7. List of checkboxes <html:multibox property="site">
. . .
<input type="checkbox" name="site" value="jb">
<input type="checkbox" name="site" value="oj">
. . .

How to Add Java Applets to Your Site

New on the Java Boutique:

New Review:

Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling API boasts simplicity, ease-of-integration, a well-rounded feature set, and it's free!

New Applet:

Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA sequences into three useful formats.

Elsewhere on internet.com:

WebDeveloper Java
Lots of Java information on webdeveloper.com

WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.

ScriptSearch Java
Hundreds of free Java code files to download.

jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.

 Microsoft Visual Studio 2010 Showcase
 Avaya Developer Showcase
 MSDN Spotlight
 PHP for Windows Showcase
XML error: undefined entity at line 39
advertisement
Receive Articles via our XML/RSS feed
Receive Articles via our XML/RSS feed

JavaBytes
Internet Cyclone
This powerful, easy-to-use, internet optimizer is for Windows 95, 98, ME, NT, 2000 and XP. It's designed to automatically optimize your Windows settings, boosting your Internet connection up to 200%.

Windows 7: From Beta to Final Code in One Year
Google Shows Off Chrome OS, Releases Source
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?
Fedora 12 Takes Aim at Linux Networking
Top Supercomputer Nearly Doubles in Speed
Fedora 12 Linux Tackles Virtualization
Apple Gives iPhone Developers App Status Tracker
Novell Sets OpenSUSE 11.2 Free

Creating Custom Export Filters for StarOffice with XSLT
WPF Wonders: Using DataTemplates
Crystal Reports Family Offers Options for Developers
Avaya Aura Session Manager video
Avaya Aura Overview video
Exploring HTML 5's Audio/Video Multimedia Support
Overriding Virtual Functions? Use C++0x Attributes to Avoid Bugs.
Understanding the Cloud Computing Security Vulnerabilities
Cisco and IBM Target a Greener World
Upgrade to Visual Studio 2010 with the Ultimate Offer

Advertising Info  |   Member Services  |   Contact Us  |   Help  |   Feedback  |   Site Map  |   Network Map  |   About

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs