You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by st...@gmail.com on 2007/05/16 16:01:33 UTC

Can someone identify the attributes of this example code, preferably
in the documentation itself?

http://struts.apache.org/2.x/docs/select.html


<s:select label="Pets"
       name="petIds"
       list="petDao.pets"
       listKey="id"
       listValue="name"
       multiple="true"
       size="3"
       required="true"
/>

Is there an expectation that a getPetDao() exists somewhere?  Also, what is
listKey/listValue and what does the discussion concerning (if list is an
Iterable Map) have to do with the setup?  A select box is so common that it
eludes me how development comes to a screeching halt when you need to drop
one on a screen!


-- 
Scott
stanlick@gmail.com

Re:

Posted by Laurie Harper <la...@holoweb.net>.
stanlick@gmail.com wrote:
> Here are the details:
> 
> My jsp is iterating over a list of Beans.  Each bean contains a Map of
> key/value pairs <both Strings>, and a property that reflects the item 
> chosen
> previously from the Map <the key>.  On my "list" page, I want to display 
> the
> values that correspond to the keys selected.
> 
> Here is my iterator, which I understand makes available each bean to the
> root of OGNL.  I can display employeeId or employees, so they are each
> clearly visible.  So why does this syntax not display the value for the 
> key?
> 
> <s:iterator value="#request.list">
> 
> <s:property value="employees[employeeId]" />
> 
> P.S. This seems so elementary!

Hmm, I'm not sure what this has to do with the discussion of s:select, 
but OK... So, you have a request attribute named 'list' which is a list 
of beans of some type X. The type X has a property M of type 
Map<String,String> and a property K of type String which is the value of 
a key in M.

So what are 'employees' and 'employeeId'? Are those the real names of 
the properties M and K? If so, what you have there looks right. What 
happens if you write the following:

   <s:property value='employees'/>
   <s:property value='employeeId'/>
   <s:property value='employeeId.class'/>
   <s:property value='employees.keys[0].class'/>

Perhaps something isn't of the type you think it is, or isn't exposed 
with the name you think it is. I'm guessing at what your data structures 
look like since you haven't posted the relevant code, but a bit of 
digging and experimenting like above should let you figure out where the 
mis-match is.

L.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re:

Posted by st...@gmail.com.
Here are the details:

My jsp is iterating over a list of Beans.  Each bean contains a Map of
key/value pairs <both Strings>, and a property that reflects the item chosen
previously from the Map <the key>.  On my "list" page, I want to display the
values that correspond to the keys selected.

Here is my iterator, which I understand makes available each bean to the
root of OGNL.  I can display employeeId or employees, so they are each
clearly visible.  So why does this syntax not display the value for the key?

<s:iterator value="#request.list">

<s:property value="employees[employeeId]" />

P.S. This seems so elementary!

Re:

Posted by Laurie Harper <la...@holoweb.net>.
Dave Newton wrote:
> --- stanlick@gmail.com wrote:
>> Say, if I want to display an item's value from the
>> map, what is the syntax?
>> I tried this, but obviously this was too intuitive.
>> <s:property value="someMap[someKey]" />
> 
> That's what I do. With names changed to protect the
> innocent, here's one of my textfields:
> 
> <s:textfield
> name="exDataMap[%{#result.id}].%{which}[0].foo"/>
> 
> Each map entry is a collection of objects with a foo
> property. The %{which} is because each map entry has a
> few different properties that I need to display based
> on a request parameter. #result is a set variable
> hence the # to distinquish it from the stack's root.
> It's a reasonably complex data structure I'm dealing
> with, but so far I haven't had any issues, including
> dynamically generating additional rows via JavaScript.

Based on that little example, I nominate Dave as author of the Advanced 
Guide to OGNL ;-)

That said, stanlick, what you wrote should do exactly what you were 
probably expecting. If not, post what you expected vs. what you got and 
any relevant supporting details (what someMap is, what someKey is, 
etc.). '...this was too intuitive...' isn't a very descriptive problem 
report ;-) [assuming it even was one!]

L.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re:

