You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Mark Menard <ma...@mjm.net> on 2007/02/13 18:49:51 UTC

[s2] Groovy Actions in Struts 2

I've recently started using Groovy in my Struts 2 project to write my
actions. After some experience with it, I've written up a blog entry with
some quick examples.

http://www.vitarara.org/cms/node/95

Mark

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


Re: [s2] Groovy Actions in Struts 2

Posted by Mark Menard <ma...@mjm.net>.
On 2/13/07 12:54 PM, "Don Brown" <do...@gmail.com> wrote:

> Very cool.  Please add a link in our Struts 2 wiki [1] to it for
> future reference.

Done. I also added some of the other writeups I've done.

Mark

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


Re: [s2] Groovy Actions in Struts 2

Posted by Don Brown <do...@gmail.com>.
Very cool.  Please add a link in our Struts 2 wiki [1] to it for
future reference.

Don

[1] http://cwiki.apache.org/confluence/display/S2WIKI

On 2/13/07, Mark Menard <ma...@mjm.net> wrote:
> I've recently started using Groovy in my Struts 2 project to write my
> actions. After some experience with it, I've written up a blog entry with
> some quick examples.
>
> http://www.vitarara.org/cms/node/95
>
> Mark
>
> ---------------------------------------------------------------------
> 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] Groovy Actions in Struts 2

Posted by Tamas Szabo <sz...@gmail.com>.
Yes, cool stuff.

You might also be interested in:
http://www.vim.org/scripts/script.php?script_id=490 ;-)

Tamas


On 2/14/07, Mark Menard <ma...@mjm.net> wrote:
> I've recently started using Groovy in my Struts 2 project to write my
> actions. After some experience with it, I've written up a blog entry with
> some quick examples.
>
> http://www.vitarara.org/cms/node/95
>
> Mark
>
> ---------------------------------------------------------------------
> 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: [OT] Re: [s2] Groovy Actions in Struts 2

Posted by Ted Husted <hu...@apache.org>.
Most often, the Actions work as an adapter between a view layer and a
general-purpose business facade. Because the Actions select a token
indicating a result, the Actions tend to be bound to some type of
navigational system. A classic Action passes input values to the
business facade, and the business facade returns output values, along
with any error or status messages. (The latter often being indicated
by exceptions.)  By creating a generic business facade, we can use it
with other view layers (which would include unit tests) that utilize
the same business logic, but may implement a different navigational
system.

Of course, since S2 Actions are generic, it would be possible to use
XWork and Actions as a business facade. But, the problem people often
run into as applications grow is that there is not a clear line where
the business facade ends and the web adapter begins.

At my day job, we're moving the UI for our next application over to
Ajax. It's a .NET application, so we are not using Struts, but we are
using a business facade based on a port of Commons Chain. The business
methods are represented as individual commands, some of which call out
to iBATIS.NET while resolving the other business logic. We chain
commands together to create a "transaction script" (to use Martin
Fowler's term).

In our case, Ajax makes the MVC separation very clear. In the last
application, the ASP codebehind would make one or more calls to the
business facade, to populate the various controls and whatnot. In this
application, the various Ajax widgets and whatnot can populate
themselves by making asynchronous calls to a JSON-RPC handler.

The handler is essentially a servlet that acts as an adapter between
the business facade and the Ajax widgets. The cool part is that we are
able to use the exact same business facade that we used with the prior
application with zero-changes. Instead of the ASP codebehind making
the calls, the JSON-RPC makes the same calls on behalf of the Ajax
widgets. We're quite happy with the result. But, the key was that we
clearly separated the business services from the rest of the
application, making them easy to reuse it in a different UI (ASPX
versus Ajax).

(To be clear, we are not using ASP pages at all anymore. Just HTML
pages that call a C# JSON-RPC handler (Jayrock), which I believe is
the same sort of thing as DWR.)

-Ted.


On 2/16/07, Dave Newton <ne...@yahoo.com> wrote:
> --- Ian Roughley <ia...@fdar.com> wrote:
> > > I'm not sure what you mean by that... it's just a
> > > class; it happens to be compiled on-the-fly during
> > > bean instantiation. Not much else is different.
> > Yes, but it feels to me like you are reaching back
> > into the business service tier to create classes
> that
> > are primarily view tier - just feels backwards to
> me.
>
> Wait, what? Which is the "business service tier"?
>
> I'm not convinced that Actions are "view tier,"
> either, since they're really just command pattern
> implementations... I suppose the result values tie
> them to the view tier, but... boy, I dunno.
>
> Hrm, that'll give me things to think about over the
> weekend :)
>
> Dave

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


[OT] Re: [s2] Groovy Actions in Struts 2

Posted by Dave Newton <ne...@yahoo.com>.
--- Ian Roughley <ia...@fdar.com> wrote:
> > I'm not sure what you mean by that... it's just a
> > class; it happens to be compiled on-the-fly during
> > bean instantiation. Not much else is different.
> Yes, but it feels to me like you are reaching back
> into the business service tier to create classes
that 
> are primarily view tier - just feels backwards to
me.  

Wait, what? Which is the "business service tier"? 

