struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Taylor, Jason" <>
Subject RE: Nested Indexed Property
Date Sun, 22 Sep 2002 15:24:02 GMT
OK, I think I see what you're trying to do better now.  Email really is one
of the worst possible ways to discuss things of technical subtlety, but it's
all we got, so patience and careful reading is sometimes required...

Instead of trying to generate a list of objects with a logic:iterate that
are then sent as request parameters to the Action and used by the controller
to populate the ActionForm, you seem to be trying to refer to an index on a
list of objects that exists already.  If I'm wrong, then let me know and
I'll suggest something else.  Otherwise, I have the following

You may want to refer to some unique identifier rather than using the array
index.  Or make the index a property of the object which is essentially the
same thing.

That way, you can do things like use <html:select> to specify the value of
the identifier, and <html:options> to specify the collection of objects.  

In your case, you'd select a customer id/index on the first page which would
correspond to the property used by the <html:select> on the second.  The
collection used by <html:options> is your array of customers.  

What I guess I don't get is why you need to refer to an array when you're
editing fields in the customer object the user selected.  Why not just have
the user select a single object from the array, and have that object be a
form bean that you then compare to the corresponding object in the array
once the user has submitted the form?  That way, you're not in the business
of selecting and editing simultaneously.

If the reason is that the array of customers we're talking about here is
actually your object model, you may want to think about the way your
application is using the form (ignore the rest of this paragraph if that's
not the reason).  Usually, it's better to have the FormBeans be copies of
the model objects so that you can have a sort of validating DMZ protecting
your data-- if you don't agree, poke around and you're sure to find a rant
by Craig McC that explains it better than I'm able.  The basic idea is to
keep the "M" and the "V" in "MVC" separate.



-----Original Message-----
From: Howard Miller []
Sent: Saturday, September 21, 2002 3:38 PM
To: Struts Users Mailing List
Subject: RE: Nested Indexed Property

More experimentation.....

Taking your example, what I would *like* to write is....

<html:text property="customer[<%= request.getParameter("index") %>].name" />

where the parameter index comes from the user selection on the previous
Doesn't compile though!! Is there a way of writing the above that will


On 21 Sep 2002 at 13:44, Taylor, Jason wrote:

> I'm not sure how you mean "nested" since there's a tag library called
> "struts-nested" and I'm not sure if you're referring to that.  If you're
> using that, I think you may not need to, depending on the complexity of
> form.
> If you have only one dimension of arbitrary length,  it's not really a
> "nested" situation, and you can try using the "indexed" property of the
> various html tags (such as html:text).  You need to have an array of beans
> in your action form class with the appropriate get/set methods for each
> "column" in your list.  The array corresponds to the set of request
> parameters sent from an array on the form that you populate using a
> logic:iterate block in the JSP.  Struts will automatically figure out that
> the "customer[0].name" request parameter is the "name" property on the
> customer bean in your customer bean array in the action form.
> Don't try it with Struts 1.0x, though, as "indexed" is a 1.1 feature...
> -----Original Message-----
> From: Howard Miller []
> Sent: Saturday, September 21, 2002 1:02 PM
> To: struts Users Mailing List
> Subject: Nested Indexed Property
> Hi,
> Sorry for repeating myself, but I think having read a lot more I can ask
> question 
> with a bit more "intelligence".
> To set the scene may I quote from the documentation:
> "You may also place a bean instance on your form, and use nested property 
> references. For example, you might have a "customer" bean on your Action 
> Form, and then refer to the property "" in your JSP view.
> would correspond to the methods customer.getName() and 
> customer.setName(string Name) on your customer bean"
> fine... BUT what if name is a property of an object in the LIST customer.
> (working backwards) I want to create the reference:
> customer.get( i ).setName(string Name) (oversimplified I know).
> BUT it gets worse.... the index, i, is actually a property set on the
> previous JSP 
> page... so its more like
> customer.get( reqest.getParameter( "index" ) ).setName(string Name )
> ...and of course the form action needs to properly read the current values
> into 
> the form text fields and then set them back into the correct place. I have
> no 
> clue how to do this! Any offers?
> HM
> --
> To unsubscribe, e-mail:
> <>
> For additional commands, e-mail:
> <>

To unsubscribe, e-mail:
For additional commands, e-mail:

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message