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

8.5. Validating an Indexed Property

Problem

You want to validate a field that is a nested property of an object in an array or Collection.

Solution

Set the indexedListProperty attribute for the field element to the name of the property that returns the array or Collection. The value of the property attribute will be interpreted as the name of a nested property of an element within the Collection. If you're using Struts 1.2, you can reference the indexed property in a test for a validwhen rule. Example 8-5 shows a complete form element from validation.xml for a form containing the array property "orders."

Example 8-5. Validations for an indexed list property (partial)

<form name="IndexedListForm"> <field property="partNumber" indexedListProperty="orders" depends="minlength"> <arg position="0" key="prompt.partNumber"/> <arg position="1" key="${var:minlength}" resource="false"/> <var> <var-name>minlength</var-name> <var-value>5</var-value> </var> </field> <field property="quantity" indexedListProperty="orders" depends="intRange,validwhen"> <arg position="0" key="prompt.quantity"/> <arg position="1" key="${var:min}" resource="false"/> <arg position="2" key="${var:max}" resource="false"/> <msg name="validwhen" key="error.quantity.invalid"/> <var> <var-name>min</var-name> <var-value>5</var-value> </var> <var> <var-name>max</var-name> <var-value>20</var-value> </var> <var> <var-name>test</var-name> <var-value> (((orders[].partNumber != null) and (*this* != null)) or ((orders[].partNumber == ...
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