I'm not convinced that Actions are "view tier,"
either, since they're really just command pattern
implementations... I suppose the result values tie
them to the view tier, but... boy, I dunno.

Hrm, that'll give me things to think about over the
weekend :)

Dave



 
____________________________________________________________________________________
Never miss an email again!
Yahoo! Toolbar alerts you the instant new Mail arrives.
http://tools.search.yahoo.com/toolbar/features/mail/

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


Re: [s2] Groovy Actions in Struts 2

Posted by Ian Roughley <ia...@fdar.com>.
>> I also personally think that defining actions in a 
>> service tier doesn't "smell" right.
>>     
>
> I'm not sure what you mean by that... it's just a
> class; it happens to be compiled on-the-fly during
> bean instantiation. Not much else is different.
>
>   
Yes, but it feels to me like you are reaching back into the business 
service tier to create classes that are primarily view tier - just feels 
backwards to me.  Technically, I understand it is no different.


Re: [s2] Groovy Actions in Struts 2

Posted by Dave Newton <ne...@yahoo.com>.
--- Ian Roughley <ia...@fdar.com> wrote:
> I'm not sure about Spring's groovy support, and
> whether it allows for hot swapping.

You can define how frequently it will check the script
for updates, even.

> I also personally think that defining actions in a 
> service tier doesn't "smell" right.

I'm not sure what you mean by that... it's just a
class; it happens to be compiled on-the-fly during
bean instantiation. Not much else is different.

d.



 
____________________________________________________________________________________
Looking for earth-friendly autos? 
Browse Top Cars by "Green Rating" at Yahoo! Autos' 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


Re: [s2] Groovy Actions in Struts 2

Posted by Ian Roughley <ia...@fdar.com>.
I think it was Chris from Adigio that had the blog entry.  The proxy 
basically always checked the filesystem for the latest .groovy script, 
and then used it.

I'm not sure about Spring's groovy support, and whether it allows for 
hot swapping.  I also personally think that defining actions in a 
service tier doesn't "smell" right.

/Ian


Dave Newton wrote:
> --- Mark Menard <ma...@mjm.net> wrote:
>   
>> Oooh... I was thinking about something like that,
>> where you would not need
>> to keep reloading the application, but be able to
>> change the script, have it
>> dynamically recompile and simply hit reload. Kind of
>> like you can do with
>> JSP files under the Maven Jetty Plugin.
>>     
>
> You can configure Spring2 beans to do this via the
> <lang:groovy.../> element. 
>
> It's not clear to me if you can configure it so the
> Groovy action can be hot-compiled w/ a standard
> <bean.../> element but w/ a combination of refs or
> something I'd bet you could.
>
> d.
>
>
>
>  
> ____________________________________________________________________________________
> Never miss an email again!
> Yahoo! Toolbar alerts you the instant new Mail arrives.
> http://tools.search.yahoo.com/toolbar/features/mail/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>   

Re: [s2] Groovy Actions in Struts 2

Posted by Wendy Smoak <ws...@gmail.com>.
On 2/14/07, Mark Menard <ma...@mjm.net> wrote:

> I have Spring configured, but when it goes to instantiate the Groovy action
> class from the script it's not on the classpath. My environment:
>
>     * Maven 2 (based off the Struts 2 Archetype)
>     * Jetty plugin
>     * Groovy source files mixed into src/main/java
>
> I know my issue is that the .groovy files are not being copied from
> src/main/java to the target directory. Problem is I'm pretty much a Maven
> novice. In ant I'd just make a task to do it, but I have no idea how to do
> that in Maven.

Put them in src/main/resources and they will be picked up automatically.

If you want them in with your Java sources, then you'll need to tell
Maven about them.

Note that you then have to explictly mention the default of
src/main/resources, in addition to your custom locations.  Something
like...

