You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Paolo Beccari <pb...@email.it> on 2007/06/06 10:27:40 UTC

[S2] decoding values of objects properties

Hi all,

I have some objects in my app whose properties needs a "decode" in the view. 
I don't want to return property values already decoded to the view, I wish 
to decode them in the view.
For the same reason, I also have to build some picklists with shown text 
different from value.

Since we have a huge set of properties to decode, the example given in the 
docs:
<s:select label="Pets" name="petIds" list="petDao.pets"

is hardly applicable: with scriplet I could use a 
<%=Decoder.decode(propertyName, propertyValue)%> and a 
<%=Decoder.buildPicklist(propertyName, propertyValue)%> method, but I wish 
to do it in a S2-fashion without using scriplets.

I think this is could be a common issue in a webapp, does anyone has an idea 
on how to resolve?

P.


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


Re: [S2] OGNL newbie: obtaining subset of a collection

Posted by Paolo Beccari <pb...@email.it>.
Laurie Harper wrote:
> L.
> 
> ObWhine: please don't post unrelated questions to an existing thread. Be 
> sure to start a new thread (with an appropriate subject) by sending a 
> fresh message to the list, rather than using Reply To.
> 
> 

Thanks for the reply.
I'm sorry for the wrong posting, it was not what I intended to do.

P.


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


Re: [S2] OGNL newbie: obtaining subset of a collection

