You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Torsten Römer <to...@luniks.net> on 2007/05/27 20:15:25 UTC

S2 tag property calls with arguments?

I guess this has been asked before but I have trouble finding an answer,
if it is somehow possible to give arguments to property calls in tags.
For example, if I'd have "vehicles" as list attribute in <s:select>,
that I could give literal arguments like "car" or "motorcycle" and have
a method like getVehicles(String type) { ... } in my backing bean.

A simple "yes" or "no" would already be very helpful :-)

Torsten

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


Re: S2 tag property calls with arguments?

Posted by Torsten Römer <to...@luniks.net>.
I should have a closer look at this... seems all very useful to know!

Thanks again!

Torsten

Sami Dalouche schrieb:
> Hi,
> 
> OGNL is yet another language  that one can use to access properties and
> methods. You can see it as a simplified language (like Groovy or Java
> itself) that is focused on data binding. 
> 
> To KISS, in Java, you would access your properties using :
> 
> obj.getProperty1().getProperty2().methodCall()
> 
> in OGNL, the syntax would be :
> obj.property1.property2.methodCall()
> 
> 
> In Java, you choose the object on which you apply the getProperty1()
> method. In OGNL, the object is implicit, and is called a context map. 
> A context Map is just a simple Hash Map where one of the objects is
> chosen as the ROOT. 
> 
> Struts2 has arbitrarily chosen to choose the Value Stack as the ROOT.
> So, that means that all the properties you call and your action's
> properties. 
> Another popular web framework, Tapestry, also uses OGNL. The Component /
> Page in Tapestry is the OGNL ROOT. 
> 
> Hope that helps,
> Sami Dalouche
> 
> 
> Le lundi 28 mai 2007 à 01:21 +0200, Torsten Römer a écrit :
>> Thanks Sami,
>>
>> That did definetely help, was just what I was looking for!
>>
>>> In Struts2, properties are accessed using the OGNL language
>> Somehow I haven't really realized what this actually means...
>>
>> Torsten
>>
>> Sami Dalouche schrieb:
>>> Hi,
>>>
>>> Not sure if I understand your question correctly, but it seems you are
>>> trying to make a Java method call from your View.
>>>
>>> In Struts2, properties are accessed using the OGNL language. The OGNL
>>> reference is available from http://www.ognl.org/.
>>>
>>> In particular, it is possible to make any method call using OGNL, using
>>> the simple syntax :
>>> myMethod(param1, param2)
>>>
>>> so, in your case, it could be
>>> getVehicles('car')
>>>
>>> Hope that helps,
>>> Regards,
>>> Sami Dalouche
>>>
>>> Le dimanche 27 mai 2007 à 20:15 +0200, Torsten Römer a écrit :
>>>> I guess this has been asked before but I have trouble finding an answer,
>>>> if it is somehow possible to give arguments to property calls in tags.
>>>> For example, if I'd have "vehicles" as list attribute in <s:select>,
>>>> that I could give literal arguments like "car" or "motorcycle" and have
>>>> a method like getVehicles(String type) { ... } in my backing bean.
>>>>
>>>> A simple "yes" or "no" would already be very helpful :-)
>>>>
>>>> Torsten
>>>>
>>>> ---------------------------------------------------------------------
>>>> 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
>>>
>>>
>>>
>> ---------------------------------------------------------------------
>> 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
> 
> 
> 

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


Re: S2 tag property calls with arguments?

Posted by Sami Dalouche <sk...@free.fr>.
Hi,

OGNL is yet another language  that one can use to access properties and
methods. You can see it as a simplified language (like Groovy or Java
itself) that is focused on data binding. 

To KISS, in Java, you would access your properties using :

obj.getProperty1().getProperty2().methodCall()

in OGNL, the syntax would be :
obj.property1.property2.methodCall()


In Java, you choose the object on which you apply the getProperty1()
method. In OGNL, the object is implicit, and is called a context map. 
A context Map is just a simple Hash Map where one of the objects is
chosen as the ROOT. 

Struts2 has arbitrarily chosen to choose the Value Stack as the ROOT.
So, that means that all the properties you call and your action's
properties. 
Another popular web framework, Tapestry, also uses OGNL. The Component /
Page in Tapestry is the OGNL ROOT. 