Posted by Dave Newton <ne...@yahoo.com>.
--- stanlick@gmail.com wrote:
> Say, if I want to display an item's value from the
> map, what is the syntax?
> I tried this, but obviously this was too intuitive.
> <s:property value="someMap[someKey]" />

That's what I do. With names changed to protect the
innocent, here's one of my textfields:

<s:textfield
name="exDataMap[%{#result.id}].%{which}[0].foo"/>

Each map entry is a collection of objects with a foo
property. The %{which} is because each map entry has a
few different properties that I need to display based
on a request parameter. #result is a set variable
hence the # to distinquish it from the stack's root.
It's a reasonably complex data structure I'm dealing
with, but so far I haven't had any issues, including
dynamically generating additional rows via JavaScript.

d.



       
____________________________________________________________________________________Be a better Globetrotter. Get better travel answers from someone who knows. Yahoo! Answers - Check it out.
http://answers.yahoo.com/dir/?link=list&sid=396545469

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re:

Posted by st...@gmail.com.
Awesome!  It looked like using the Map saved time and I was looking for a
second opinion.  I have it working the way you have identified it here, but
just wanted to make sure it was not some twisted end-around solution that
people would laugh at later!

Say, if I want to display an item's value from the map, what is the syntax?
I tried this, but obviously this was too intuitive. :)

<s:property value="someMap[someKey]" />

Scott


On 5/16/07, Laurie Harper <la...@holoweb.net> wrote:
>
> But it is simple :-) The note in the docs about 'If the list is a
> Map...' is just telling you that the tag will automatically use the map
> key/value pairs to fill the option tags -- i.e. that these are (roughly)
> equivalent:
>
>    <s:select list="someMap.entrySet()"
>              listKey="key" listValue="value" ...
>
>    <s:select list="someMap" ...
>
> If 'list' points to a collection that is not a Map, then you need to
> specify listKey and listValue to tell the tag what properties of the
> instance objects in the list should be placed into the options.
>
> L.
>
> stanlick@gmail.com wrote:
> > Thanks d!  It appears that if neither you nor I can easily drop a
> <s:select
> > /> on a page and wire it up without fuss-n-muss, perhaps it is causing
> > others grief too.  I just think something this typical should be simple
> to
> > code.
> >
> > Scott
> >
> > On 5/16/07, Dave Newton <ne...@yahoo.com> wrote:
> >>
> >> --- stanlick@gmail.com wrote:
> >> > 1. Where is the getPetDao() method expected to be
> >> > coded?  I'd like to "set" this data from my Tiles
> >> > Controller.
> >>
> >> It can be coded anywhere, but like most of the other
> >> tags, is expected to be accessible via the OGNL stack.
> >>
> >> > 2. Where do the properties listKey/listValue need
> >> > to be coded and what is the effect of this when list
> >>
> >> > is an Iterable Map?
> >>
> >> Those are properties of whatever object the list is
> >> of. I don't have my code in front of me and I don't
> >> recall what happens when the <s:select.../> is being
> >> populated from a map, sorry :/
> >>
> >> IIRC if it's a "simple" map the value will be the key
> >> and the text will be the toString of the value, but...
> >> IRRC (I Rarely Remember Correctly).
> >>
> >> The following may be wrong, but it tripped me up for
> >> about 15 minutes, and this was how I solved it:
> >>
> >> One thing of note regarding <s:select.../> is that the
> >> "value" attribute apparently needs to be a map with a
> >> *string* key. So even if the list/set you're
> >> populating the list from has a java.lang.Long id (like
> >> all my Hibernate POJOs do) the *value* attribute must
> >> be a map in order for list "pre-selection" to work.
> >>
> >> *If* this is true, it is unfortunate, as it adds a
> >> step between simply getting the appropriate sets and
> >> values and just throwing them at <s:select.../> but I
> >> suppose it makes sense from a practicality standpoint.
> >>
> >> d.
> >>
> >>
> >>
> >>
> >>
> >>
> ____________________________________________________________________________________
> >>
> >> Be a PS3 game guru.
> >> Get your game face on with the latest PS3 news and previews at Yahoo!
> >> Games.
> >> http://videogames.yahoo.com/platform?platform=120121
> >>
> >> ---------------------------------------------------------------------
> >> 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
>
>


