Skip to Main Content
Jakarta Struts Cookbook
book

Jakarta Struts Cookbook

by Bill Siggelkow
February 2005
Intermediate to advanced content levelIntermediate to advanced
528 pages
12h 53m
English
O'Reilly Media, Inc.
Content preview from Jakarta Struts Cookbook

5.5. Lazy Dynamic Action Forms

Problem

You want to create a form where the properties are variable and completely determined at runtime.

Solution

Use Niall Pemberton's Lazy DynaBean forms available for download from http://www.niallp.pwp.blueyonder.co.uk/.

Declare the form-bean to use in the struts-config.xml:

<form-bean name="LazyForm" type="lib.framework.struts.LazyValidatorForm"/>

Then, use the form on a JSP page as you would a normal ActionForm. Example 5-8 shows a JSP page (lazy_form_test.jsp) that will utilize the LazyForm declared previously.

Example 5-8. Using the LazyValidatorForm on an HTML form

<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix= "html" %> <%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix= "bean" %> <html> <head> <title>Struts Cookbook - Chapter 5 : Lazy Form</title> </head> <body> <h2>Lazy Form Test</h2> <html:form action="/ProcessLazyForm"> What is your name:<br /> First Name: <html:text property="firstName"/><br /> Last Name: <html:text property="lastName"/><br /> Do you want to subscribe to our newsletter?<br /> <html:checkbox property="subscribe"/><br /> Who are your 3 friends:<br /> Friend 1: <html:text property="friend[0].name"/><br /> Friend 2: <html:text property="friend[1].name"/><br /> Friend 3: <html:text property="friend[2].name"/><br /> <html:submit/> </html:form> <hr /> Your name is: <bean:write name="LazyForm" property="firstName"/>&nbsp; <bean:write ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Programming Jakarta Struts

Programming Jakarta Struts

Chuck Cavaness
Beginning Spring Framework 2

Beginning Spring Framework 2

Bruce Snyder, Sing Li, Anne Horton, Thomas Van de Velde, Naveen Balani, Christian Dupuis
Java Cookbook

Java Cookbook

Ian F. Darwin
Struts 2 in Action

Struts 2 in Action

J. Scott Stanlick, Chad Michael Davis, Donald J. Brown

Publisher Resources

ISBN: 059600771XSupplemental ContentErrata Page