Posted by Laurie Harper <la...@holoweb.net>.
Paolo Beccari wrote:
> 
> Hi there,
> 
> here:
> http://struts.apache.org/2.x/docs/ognl.html
> 
> I found that:
> To select a subset of a collection (called projection), use a wildcard
> within the collection.
> ? - All elements matching the selection logic
> ^ - Only the first element matching the selection logic
> $ - Only the last element matching the selection logic
> To obtain a subset of just male relatives from the object person:
> person.relatives.{? #this.gender == 'male'}
> 
> I can't find the correct syntax to pass a variable (picked from valueStack)
> instead of the string 'male'
> 
> Someone can help or point me the docs?
> P.

If the value you want to retrieve in place of the string 'male' is a 
property on your action, just reference it by name. Otherwise, use the 
'#' notation to access it, as in

     person.relatives.{? #this.gender == someProperty}
     person.relatives.{? #this.gender == #somethingElse}

If that doesn't do the trick, you'll need to post more details of what 
data you have stored where and what you want to access.

L.

ObWhine: please don't post unrelated questions to an existing thread. Be 
sure to start a new thread (with an appropriate subject) by sending a 
fresh message to the list, rather than using Reply To.


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


[S2] OGNL newbie: obtaining subset of a collection

Posted by Paolo Beccari <pb...@email.it>.
Hi there,

here:
http://struts.apache.org/2.x/docs/ognl.html

I found that:
To select a subset of a collection (called projection), use a wildcard
within the collection.
? - All elements matching the selection logic
^ - Only the first element matching the selection logic
$ - Only the last element matching the selection logic
To obtain a subset of just male relatives from the object person:
person.relatives.{? #this.gender == 'male'}

I can't find the correct syntax to pass a variable (picked from valueStack)
instead of the string 'male'

Someone can help or point me the docs?
P. 


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


RE: [S2] decoding values of objects properties

Posted by Al Sutton <al...@al-and-andrea.org.uk>.
Why not pre-decode the results in the action, populate a Collection, and add
a getDecoded method to the action which returns the pre-decoded Collection.
You can then use s:iterator to iterator over the collection and call methods
within each element. This allows you to implement whatever class hierarchy
you want for the objects in the collection to provide the data for your view
without needing a getXXXX method for each property.

Also as a side note, you said "...if the decoded value I'm searching is the
last in the list...", is there any reason you aren't taking your search
value, encoding it for your data model, and putting it into your database
query. That way you're using the database to do the search and you don't
pull all the data from a table over the network just to find one value.

-----Original Message-----
From: Paolo Beccari [mailto:pbeccari@email.it] 
Sent: 06 June 2007 12:36
To: Struts Users Mailing List
Subject: Re: [S2] decoding values of objects properties


----- Original Message -----
From: "Dave Newton" <ne...@yahoo.com>
To: "Struts Users Mailing List" <us...@struts.apache.org>
Sent: Wednesday, June 06, 2007 1:14 PM
Subject: Re: [S2] decoding values of objects properties


> I'm still not entirely what you're decoding from and
> to; it sounds like something is fundamentally broken,
> but...
>

Ok, I explain: suppose we have an entity with a state property that can 
assume values 0, 1 where 0 stands for "Active" and 1 stands for "Not 
Active".
state is the property name
0 is the value
"Active" is the "decoded" value

It's often useful (at database level) to map certain properties to numbers 
(or strings, or whatever) which belongs to a description in metadata, so it 
is possible (for example) to change the description without any side-effects

on old stored data.

(Joining the table to retrieve the decoded value is not an option when the 
metadata table is shared through many sets of values and not dedicated to a 
precise field or table (it should be joined too many times): it is best 
effective to store metadata in memory and pick values from it.)

> Remember that with OGNL you *can* call arbitrary
> methods, including static utility methods, from with
> the EL. So with either a static decoding class or
> (preferably) a service object in your action if you're
> iterating over a list you can call methods on items
> from that list.
>
> d.

Ok, so it seems I'm missing some OGNL features: if I can call a method of an

Action that accept parameters in input then this is the solution. I'm going 
back to study and find how to.

Many thanks,
P.


---------------------------------------------------------------------
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: [S2] decoding values of objects properties

Posted by Paolo Beccari <pb...@email.it>.
----- Original Message ----- 
From: "Dave Newton" <ne...@yahoo.com>
To: "Struts Users Mailing List" <us...@struts.apache.org>
Sent: Wednesday, June 06, 2007 1:14 PM
Subject: Re: [S2] decoding values of objects properties


> I'm still not entirely what you're decoding from and
> to; it sounds like something is fundamentally broken,
> but...
>

Ok, I explain: suppose we have an entity with a state property that can 
assume values 0, 1 where 0 stands for "Active" and 1 stands for "Not 
Active".
state is the property name
0 is the value
"Active" is the "decoded" value

It's often useful (at database level) to map certain properties to numbers 
(or strings, or whatever) which belongs to a description in metadata, so it 
is possible (for example) to change the description without any side-effects 
on old stored data.

(Joining the table to retrieve the decoded value is not an option when the 
metadata table is shared through many sets of values and not dedicated to a 
precise field or table (it should be joined too many times): it is best 
effective to store metadata in memory and pick values from it.)

> Remember that with OGNL you *can* call arbitrary
> methods, including static utility methods, from with
> the EL. So with either a static decoding class or
> (preferably) a service object in your action if you're
> iterating over a list you can call methods on items
> from that list.
>
> d.

Ok, so it seems I'm missing some OGNL features: if I can call a method of an 
Action that accept parameters in input then this is the solution. I'm going 
back to study and find how to.

Many thanks,
P.


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


Re: [S2] decoding values of objects properties

Posted by Dave Newton <ne...@yahoo.com>.
I'm still not entirely what you're decoding from and
to; it sounds like something is fundamentally broken,
but...

Remember that with OGNL you *can* call arbitrary
methods, including static utility methods, from with
the EL. So with either a static decoding class or
(preferably) a service object in your action if you're
iterating over a list you can call methods on items
from that list.

d.

--- Paolo Beccari <pb...@email.it> wrote:

> 
> > --- Dave Newton  wrote:
> >
> > Why?
> >
> 
> I'll try to explain. The main problem is, that i
> would not to expose a 
> single getter-method in the action for each property
> I want to decode. I'm 
> searching for a more generic method.
> I thought on some possibile solution, one was to
> return, in each action, the 
> entire decode set (roughly speaking, a series of
> tuples name-value-decode). 
> That way, I could handle it with <s:iterator and
> <s:if tag each time I need 
> a decode. In addition, if the decoded value I'm
> searching is the last in the 
> list, the list is entirely scrolled before finding
> result. So I tend to 
> discard that.
> 
> Maybe it is only a matter of wrong architectural
> design: we are returning to 
> the views some objects mapped from the database
> layer "as they are". It is 
> possible we need an additional level between, to
> provide decoded values for 
> each property, but the temptation to use a scriplet
> <%=Decode(name, value)%> 
> with a generic, singleton Decoder class is still
> strong :).
> 
> >
> > I've never had to do that, but if I did, I'd be
> most
> > likely to do it in the action or, more likely, a
> > service object in the action.
> >
> > d.
> >
> 
> Yes, I'd be most likely to do, too. But I have to
> find a way to NOT write 
> hundreds of methods, one for each decode-set.
> Well, I'll continue thinking on it, BTW thanks for
> reply.
> 
> P.
> 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> user-unsubscribe@struts.apache.org
> For additional commands, e-mail:
> user-help@struts.apache.org
> 
> 



       
____________________________________________________________________________________
Get the free Yahoo! toolbar and rest assured with the added security of spyware protection.
http://new.toolbar.yahoo.com/toolbar/features/norton/index.php

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


Re: [S2] decoding values of objects properties

Posted by Paolo Beccari <pb...@email.it>.
> --- Dave Newton  wrote:
>
> Why?
>

I'll try to explain. The main problem is, that i would not to expose a 
single getter-method in the action for each property I want to decode. I'm 
searching for a more generic method.
I thought on some possibile solution, one was to return, in each action, the 
entire decode set (roughly speaking, a series of tuples name-value-decode). 
That way, I could handle it with <s:iterator and <s:if tag each time I need 
a decode. In addition, if the decoded value I'm searching is the last in the 
list, the list is entirely scrolled before finding result. So I tend to 
discard that.

Maybe it is only a matter of wrong architectural design: we are returning to 
the views some objects mapped from the database layer "as they are". It is 
possible we need an additional level between, to provide decoded values for 
each property, but the temptation to use a scriplet <%=Decode(name, value)%> 
with a generic, singleton Decoder class is still strong :).

>
> I've never had to do that, but if I did, I'd be most
> likely to do it in the action or, more likely, a
> service object in the action.
>
> d.
>

Yes, I'd be most likely to do, too. But I have to find a way to NOT write 
hundreds of methods, one for each decode-set.
Well, I'll continue thinking on it, BTW thanks for reply.

P.


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


Re: [S2] decoding values of objects properties

Posted by Dave Newton <ne...@yahoo.com>.
--- Paolo Beccari <pb...@email.it> wrote:
> I wish to decode them in the view.

Why?

> I think this is could be a common issue in a webapp,
> does anyone has an idea on how to resolve?

I've never had to do that, but if I did, I'd be most
likely to do it in the action or, more likely, a
service object in the action.

d.



       
____________________________________________________________________________________
Need a vacation? Get great deals
to amazing places on Yahoo! Travel.
http://travel.yahoo.com/

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