Struts tags with Groovy meta programming

View: New views
5 Messages — Rating Filter:   Alert me  

Struts tags with Groovy meta programming

by Ronny Løvtangen-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


How can I from a Struts tag access properties that is overridden by  
Groovy meta programming?
Example:

Bar.groovy
---------------

class Bar {
        String baz
}



FooAction.groovy
-------------------------

class FooAction extends ActionSupport {

        Bar bar

        String retrieveBar() {
                bar = new Bar(baz: "original value")
                bar.metaClass.getBaz = {"new value"}
                return SUCCESS
        }
}

foo.jsp
--------

<%@ taglib prefix="s" uri="/struts-tags" %>
Baz is: <s:property value="bar.baz"/>




Which yields the output  "Baz is: original value"

I was expecting "Baz is: new value", which is true for this test:


class FooActionTest extends GroovyTestCase {

        void testRetrieveBar() {
                FooAction action = new FooAction()
                action.retrieveBar()
                assertEquals "new value", action.bar.baz
        }
}


Any idea on how I from a Struts tag can invoke the overridden getBaz  
method instead of the original one?


Ronny

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


Re: Struts tags with Groovy meta programming

by Ronny Løvtangen-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Anyone?

Does the struts tags do some reflection magic that bypass the Groovy  
MetaClass?


On Nov 9, 2009, at 5:55 PM, Ronny Løvtangen wrote:

>
> How can I from a Struts tag access properties that is overridden by  
> Groovy meta programming?
> Example:
>
> Bar.groovy
> ---------------
>
> class Bar {
> String baz
> }
>
>
>
> FooAction.groovy
> -------------------------
>
> class FooAction extends ActionSupport {
>
> Bar bar
>
> String retrieveBar() {
> bar = new Bar(baz: "original value")
> bar.metaClass.getBaz = {"new value"}
> return SUCCESS
> }
> }
>
> foo.jsp
> --------
>
> <%@ taglib prefix="s" uri="/struts-tags" %>
> Baz is: <s:property value="bar.baz"/>
>
>
>
>
> Which yields the output  "Baz is: original value"
>
> I was expecting "Baz is: new value", which is true for this test:
>
>
> class FooActionTest extends GroovyTestCase {
>
> void testRetrieveBar() {
> FooAction action = new FooAction()
> action.retrieveBar()
> assertEquals "new value", action.bar.baz
> }
> }
>
>
> Any idea on how I from a Struts tag can invoke the overridden getBaz  
> method instead of the original one?
>
>
> Ronny
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@...
> For additional commands, e-mail: user-help@...
>


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


Re: Struts tags with Groovy meta programming

by Musachy Barroso :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

yes, field/methods are calling using reflection, I have no idea how
the Groovy MetaClass works. You can look at the OGNLReflectionProvider
class, that's the one doing the reflection stuff.

musachy

On Tue, Nov 10, 2009 at 7:10 AM, Ronny Løvtangen <lists@...> wrote:

> Anyone?
>
> Does the struts tags do some reflection magic that bypass the Groovy
> MetaClass?
>
>
> On Nov 9, 2009, at 5:55 PM, Ronny Løvtangen wrote:
>
>>
>> How can I from a Struts tag access properties that is overridden by Groovy
>> meta programming?
>> Example:
>>
>> Bar.groovy
>> ---------------
>>
>> class Bar {
>>        String baz
>> }
>>
>>
>>
>> FooAction.groovy
>> -------------------------
>>
>> class FooAction extends ActionSupport {
>>
>>        Bar bar
>>
>>        String retrieveBar() {
>>                bar = new Bar(baz: "original value")
>>                bar.metaClass.getBaz = {"new value"}
>>                return SUCCESS
>>        }
>> }
>>
>> foo.jsp
>> --------
>>
>> <%@ taglib prefix="s" uri="/struts-tags" %>
>> Baz is: <s:property value="bar.baz"/>
>>
>>
>>
>>
>> Which yields the output  "Baz is: original value"
>>
>> I was expecting "Baz is: new value", which is true for this test:
>>
>>
>> class FooActionTest extends GroovyTestCase {
>>
>>        void testRetrieveBar() {
>>                FooAction action = new FooAction()
>>                action.retrieveBar()
>>                assertEquals "new value", action.bar.baz
>>        }
>> }
>>
>>
>> Any idea on how I from a Struts tag can invoke the overridden getBaz
>> method instead of the original one?
>>
>>
>> Ronny
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@...
>> For additional commands, e-mail: user-help@...
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@...
> For additional commands, e-mail: user-help@...
>
>

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


RE: Struts tags with Groovy meta programming

by mgainty :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


ask this question on tomcat-users list

Groovy and all CGI languages do not exist in J2EE world (correction i havent seen any Groovy parsers implemented in TC,GF or WL or JBoss)
Groovy Rails as GRAILS with Spring Framework is available at
http://grails.org

Martin Gainty
______________________________________________
Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité
 
Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen.
Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité pour le contenu fourni.




