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.

XML error: undefined entity at line 19
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%.

Linux Vendors Head to the Cloud in Search of Cash
iPhone 3GS: Overheating Fears, OS Update Nears
PostgreSQL 8.4 Revs Up Database Admin, Security
PHP 5.3 Accelerates PHP
Sun Releases NetBeans 6.7 IDE for Java, PHP
Why Firefox Doesn't Take Google Chrome Features
First Major PHP Update in Years Coming Soon
Red Hat CEO Calls on Oracle to Keep Java Open
Google Widens AdSense for iPhone, Android Apps
Eclipse Galileo Releases 33 Open Source Projects

A Taste of JavaFX for the Uninitiated
A Guide to Caching and Compression for High Performance Web Applications
How User-Centered Design Can Put User Stories in Proper Context
Explore C# 4's New Dynamic Types and Named/Optional Parameters
Enterprise Architecture: The Journey Begins Here, Part 2
Create a Syslog Sender/Receiver Using the MS Winsock Control
AMD CodeAnalyst Helps Developers Optimize and Tune Applications
Securing Microsoft's Cloud Infrastructure
Introducing the Azure Services Platform
An Introduction to Microsoft .NET Services for Developers

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, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs