What would happend if I use this <html:text indexed="true" property="something">
The spec says the generated html tag will have a name attribute of the format 'id[index].propertyName'. I know the 'index' comes from the enclosing logic:iterate tag and the 'propertyName' is the value of the property= attribute. But where does 'id' come from? I tried this myself & got 'org.apache.struts.taglib.html.BEAN' used as the 'id' which is the attribute name of the FormBean corresponding to the enclosing <html:form> tag!
I know the 'indexed=true' attribute is needed to work with Indexed Properties and LazyActionForm but it seems that it was never properly documented.
The id refers to the id attribute of the enclosing <logic:iterate> tag. Here's an example.
Suppose you have a Customer bean with name, address and customerNumber properties, and that you have a List of these customer beans as a property of your ActionForm bean. In order to use indexed properties, you will have to create an indexed getter and setter for an individual customer in the list like this:
Struts would then create a property name of customer[index].customerNumber. There's one more thing: If your ActionForm is in request scope, you will have to give your indexed getter "lazy initialization" capability. This link will explain how to do that.
For the group of tags that includes html:text, it says: these tags will generate an HTML "name" attribute of "name[nn].property"
It took me a long time to figure out something that is mentioned in the wiki page that Merrill linked: "The trick is to name the id attribute to the same as the indexed property."
Notice how in Merrill's example he has an id value of "customer" a name value of "customer" and a method named getCustomer.
Joined: Jan 28, 2004
Thanks. It also me a very long time to figure what is going on with this single attribute! Another question, why would we ever want to use indexed Properties in the Form bean?
Joined: Feb 08, 2006
Indexed properties is a topic that comes up often on this forum. An example would be a shopping checkout page where you had a list of products in the person's shopping bag and you had a text field on each line where the user could change the quantity. This type of example where you have a variable number of items to edit is a perfect use for indexed properties.