You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Haulyn R. Jason" <sa...@gmail.com> on 2008/08/11 18:25:00 UTC
How to resolve list property for ModelDriven Action?
Hi,
I implement ModelDriven interface, but I have a list in my model. It
looks like:
public class Role(){
private String id;
private String name ;
private List<Privilege> privilegeList;
}
In my action, I have a set/get method for Role Object, but what about
the list?
I am confused for retrieve data from my "edit page" for privilegeList.
Should I define another list then convent it to privilegeList myself?
Always thanks for solution or some urls for reference.
--
Thanks!
Mobile: +086-15864011231
EMail>alk:saharabear@gmail.com
EMail&yahoo:jia_haolin@yahoo.com
Skype:saharabear
贾昊林(Haulyn Runner Jason)
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: How to resolve list property for ModelDriven Action?
Posted by Dave Newton <ne...@yahoo.com>.
--- On Mon, 8/11/08, Haulyn R. Jason wrote:
> I mean , I know how to populate data to a select tag, and I
> know how to collection data from a select tag, but the problem
> is: If the list I want to collection from select tag is not a
> simple data type(String), but it's another object, how can I do
> that?
There are at least two options; using the <s:select...> tag or building the options manually.
If you're using the <s:select...> tag, assuming a list of "Foo" objects with "id" and "bar" properties:
<s:select list="listOfFoo" listKey="id" listValue="bar" value="foos"/>
See the <s:select...> tag documentation [1].
If you're building the options by hand:
<select name="foos">
<c:forEach value="${listOfFoos}" var="foo">
<option value="${foo.id}">${foo.bar}</option>
</c:forEach>
</select>
(You'd also need logic to determine if the option should be selected.)
Some of the information on the tag syntax page [2] might also be of interest.
Dave
[1] <s:select...> tag:
http://struts.apache.org/2.x/docs/select.html
[2] Tag syntax:
http://struts.apache.org/2.x/docs/tag-syntax.html
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: How to resolve list property for ModelDriven Action?
Posted by "Haulyn R. Jason" <sa...@gmail.com>.
Dave Newton :
> Oh. So what are you asking then? How to create a select list? How to use the <s:select...> tag?
>
> Dave
>
> --- On Mon, 8/11/08, Haulyn R. Jason <sa...@gmail.com> wrote:
>
>
>> From: Haulyn R. Jason <sa...@gmail.com>
>> Subject: Re: How to resolve list property for ModelDriven Action?
>> To: "Struts Users Mailing List" <us...@struts.apache.org>
>> Date: Monday, August 11, 2008, 12:35 PM
>> Dave Newton :
>>
>>> --- On Mon, 8/11/08, Haulyn R. Jason
>>>
>> <sa...@gmail.com> wrote:
>>
>>>
>>>
>>>> I implement ModelDriven interface, but I have a
>>>>
>> list in my
>>
>>>> model. It
>>>> looks like:
>>>> public class Role(){
>>>> private String id;
>>>> private String name ;
>>>> private List<Privilege> privilegeList;
>>>> }
>>>>
>>>> In my action, I have a set/get method for Role
>>>>
>> Object, but
>>
>>>> what about the list?
>>>>
>>>>
>>> You don't need a separate method for the list; if
>>>
>> you're using ModelDriven you'd get it, for example,
>> by using:
>>
>>> <s:iterator value="privilegeList">
>>> ...
>>>
>>> The model (when not null) is pushed onto the top of
>>>
>> the stack. If you weren't using ModelDriven and had a
>> getter for role:
>>
>>> <s:iterator
>>>
>> value="role.privilegeList">
>>
>>> ...
>>>
>>>
>>> Dave
>>>
>>>
>>>
>>>
>> ---------------------------------------------------------------------
>>
>>> To unsubscribe, e-mail:
>>>
>> user-unsubscribe@struts.apache.org
>>
>>> For additional commands, e-mail:
>>>
>> user-help@struts.apache.org
>>
>>>
>>>
>> Thanks Dave, but
>> It's a form, I want to use <select
>> multiple="true" > or the similar ui
>> tags for modifying it. So how can I retrieve data from
>> form?
>>
>> --
>>
>> Thanks!
>>
>> Mobile: +086-15864011231
>> EMail>alk:saharabear@gmail.com
>> EMail&yahoo:jia_haolin@yahoo.com
>> Skype:saharabear
>>
>>
>> Haulyn Runner Jason
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail:
>> user-help@struts.apache.org
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
>
Hi, Dave
Sorry for my poor English, I am not english speaking.
I mean , I know how to populate data to a select tag, and I know how to
collection data from a select tag, but the problem is:
If the list I want to collection from select tag is not a simple data
type(String), but it's another object, how can I do that?
Thanks
--
Thanks!
Mobile: +086-15864011231
EMail>alk:saharabear@gmail.com
EMail&yahoo:jia_haolin@yahoo.com
Skype:saharabear
Haulyn Runner Jason
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: How to resolve list property for ModelDriven Action?
Posted by Dave Newton <ne...@yahoo.com>.
Oh. So what are you asking then? How to create a select list? How to use the <s:select...> tag?
Dave
--- On Mon, 8/11/08, Haulyn R. Jason <sa...@gmail.com> wrote:
> From: Haulyn R. Jason <sa...@gmail.com>
> Subject: Re: How to resolve list property for ModelDriven Action?
> To: "Struts Users Mailing List" <us...@struts.apache.org>
> Date: Monday, August 11, 2008, 12:35 PM
> Dave Newton :
> > --- On Mon, 8/11/08, Haulyn R. Jason
> <sa...@gmail.com> wrote:
> >
> >> I implement ModelDriven interface, but I have a
> list in my
> >> model. It
> >> looks like:
> >> public class Role(){
> >> private String id;
> >> private String name ;
> >> private List<Privilege> privilegeList;
> >> }
> >>
> >> In my action, I have a set/get method for Role
> Object, but
> >> what about the list?
> >>
> >
> > You don't need a separate method for the list; if
> you're using ModelDriven you'd get it, for example,
> by using:
> >
> > <s:iterator value="privilegeList">
> > ...
> >
> > The model (when not null) is pushed onto the top of
> the stack. If you weren't using ModelDriven and had a
> getter for role:
> >
> > <s:iterator
> value="role.privilegeList">
> > ...
> >
> >
> > Dave
> >
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> user-unsubscribe@struts.apache.org
> > For additional commands, e-mail:
> user-help@struts.apache.org
> >
> >
> >
>
> Thanks Dave, but
> It's a form, I want to use <select
> multiple="true" > or the similar ui
> tags for modifying it. So how can I retrieve data from
> form?
>
> --
>
> Thanks!
>
> Mobile: +086-15864011231
> EMail>alk:saharabear@gmail.com
> EMail&yahoo:jia_haolin@yahoo.com
> Skype:saharabear
>
>
> 贾昊林(Haulyn Runner Jason)
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail:
> user-help@struts.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: How to resolve list property for ModelDriven Action?
Posted by "Haulyn R. Jason" <sa...@gmail.com>.
Dave Newton :
> --- On Mon, 8/11/08, Haulyn R. Jason <sa...@gmail.com> wrote:
>
>> I implement ModelDriven interface, but I have a list in my
>> model. It
>> looks like:
>> public class Role(){
>> private String id;
>> private String name ;
>> private List<Privilege> privilegeList;
>> }
>>
>> In my action, I have a set/get method for Role Object, but
>> what about the list?
>>
>
> You don't need a separate method for the list; if you're using ModelDriven you'd get it, for example, by using:
>
> <s:iterator value="privilegeList">
> ...
>
> The model (when not null) is pushed onto the top of the stack. If you weren't using ModelDriven and had a getter for role:
>
> <s:iterator value="role.privilegeList">
> ...
>
>
> Dave
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
>
Thanks Dave, but
It's a form, I want to use <select multiple="true" > or the similar ui
tags for modifying it. So how can I retrieve data from form?
--
Thanks!
Mobile: +086-15864011231
EMail>alk:saharabear@gmail.com
EMail&yahoo:jia_haolin@yahoo.com
Skype:saharabear
贾昊林(Haulyn Runner Jason)
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: How to resolve list property for ModelDriven Action?
Posted by Dave Newton <ne...@yahoo.com>.
--- On Mon, 8/11/08, Haulyn R. Jason <sa...@gmail.com> wrote:
> I implement ModelDriven interface, but I have a list in my
> model. It
> looks like:
> public class Role(){
> private String id;
> private String name ;
> private List<Privilege> privilegeList;
> }
>
> In my action, I have a set/get method for Role Object, but
> what about the list?
You don't need a separate method for the list; if you're using ModelDriven you'd get it, for example, by using:
<s:iterator value="privilegeList">
...
The model (when not null) is pushed onto the top of the stack. If you weren't using ModelDriven and had a getter for role:
<s:iterator value="role.privilegeList">
...
Dave
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org