> Subject: Re: Struts tags with Groovy meta programming
> From: lists@...
> Date: Tue, 10 Nov 2009 16:10:08 +0100
> To: user@...
>
> Anyone?
>
> Does the struts tags do some reflection magic that bypass the Groovy  
> MetaClass?
>
>
> On Nov 9, 2009, at 5:55 PM, Ronny Løvtangen wrote:
>
> >
> > How can I from a Struts tag access properties that is overridden by  
> > Groovy meta programming?
> > Example:
> >
> > Bar.groovy
> > ---------------
> >
> > class Bar {
> > String baz
> > }
> >
> >
> >
> > FooAction.groovy
> > -------------------------
> >
> > class FooAction extends ActionSupport {
> >
> > Bar bar
> >
> > String retrieveBar() {
> > bar = new Bar(baz: "original value")
> > bar.metaClass.getBaz = {"new value"}
> > return SUCCESS
> > }
> > }
> >
> > foo.jsp
> > --------
> >
> > <%@ taglib prefix="s" uri="/struts-tags" %>
> > Baz is: <s:property value="bar.baz"/>
> >
> >
> >
> >
> > Which yields the output  "Baz is: original value"
> >
> > I was expecting "Baz is: new value", which is true for this test:
> >
> >
> > class FooActionTest extends GroovyTestCase {
> >
> > void testRetrieveBar() {
> > FooAction action = new FooAction()
> > action.retrieveBar()
> > assertEquals "new value", action.bar.baz
> > }
> > }
> >
> >
> > Any idea on how I from a Struts tag can invoke the overridden getBaz  
> > method instead of the original one?
> >
> >
> > Ronny
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@...
> > For additional commands, e-mail: user-help@...
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@...
> For additional commands, e-mail: user-help@...
>
     
_________________________________________________________________
Bing brings you maps, menus, and reviews organized in one place.
http://www.bing.com/search?q=restaurants&form=MFESRP&publ=WLHMTAG&crea=TEXT_MFESRP_Local_MapsMenu_Resturants_1x1

Re: Struts tags with Groovy meta programming

by Musachy Barroso :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

please pardon the bot, it hasn't been patched in a while, this *is*
the right place to ask this question.

musachy

On Tue, Nov 10, 2009 at 12:57 PM, Martin Gainty <mgainty@...> wrote:

>
> ask this question on tomcat-users list
>
> Groovy and all CGI languages do not exist in J2EE world (correction i havent seen any Groovy parsers implemented in TC,GF or WL or JBoss)
> Groovy Rails as GRAILS with Spring Framework is available at
> http://grails.org
>
> Martin Gainty
> ______________________________________________
> Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité
>
> Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen.
> Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité pour le contenu fourni.
>
>
>
>
>> Subject: Re: Struts tags with Groovy meta programming
>> From: lists@...
>> Date: Tue, 10 Nov 2009 16:10:08 +0100
>> To: user@...
>>
>> Anyone?
>>
>> Does the struts tags do some reflection magic that bypass the Groovy
>> MetaClass?
>>
>>
>> On Nov 9, 2009, at 5:55 PM, Ronny Løvtangen wrote:
>>
>> >
>> > How can I from a Struts tag access properties that is overridden by
>> > Groovy meta programming?
>> > Example:
>> >
>> > Bar.groovy
>> > ---------------
>> >
>> > class Bar {
>> >     String baz
>> > }
>> >
>> >
>> >
>> > FooAction.groovy
>> > -------------------------
>> >
>> > class FooAction extends ActionSupport {
>> >
>> >     Bar bar
>> >
>> >     String retrieveBar() {
>> >             bar = new Bar(baz: "original value")
>> >             bar.metaClass.getBaz = {"new value"}
>> >             return SUCCESS
>> >     }
>> > }
>> >
>> > foo.jsp
>> > --------
>> >
>> > <%@ taglib prefix="s" uri="/struts-tags" %>
>> > Baz is: <s:property value="bar.baz"/>
>> >
>> >
>> >
>> >
>> > Which yields the output  "Baz is: original value"
>> >
>> > I was expecting "Baz is: new value", which is true for this test:
>> >
>> >
>> > class FooActionTest extends GroovyTestCase {
>> >
>> >     void testRetrieveBar() {
>> >             FooAction action = new FooAction()
>> >             action.retrieveBar()
>> >             assertEquals "new value", action.bar.baz
>> >     }
>> > }
>> >
>> >
>> > Any idea on how I from a Struts tag can invoke the overridden getBaz
>> > method instead of the original one?
>> >
>> >
>> > Ronny
>> >
>> > ---------------------------------------------------------------------
>> > To unsubscribe, e-mail: user-unsubscribe@...
>> > For additional commands, e-mail: user-help@...
>> >
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@...
>> For additional commands, e-mail: user-help@...
>>
>
> _________________________________________________________________
> Bing brings you maps, menus, and reviews organized in one place.
> http://www.bing.com/search?q=restaurants&form=MFESRP&publ=WLHMTAG&crea=TEXT_MFESRP_Local_MapsMenu_Resturants_1x1

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