Java Reference
In-Depth Information
and contact4 ), and we'd have to assemble the list of contacts ourselves.
Indexed properties make it all much easier.
What's even cooler about indexed properties is that Stripes is smart
enough to ignore rows that are left completely empty. In the example
from Figure 9.3 , on the preceding page, say we made email a required
field. In a row where the user enters a first name but no email, Stripes
would trigger a validation error. But in other rows where the user left
all the fields blank, Stripes would just ignore the row altogether. This
way, we can make the email a required field without forcing the user to
fill in every row of fields.
We can also use a Map to work with indexed properties. In that case,
the value between the square brackets, [ ], is the key in the map. Since
order does not matter in a map, only the fields filled in by the user will
generate key-value pairs in the map. Even if the user enters a value in
the second field and leaves the first field blank, the map will not contain
any null entries.
Finally, we can use more than one level of indexed properties. For exam-
ple, with an action bean property named contacts of type Map<String,List
<Contact>> , we could use these indexed properties:
contacts['to'] [0].email
contacts['to'] [1].email
contacts['to'] [2].email
contacts['cc'] [0].email
contacts['cc'] [1].email
contacts['cc'] [2].email
If the user enters values in the fields such that the parameters have
these values:
contacts['to'] [0].email=fred@stripesbook.org
contacts['to'] [1].email=nadia@stripesbook.org
contacts['cc'] [0].email=lily@stripesbook.org
then the contacts property in the action bean would be populated as
follows:
contacts = {
"to" = [
Contact(email=fred@stripesbook.org),
Contact(email=nadia@stripesbook.org)
],
"cc" = [
Contact(email=lily@stripesbook.org)
]
}
 
 
Search WWH ::




Custom Search