struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Miguel Almeida <>
Subject Re: How to set the name parameter on a multiple s:select
Date Thu, 30 May 2013 09:42:30 GMT
Thanks for the feedback Dale.
A couple of thoughts below.
On Wed, 2013-05-29 at 08:18 -0400, Dale Newfield wrote:

> I would have a setter on my action class that takes an array of ids.  Then the action
does the appropriate lookups, and sets the hydrated objects on the appropriate models.

That's an alternative, yes. I do tend to prefer having the model objects
in my actions though, to keep the number of objects to a minimum - it
makes more sense to have a List<SomeObject> objects than an Integer[]
ids, but maybe that's personal preference.

> You do recognize that the data you provided is ambiguous, though, right?  Nothing you
stated is sufficient to know *which* entity2 objects should be set on entity, just which entity3
objects you want those entity2 objects to have.  In fact, if you don't happen to get a number
of entity3 ids that matches the number of entity2s on entity, you've left yourself no way
of knowing how to proceed. (Remember, all you get is a (potentially unordered) list of ids
from the form submission, not tuples.)

I'm not sure where the ambiguity is. Take the following request

There is no ambiguity in how the Object should be populated - one
entity, which has two Entity2 on the entity2List object: the first
entity2 has an and the second Entity2 has an
In fact, this request works as expected (as evidenced by the test case
[1]). The challenge is to create an s:select that generates that request


[1] Unit Test snippet

request.setParameter("entity.entity2List[0]", "2");
		request.setParameter("entity.entity2List[1]", "11");


		Entity entity = ((TypeConversionAction) action).getEntity();
		assertEquals(2, entity.getEntity2List().size());
		assertEquals(2, entity.getEntity2List().get(0).getEntity3().getId());
		assertEquals(11, entity.getEntity2List().get(1).getEntity3().getId());

> -Dale
> On May 29, 2013, at 6:27 AM, Miguel Almeida <> wrote:
> > Dear all,
> > 
> > Imagine you have the following scenario:
> > - a property in your action: private Entity entity;
> > 
> > - Entity has a List<Entity2> entity2List
> > - Entity2 has a Entity3 entity3
> > 
> > Now, you need an s:select with multiple="true" to populate entity3. This
> > corresponds to having a request in the form
> > entity.entity2List[n] (n=0,1,2...depending on how many items
> > are selected).
> > 
> > Question: how should the name parameter of the s:select be like to
> > achieve this?
> > 
> > Me and Lukasz  have tried the following without success (meaning
> > entity.entity2List has is empty):
> > <s:select key="centre.choose" multiple="true"
> > name="%{entity.entity2List[]}" list="#someList" listKey="id"
> > listValue="code"/>
> > <s:select key="centre.choose" multiple="true"
> > name="entity.entity2List[]" list="#someList" listKey="id"
> > listValue="code"/>
> > 
> > 
> > Thank you for your help!
> > 
> > Miguel Almeida
> > 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

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