February 2005
Intermediate to advanced
528 pages
12h 53m
English
You want to create a form where the properties are variable and completely determined at runtime.
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"/> <bean:write ...