-- 
Scott
stanlick@gmail.com

Re:

Posted by Laurie Harper <la...@holoweb.net>.
But it is simple :-) The note in the docs about 'If the list is a 
Map...' is just telling you that the tag will automatically use the map 
key/value pairs to fill the option tags -- i.e. that these are (roughly) 
equivalent:

   <s:select list="someMap.entrySet()"
             listKey="key" listValue="value" ...

   <s:select list="someMap" ...

If 'list' points to a collection that is not a Map, then you need to 
specify listKey and listValue to tell the tag what properties of the 
instance objects in the list should be placed into the options.

L.

stanlick@gmail.com wrote:
> Thanks d!  It appears that if neither you nor I can easily drop a <s:select
> /> on a page and wire it up without fuss-n-muss, perhaps it is causing
> others grief too.  I just think something this typical should be simple to
> code.
> 
> Scott
> 
> On 5/16/07, Dave Newton <ne...@yahoo.com> wrote:
>>
>> --- stanlick@gmail.com wrote:
>> > 1. Where is the getPetDao() method expected to be
>> > coded?  I'd like to "set" this data from my Tiles
>> > Controller.
>>
>> It can be coded anywhere, but like most of the other
>> tags, is expected to be accessible via the OGNL stack.
>>
>> > 2. Where do the properties listKey/listValue need
>> > to be coded and what is the effect of this when list
>>
>> > is an Iterable Map?
>>
>> Those are properties of whatever object the list is
>> of. I don't have my code in front of me and I don't
>> recall what happens when the <s:select.../> is being
>> populated from a map, sorry :/
>>
>> IIRC if it's a "simple" map the value will be the key
>> and the text will be the toString of the value, but...
>> IRRC (I Rarely Remember Correctly).
>>
>> The following may be wrong, but it tripped me up for
>> about 15 minutes, and this was how I solved it:
>>
>> One thing of note regarding <s:select.../> is that the
>> "value" attribute apparently needs to be a map with a
>> *string* key. So even if the list/set you're
>> populating the list from has a java.lang.Long id (like
>> all my Hibernate POJOs do) the *value* attribute must
>> be a map in order for list "pre-selection" to work.
>>
>> *If* this is true, it is unfortunate, as it adds a
>> step between simply getting the appropriate sets and
>> values and just throwing them at <s:select.../> but I
>> suppose it makes sense from a practicality standpoint.
>>
>> d.
>>
>>
>>
>>
>>
>> ____________________________________________________________________________________ 
>>
>> Be a PS3 game guru.
>> Get your game face on with the latest PS3 news and previews at Yahoo!
>> Games.
>> http://videogames.yahoo.com/platform?platform=120121
>>
>> ---------------------------------------------------------------------
>> 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:

Posted by st...@gmail.com.
Thanks d!  It appears that if neither you nor I can easily drop a <s:select
/> on a page and wire it up without fuss-n-muss, perhaps it is causing
others grief too.  I just think something this typical should be simple to
code.

Scott

On 5/16/07, Dave Newton <ne...@yahoo.com> wrote:
>
> --- stanlick@gmail.com wrote:
> > 1. Where is the getPetDao() method expected to be
> > coded?  I'd like to "set" this data from my Tiles
> > Controller.
>
> It can be coded anywhere, but like most of the other
> tags, is expected to be accessible via the OGNL stack.
>
> > 2. Where do the properties listKey/listValue need
> > to be coded and what is the effect of this when list
>
> > is an Iterable Map?
>
> Those are properties of whatever object the list is
> of. I don't have my code in front of me and I don't
> recall what happens when the <s:select.../> is being
> populated from a map, sorry :/
>
> IIRC if it's a "simple" map the value will be the key
> and the text will be the toString of the value, but...
> IRRC (I Rarely Remember Correctly).
>
> The following may be wrong, but it tripped me up for
> about 15 minutes, and this was how I solved it:
>
> One thing of note regarding <s:select.../> is that the
> "value" attribute apparently needs to be a map with a
> *string* key. So even if the list/set you're
> populating the list from has a java.lang.Long id (like
> all my Hibernate POJOs do) the *value* attribute must
> be a map in order for list "pre-selection" to work.
>
> *If* this is true, it is unfortunate, as it adds a
> step between simply getting the appropriate sets and
> values and just throwing them at <s:select.../> but I
> suppose it makes sense from a practicality standpoint.
>
> d.
>
>
>
>
>
> ____________________________________________________________________________________
> Be a PS3 game guru.
> Get your game face on with the latest PS3 news and previews at Yahoo!
> Games.
> http://videogames.yahoo.com/platform?platform=120121
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>