Hope that helps,
Sami Dalouche


Le lundi 28 mai 2007 à 01:21 +0200, Torsten Römer a écrit :
> Thanks Sami,
> 
> That did definetely help, was just what I was looking for!
> 
> > In Struts2, properties are accessed using the OGNL language
> 
> Somehow I haven't really realized what this actually means...
> 
> Torsten
> 
> Sami Dalouche schrieb:
> > Hi,
> > 
> > Not sure if I understand your question correctly, but it seems you are
> > trying to make a Java method call from your View.
> > 
> > In Struts2, properties are accessed using the OGNL language. The OGNL
> > reference is available from http://www.ognl.org/.
> > 
> > In particular, it is possible to make any method call using OGNL, using
> > the simple syntax :
> > myMethod(param1, param2)
> > 
> > so, in your case, it could be
> > getVehicles('car')
> > 
> > Hope that helps,
> > Regards,
> > Sami Dalouche
> > 
> > Le dimanche 27 mai 2007 à 20:15 +0200, Torsten Römer a écrit :
> >> I guess this has been asked before but I have trouble finding an answer,
> >> if it is somehow possible to give arguments to property calls in tags.
> >> For example, if I'd have "vehicles" as list attribute in <s:select>,
> >> that I could give literal arguments like "car" or "motorcycle" and have
> >> a method like getVehicles(String type) { ... } in my backing bean.
> >>
> >> A simple "yes" or "no" would already be very helpful :-)
> >>
> >> Torsten
> >>
> >> ---------------------------------------------------------------------
> >> 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
> > 
> > 
> > 
> 
> ---------------------------------------------------------------------
> 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 tag property calls with arguments?

Posted by Torsten Römer <to...@luniks.net>.
Thanks Sami,

That did definetely help, was just what I was looking for!

> In Struts2, properties are accessed using the OGNL language

Somehow I haven't really realized what this actually means...

Torsten

Sami Dalouche schrieb:
> Hi,
> 
> Not sure if I understand your question correctly, but it seems you are
> trying to make a Java method call from your View.
> 
> In Struts2, properties are accessed using the OGNL language. The OGNL
> reference is available from http://www.ognl.org/.
> 
> In particular, it is possible to make any method call using OGNL, using
> the simple syntax :
> myMethod(param1, param2)
> 
> so, in your case, it could be
> getVehicles('car')
> 
> Hope that helps,
> Regards,
> Sami Dalouche
> 
> Le dimanche 27 mai 2007 à 20:15 +0200, Torsten Römer a écrit :
>> I guess this has been asked before but I have trouble finding an answer,
>> if it is somehow possible to give arguments to property calls in tags.
>> For example, if I'd have "vehicles" as list attribute in <s:select>,
>> that I could give literal arguments like "car" or "motorcycle" and have
>> a method like getVehicles(String type) { ... } in my backing bean.
>>
>> A simple "yes" or "no" would already be very helpful :-)
>>
>> Torsten
>>
>> ---------------------------------------------------------------------
>> 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
> 
> 
> 

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


Re: S2 tag property calls with arguments?

Posted by Sami Dalouche <sk...@free.fr>.
Hi,

Not sure if I understand your question correctly, but it seems you are
trying to make a Java method call from your View.

In Struts2, properties are accessed using the OGNL language. The OGNL
reference is available from http://www.ognl.org/.

In particular, it is possible to make any method call using OGNL, using
the simple syntax :
myMethod(param1, param2)

so, in your case, it could be
getVehicles('car')

Hope that helps,
Regards,
Sami Dalouche

Le dimanche 27 mai 2007 à 20:15 +0200, Torsten Römer a écrit :
> I guess this has been asked before but I have trouble finding an answer,
> if it is somehow possible to give arguments to property calls in tags.
> For example, if I'd have "vehicles" as list attribute in <s:select>,
> that I could give literal arguments like "car" or "motorcycle" and have
> a method like getVehicles(String type) { ... } in my backing bean.
> 
> A simple "yes" or "no" would already be very helpful :-)
> 
> Torsten
> 
> ---------------------------------------------------------------------
> 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