You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Ken <ke...@aerose.com> on 2010/07/01 20:47:27 UTC

OGNL to get list of keys

In my jsp I have:

                    <s:iterator value="list[0].keys">
                        <th><s:property value="#this"/></th>
                    </s:iterator>

Where list, is a List<Map>...

The above produces the following html:

                        <th>[id,
app.mz.address.CompanyNameLister@e8e3b0,
com.opensymphony.xwork2.DefaultTextProvider@178cce2]</th>
                    
                        <th>[curName,
app.mz.address.CompanyNameLister@e8e3b0,
com.opensymphony.xwork2.DefaultTextProvider@178cce2]</th>
                    
                        <th>[group,
app.mz.address.CompanyNameLister@e8e3b0,
com.opensymphony.xwork2.DefaultTextProvider@178cce2]</th>
                    
                        <th>[oldName,
app.mz.address.CompanyNameLister@e8e3b0,
com.opensymphony.xwork2.DefaultTextProvider@178cce2]</th>

When I expected to see:
                        <th>id</th>
                    
                        <th>curName</th>
                    
                        <th>group</th>
                    
                        <th>oldName</th>

I must be missing something terribly obvious! Help.

Re: OGNL to get list of keys

Posted by Dale Newfield <da...@newfield.org>.
On 7/1/10 4:08 PM, Ken wrote:
> Adding 'var="header"' to the <s:iterator> tag simply pushed a named
> object onto the stack.

> Am I missing something?

Yes.

Any use of an s:iterator always pushes the current item onto the top of 
the stack during each iteration of the body.  You can refer to that as 
"top" if you so choose.

Adding a var attribute also stores the value in the map that sits 
alongside the valuestack, and the prefix # tells ognl to look something 
up in that map.

-Dale

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


Re: OGNL to get list of keys

Posted by Dale Newfield <da...@newfield.org>.
On 7/1/10 3:51 PM, Ken wrote:
> This produced the desired effect:
> (added var="header" to iterator tag)
>
>                      <s:iterator value="list[0].keys" var="header">
>                          <th><s:property value="header"/></th>
>                      </s:iterator>

If you have var="header" in the iterator, the appropriate way to 
reference that value within the iterator is "%{#header}"

-Dale

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


Re: OGNL to get list of keys

Posted by Ken <ke...@aerose.com>.
This produced the desired effect:
(added var="header" to iterator tag)

                    <s:iterator value="list[0].keys" var="header">
                        <th><s:property value="header"/></th>
                    </s:iterator>

On Thu, 2010-07-01 at 12:47 -0600, Ken wrote:

> In my jsp I have:
> 
>                     <s:iterator value="list[0].keys">
>                         <th><s:property value="#this"/></th>
>                     </s:iterator>
> 
> Where list, is a List<Map>...
> 
> The above produces the following html:
> 
>                         <th>[id,
> app.mz.address.CompanyNameLister@e8e3b0,
> com.opensymphony.xwork2.DefaultTextProvider@178cce2]</th>
>                     
>                         <th>[curName,
> app.mz.address.CompanyNameLister@e8e3b0,
> com.opensymphony.xwork2.DefaultTextProvider@178cce2]</th>
>                     
>                         <th>[group,
> app.mz.address.CompanyNameLister@e8e3b0,
> com.opensymphony.xwork2.DefaultTextProvider@178cce2]</th>
>                     
>                         <th>[oldName,
> app.mz.address.CompanyNameLister@e8e3b0,
> com.opensymphony.xwork2.DefaultTextProvider@178cce2]</th>
> 
> When I expected to see:
>                         <th>id</th>
>                     
>                         <th>curName</th>
>                     
>                         <th>group</th>
>                     
>                         <th>oldName</th>
> 
> I must be missing something terribly obvious! Help.