<build>
   ...
   <resources>
      <resource>
        <directory>src/main/resources</directory>
      </resource>
      <resource>
        <directory>src/main/java</directory>
        <includes>
          <include>**/*.groovy</include>
        <includes/>
      </resource>
    </resources>
   ...

-- 
Wendy

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


Re: [s2] Groovy Actions in Struts 2

Posted by Mark Menard <ma...@mjm.net>.
On 2/14/07 10:03 AM, "Dave Newton" <ne...@yahoo.com> wrote:

> You can configure Spring2 beans to do this via the
> <lang:groovy.../> element.
> 
> It's not clear to me if you can configure it so the
> Groovy action can be hot-compiled w/ a standard
> <bean.../> element but w/ a combination of refs or
> something I'd bet you could.

I did some research and found the Groovy actions in WebWork post from
Christian at Adigio. That doesn't work for me, because he was using WebWork
to instantiate his actions. I'm using Spring. So, that got me thinking about
making a bean factory that would do dynamic reloading of Groovy beans, then
discovered the Spring already does it.

I have Spring configured, but when it goes to instantiate the Groovy action
class from the script it's not on the classpath. My environment:

    * Maven 2 (based off the Struts 2 Archetype)
    * Jetty plugin
    * Groovy source files mixed into src/main/java

I know my issue is that the .groovy files are not being copied from
src/main/java to the target directory. Problem is I'm pretty much a Maven
novice. In ant I'd just make a task to do it, but I have no idea how to do
that in Maven.

I'd like to get Jetty to just add the Groovy files to the classpath, and
additionally not restart the application server when a groovy class is
saved. Just leave the reloading to Spring.

Then I did some more research and it appears that Spring script beans are
strictly singletons. So, that won't work for Struts 2 actions.
(http://forum.springframework.org/showthread.php?p=101486) I'm going to
follow that thread on the Spring forum, and I'll report back when I've got
more information.

Mark

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


Re: [s2] Groovy Actions in Struts 2

Posted by Dave Newton <ne...@yahoo.com>.
--- Mark Menard <ma...@mjm.net> wrote:
> Oooh... I was thinking about something like that,
> where you would not need
> to keep reloading the application, but be able to
> change the script, have it
> dynamically recompile and simply hit reload. Kind of
> like you can do with
> JSP files under the Maven Jetty Plugin.

You can configure Spring2 beans to do this via the
<lang:groovy.../> element. 

It's not clear to me if you can configure it so the
Groovy action can be hot-compiled w/ a standard
<bean.../> element but w/ a combination of refs or
something I'd bet you could.

d.



 
____________________________________________________________________________________
Never miss an email again!
Yahoo! Toolbar alerts you the instant new Mail arrives.
http://tools.search.yahoo.com/toolbar/features/mail/

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


Re: [s2] Groovy Actions in Struts 2

Posted by Mark Menard <ma...@mjm.net>.
On 2/14/07 9:46 AM, "Ian Roughley" <ia...@fdar.com> wrote:

> I remember seeing Groovy support on a blog for WebWork a while back.  I
> think the implementation was a new ActionProxy, so the groovy actions
> could be scripted dynamically at run time and the page only needed to be
> refreshed.  For some reason, pre-compiling the groovy actions into class
> files, and using the language that way didn't register with me.

Oooh... I was thinking about something like that, where you would not need
to keep reloading the application, but be able to change the script, have it
dynamically recompile and simply hit reload. Kind of like you can do with
JSP files under the Maven Jetty Plugin.

I'll do some looking around and see if I can find anything on this.

Thanks,

Mark

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


Re: [s2] Groovy Actions in Struts 2

Posted by Ian Roughley <ia...@fdar.com>.
I remember seeing Groovy support on a blog for WebWork a while back.  I 
think the implementation was a new ActionProxy, so the groovy actions 
could be scripted dynamically at run time and the page only needed to be 
refreshed.  For some reason, pre-compiling the groovy actions into class 
files, and using the language that way didn't register with me.

/Ian

Vinny wrote:
> I read trough your blog entry. This is brilliant.
> I'm a groovy newbie myself and I plan to tinker with Groovy actions.
> Perhaps s2 might end up becoming a nice web platform for Groovy
> in addition to Grails.
>
>
>
> On 2/13/07 3:22 PM, "Ian Roughley" <ia...@fdar.com> wrote:
>>
>> > Very cool.  If only Groovy supported annotations so that the
>> > configuration didn't need to be in the struts.xml file (but it looks
>> > like annotation support is starting).
>>
>> Ian,
>>
>> From your lips to G_d's ears. I can't wait for annotations.
>>
>> Mark
>>
>> ---------------------------------------------------------------------
>> 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] Groovy Actions in Struts 2

Posted by Vinny <xa...@gmail.com>.
I read trough your blog entry. This is brilliant.
I'm a groovy newbie myself and I plan to tinker with Groovy actions.
Perhaps s2 might end up becoming a nice web platform for Groovy
in addition to Grails.



On 2/13/07 3:22 PM, "Ian Roughley" <ia...@fdar.com> wrote:
>
> > Very cool.  If only Groovy supported annotations so that the
> > configuration didn't need to be in the struts.xml file (but it looks
> > like annotation support is starting).
>
> Ian,
>
> From your lips to G_d's ears. I can't wait for annotations.
>
> Mark
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>


-- 
Ghetto Java: http://www.ghettojava.com

Re: [s2] Groovy Actions in Struts 2

Posted by Mark Menard <ma...@mjm.net>.
On 2/13/07 3:22 PM, "Ian Roughley" <ia...@fdar.com> wrote:

> Very cool.  If only Groovy supported annotations so that the
> configuration didn't need to be in the struts.xml file (but it looks
> like annotation support is starting).

Ian,

>From your lips to G_d's ears. I can't wait for annotations.

Mark

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


Re: [s2] Groovy Actions in Struts 2

Posted by Ian Roughley <ia...@fdar.com>.
Very cool.  If only Groovy supported annotations so that the 
configuration didn't need to be in the struts.xml file (but it looks 
like annotation support is starting).

/Ian


Mark Menard wrote:
> I've recently started using Groovy in my Struts 2 project to write my
> actions. After some experience with it, I've written up a blog entry with
> some quick examples.
>
> http://www.vitarara.org/cms/node/95
>
> Mark
>
> ---------------------------------------------------------------------
> 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