-- 
Scott
stanlick@gmail.com

Re:

Posted by Dave Newton <ne...@yahoo.com>.
--- stanlick@gmail.com wrote:
> 1. Where is the getPetDao() method expected to be
> coded?  I'd like to "set" this data from my Tiles 
> Controller.

It can be coded anywhere, but like most of the other
tags, is expected to be accessible via the OGNL stack.

> 2. Where do the properties listKey/listValue need
> to be coded and what is the effect of this when list

> is an Iterable Map?

Those are properties of whatever object the list is
of. I don't have my code in front of me and I don't
recall what happens when the <s:select.../> is being
populated from a map, sorry :/ 

IIRC if it's a "simple" map the value will be the key
and the text will be the toString of the value, but...
IRRC (I Rarely Remember Correctly).

The following may be wrong, but it tripped me up for
about 15 minutes, and this was how I solved it:

One thing of note regarding <s:select.../> is that the
"value" attribute apparently needs to be a map with a
*string* key. So even if the list/set you're
populating the list from has a java.lang.Long id (like
all my Hibernate POJOs do) the *value* attribute must
be a map in order for list "pre-selection" to work.

*If* this is true, it is unfortunate, as it adds a
step between simply getting the appropriate sets and
values and just throwing them at <s:select.../> but I
suppose it makes sense from a practicality standpoint.

d.



 
____________________________________________________________________________________
Be a PS3 game guru.
Get your game face on with the latest PS3 news and previews at Yahoo! Games.
http://videogames.yahoo.com/platform?platform=120121

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re:

Posted by st...@gmail.com.
Dave you are a funny guy!  Let's try this again.

On 5/16/07, stanlick@gmail.com <st...@gmail.com> wrote:
>
> Can someone identify the attributes of this example code, preferably in the documentation itself?
>
> http://struts.apache.org/2.x/docs/select.html
>
>
>
> <s:select
>        name="petIds"
>        list="petDao.pets"
>        listKey="id"
>        listValue="name"
> />
>
>

   1. Where is the getPetDao() method expected to be coded?  I'd like to
   "set" this data from my Tiles Controller.
   2. Where do the properties listKey/listValue need to be coded and what
   is the effect of this when list is an Iterable Map?

-- 
Scott
stanlick@gmail.com

Re:

Posted by Dave Newton <ne...@yahoo.com>.
--- stanlick@gmail.com wrote:
> Can someone identify the attributes of this example
> code, preferably in the documentation itself?
> 
> http://struts.apache.org/2.x/docs/select.html
> 
> 
> <s:select label="Pets"

The label.

>        name="petIds"

The action property.

>        list="petDao.pets"

Where the list comes from (the list used to populate
the options).

>        listKey="id"

The value for <option value="xxx">

>        listValue="name"

The text of the option <option...>XXX</option>

>        multiple="true"

Multiple select?

>        size="3"

How tall is it?

>        required="true"

Is it a required form element?

> Is there an expectation that a getPetDao() exists
> somewhere?  

Yes. That's where the list comes from.

> Also, what is listKey/listValue 

See above.

> [...] it eludes me how development comes to a \
> screeching halt when you need to drop one on a 
> screen!

That eludes me too.

d.



      ____________________________________________________________________________________
Park yourself in front of a world of choices in alternative vehicles. Visit the Yahoo! Auto Green Center.
http://autos.yahoo.com/green_center/ 

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org