struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Miguel Almeida <mig...@almeida.at>
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
parameters:
entity.entity2List[0].entity3.id=10
entity.entity2List[1].entity3.id=20

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 Entity3.id=10 and the second Entity2 has an
Entity3.id=20.
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
parameters!

Miguel

[1] Unit Test snippet

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

		createAction("/example/Conversion.action");

		executeProxy();
		
		Entity entity = ((TypeConversionAction) action).getEntity();
		assertNotNull(entity);
		assertNotNull(entity.getEntity2List());
		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 <miguel@almeida.at> 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].entity3.id (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[].entity3.id}" list="#someList" listKey="id"
> > listValue="code"/>
> > <s:select key="centre.choose" multiple="true"
> > name="entity.entity2List[].entity3.id" list="#someList" listKey="id"
> > listValue="code"/>
> > 
> > 
> > Thank you for your help!
> > 
> > Miguel Almeida
> > 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 



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