runevent

4 views
Skip to first unread message

andreacfm

unread,
May 26, 2009, 3:12:40 PM5/26/09
to model-glue
Hi,

I was trying to implement a sort of view-let in MG.
Is there a way to runa specific eventhandler from a view.

Something like runEvent('myEvent')

Thanks

Andrea

denstar

unread,
May 26, 2009, 7:14:47 PM5/26/09
to model...@googlegroups.com

With MVC, the idea is that the controller handles the events (by
talking to your model, hopefully), vs. spreading your event logic
throughout your app (like in your views).

Seems sorta like it should be MCV, neh?

At least that's my [limited] understanding of the pattern.

The most a view should do would have a link to the event, not run the
event itself (the controller should have done that, if it was needed).

I think. :)

--
We can recognize the dawn and the decline of love by the uneasiness we
feel when alone together.
Jean de la Bruyere

andreacfm

unread,
May 27, 2009, 3:44:18 AM5/27/09
to model-glue
Jena,

yes that is the general idea but sometimes a "portlet" approach is
really more efficient.

I assume this :

1) A very high traffic application cannot perform well with no
caching.
2) A quite big application is really more efficient when is divided
into small logical unit that are able to run / cache / refresh by
themselves.

Example:

You have a sidebar menu that in base of the event running generate a
different output ( selected item, tree opened etc......).
You have an event-handler that broadcast a controller to prepare data
( lets' say from a db or xml as you like ) and push into event objetc.
Your view take the data and make the output.
This is done for any event/page.

I can cache the hanlder: yes that's help but my logic/query run in
any case.
I can cache the view ( assuming that cache over an include in MG will
work, now is not ): yes but controller is fired in any case. I will
not use resources to make the output but I still run en event with no
need to use the data returned by that.

Better way:
I can cache the view ( in base of the event where is running ans maybe
a userid if needed ).
If no cached view run first time firing the event from the view
itself , making the output and caching it.
If you reload page no hit to event/controller is done. Just include
html.
When cache expire viewlet will run logic and cache again.
Sometimes that's a great way to use the event-handler system that an
mvc framework is able to give you.

This is not attempting to destroy MVC pattern but simply a better way
to use it in cases where your application allow you to do that.

Andrea

Zac Spitzer

unread,
May 27, 2009, 4:00:54 AM5/27/09
to model...@googlegroups.com
AddResult() is the MG way to do that,

it would be nice and easier to understand if a result name was
optional, ie allow just specifying the event name for a <RESULT>

it's great to have aliases, but looking over a lot of my modelglue xml
files, there seems to be a lot of duplication caused by the mandatory aliases

ie
<message-listener message="onRequestStart" />
implies
<message-listener message="onRequestStart" function="onRequestStart" />

z
--
Zac Spitzer -
http://zacster.blogspot.com
+61 405 847 168

andreacfm

unread,
May 27, 2009, 7:06:01 AM5/27/09
to model-glue
Zac,

I think It was not clear.
I want to call a MG eventHandler from the view outside of the implicit
event queue.

I see a public method like:

event.executeEventHandler()

That I am not able to run properly.

I cannot event think MG do not allow this.

Andrea

On May 27, 10:00 am, Zac Spitzer <zac.spit...@gmail.com> wrote:
> AddResult() is the MG way to do that,
>
> it would be nice and easier to understand if a result name was
> optional, ie allow just specifying the event name for a <RESULT>
>
> it's great to have aliases, but looking over a lot of my modelglue xml
> files, there seems to be a lot of duplication caused by the mandatory aliases
>
> ie
> <message-listener message="onRequestStart" />  
> implies
> <message-listener message="onRequestStart" function="onRequestStart" />      
>
> z
>
> On Wed, May 27, 2009 at 5:12 AM, andreacfm <acampolon...@gmail.com> wrote:
>
> > Hi,
>
> > I was trying to implement a sort of view-let in MG.
> > Is there a way to runa specific eventhandler from a view.
>
> > Something like runEvent('myEvent')
>
> > Thanks
>
> > Andrea
>
> --
> Zac Spitzer -http://zacster.blogspot.com
> +61 405 847 168

Chris Peterson

unread,
May 27, 2009, 7:11:54 AM5/27/09
to model...@googlegroups.com
Ok, maybe I am being too simplistic, but isn't a normal url request, like
GET or POST, invoking a request handler? I am still not following the need
for what you are asking, the view should not have anything but display and
links, to have the view actually invoke a handler / controller / service
directly would muddy the waters for me.



Chris Peterson

andreacfm

unread,
May 27, 2009, 8:05:11 AM5/27/09
to model-glue
Chris is easy,

I want to cache a view and do not have the handler run again when the
view for which
hanlder prepare datas is cached.
That's really unefficient.

Andrea


On May 27, 1:11 pm, Chris Peterson <overrid...@gmail.com> wrote:
> Ok, maybe I am being too simplistic, but isn't a normal url request, like
> GET or POST, invoking a request handler? I am still not following the need
> for what you are asking, the view should not have anything but display and
> links, to have the view actually invoke a handler / controller / service
> directly would muddy the waters for me.
>
> Chris Peterson
>

denstar

unread,
May 27, 2009, 4:40:33 PM5/27/09
to model...@googlegroups.com
On Wed, May 27, 2009 at 6:05 AM, andreacfm wrote:
>
> Chris is easy,
>
> I want to cache a view and do not have the handler run again when the
> view for which
> hanlder prepare datas is cached.
> That's really unefficient.

In the real world, sometimes we can't avoid doing "bad things" for
"good performance" reasons, but what you're suggesting really seems
like it should be doable within the MVC pattern.

Since you can "stack" views, how about caching the ones that don't
change, and not caching the ones that do?

I'm thinking there's a way to do the thing you're asking about without
mixing controller logic into your view, but I'm not completely sure
without a use-case.

Can you give us a little real-world walk-through of what you are
trying to accomplish?

--
The world is not comprehensible, but it is embraceable: through the
embracing of one of its beings.
Martin Buber

andreacfm

unread,
May 28, 2009, 5:53:09 AM5/28/09
to model-glue
Martin,

Ok.

I give the same example.
You have a sidebar of a web application. You have a site tree
navigation stored into a db ( like a cms should do ).
Any event is a page and in base of the event my sidebar will change.

I have my controller.doSidebar ( I read db and push into event the
data I need to make my sidebar )
I have my event-handler that broadcast and include the sidebar.cfm
view caching it.

In normal way MG should fire the controller that read the db and make
his things, inject data into event and then at the moment of
creating the view will just include the cached html created at the
previous call....
Controller fires for nothing and will do it for any event call.
A complex application can have many many views on a single pages that
should run a controller for nothing.

Being my sidebar predictable in base of the event where we are ( as
most of the part of a web application based on a n number of known
variables that I could use to create more cached versions of my code )
is a good candidate to be cached for long time, or for the entire
application life ( flush it when you need it ).

If I could be able to run the controller from the view layer I should
have:

Controller.doSidebar
My event-handler that broadcast the controller but do not include
nothing. Wait to be fired.
The 'main' event that include and cache my sidebar.cfm view.

So first time view is inlcuded:

runEvent('doSidebar');
make html

from this moment the runEvent will not be called anymore up to when
cache is flushed.

I think cache is essential.
With a good caching layer performance increase of 2 3 4 times.

I find a bit curioes that MG never implemented somethign like this
( coldbox and Mach II have this functionality.
I also fine a bit curious to discover that MG caching content do not
completely work on MG3 beta.

Andrea

Sean Coyne

unread,
May 28, 2009, 8:08:42 AM5/28/09
to model-glue

Why not do an ajax call to an MG event that returns the HTML (or xml
or json or whatever)? You can then use jQuery or innerHTML or
whatever to replace your sidebar with the returned HTML.

Then in your controller you can handle your caching.

Sean

andreacfm

unread,
May 28, 2009, 8:22:23 AM5/28/09
to model-glue
Sean,

makes no sense to me. Really.
This to me is an incredibly big limitation in MG.
I am quite surprised.

I cannot believe there is no way to call an Event-Handler outside the
implicit event invocation.

I was told MG was a great framework and it is but this is a killer to
me.

Any suggestion??

Someone from the MG team??

Andrea

Chris Peterson

unread,
May 28, 2009, 8:45:09 AM5/28/09
to model...@googlegroups.com
Sorry to be snippy, but this may come off a bit like that:

It really sounds like you are trying to do something before you fully
understand why it should not be done that way. If your views are directly
invoking controller / service methods, you are doing something wrong.
Re-factor your requirements a bit there, and do what you need inside a
controller rather than asking a view to do something that, based on
separation of concern, should *not* be done!

I know its sometimes a long road to grok this, but MG was designed (as are
most of the frameworks I am betting) such that the view is just that, the
view. No provisions are made for the view to call into the service tier
directly, as that is not what its job is, its there to generate output in
any form.

hth

Chris Peterson

andreacfm

unread,
May 28, 2009, 4:12:10 PM5/28/09
to model-glue
Chris,

really I do not get what is not clear.

View is not going to make logic but if MG do not is able to run events
outside of the implicit way
( via url ) is really limitated as framework itself.

Basically of all the mvc cf framework MG is the only one that do not
is designed to fire an event
programmatically.

Remember that the most advanced system implements portlets that are
nothing else than views that fire events
and manage data in a small unit that you can place where you like.
Be carefull ... fire event on teh same eventmanager .... i think that
this is the part that MG really miss ... being able to
be invoked as eventManager outisde of the implicit event url
invocation.

That's bad....very high traffic site will suffer this poor caching
capabilities.

Btw

Thanks for answering.

Andrea

@Chris
Read something about Jboss ot webspehre Portlets and you will get the
point.

On 28 Mag, 14:45, Chris Peterson <overrid...@gmail.com> wrote:
> Sorry to be snippy, but this may come off a bit like that:
>
> It really sounds like you are trying to do something before you fully
> understand why it should not be done that way. If your views are directly
> invoking controller / service methods, you are doing something wrong.
> Re-factor your requirements a bit there, and do what you need inside a
> controller rather than asking a view to do something that, based on
> separation of concern, should *not* be done!
>
> I know its sometimes a long road to grok this, but MG was designed (as are
> most of the frameworks I am betting) such that the view is just that, the
> view.  No provisions are made for the view to call into the service tier
> directly, as that is not what its job is, its there to generate output in
> any form.
>
> hth
>
> Chris Peterson
>

denstar

unread,
May 28, 2009, 4:46:11 PM5/28/09
to model...@googlegroups.com
On Thu, May 28, 2009 at 6:22 AM, andreacfm wrote:
>
> Sean,
>
> makes no sense to me. Really.
> This to me is an incredibly big limitation in MG.
> I am quite surprised.

As am I! If it were an incredibly big limitation, you'd think many,
many other people would have run into it. ;)

> I cannot believe there is no way to call an Event-Handler outside the
> implicit event invocation.

There is always a way, but the why is generally more important.

I don't see anything in your use-case that suggests what you want to
achieve can only be (or in face, should be) done in the view.

But FWIW: Have you looked at the RemotingService stuff? Using MG with
Flash, etc.?

On the reals tho, I think you haven't quite wrapped your head around
the MVC pattern (it's cool, neither have I).

Portlets don't seem to be "views firing events" (as far as I can
tell)-- check out the JSR:

http://jcp.org/en/jsr/detail?id=168

For the caching, sounds like you want to put a lot of stuff in each
session? Lots of per-session caching seems kind of hard to scale out,
but I'm no expert.

Let's see if we can't come up with a real world, MG-style solution for
your real-world example! I'm hot to try out the caching stuff too,
right after I finish some play with Scaffolds.

:DeN*

--
To be old can be glorious if one has not unlearned how to begin.
Martin Buber

andreacfm

unread,
May 29, 2009, 5:53:38 AM5/29/09
to model-glue
Denstar,

1) Exists avanced caching system that can easily be adapted to MG
( see ehCache for example ).
These systems are able to mange cache on ram as on disk as you
require.
Do you think igh traffic site use only ram caching??
Is absolutely normal to craete more content caching in base of any
n number of variables you need.

2) We are not talking of breaking MVC pattern. MVC pattern do not tell
you from which layer
an event can be invoked. What MG doeas is to adapt an MVC pattern
to an url call.....that's it.

I will try again and I will let it go....

I want to cache a view ok??
This view needs data to produce an output ok???

I run my event first time.
Controller is fired and make logic for preparing data.
The views receives data make html and cache itself.

I recall the event.
The view is cached so do not need data but ..... controller is fired
in any case.

Is that right???
Is that efficient to you???

Andrea

Jason Fisher

unread,
May 29, 2009, 4:24:10 PM5/29/09
to model...@googlegroups.com
If I understand your question correctly, I would recommend a broadcast message that cached the necessary data (if not in session, then query and add to session) and output the necessary HTML, then add that broadcast to the broadcasts block of any event that needed it.
 
If you wanted to strictly separate Model and View, then call the cache broadcast message and also add a view to the views block that adds the correct view to the current event.  In either case, it's not a separate Controller action, it's a reusable broadcast message or a reusable broadcast message + a reusable view message.
 
<broadcasts>
<message name="getCachedNav" />
</broadcasts>
<views>
<include name="navBar" template="dsp.cached.nav.cfm" />
<include name="body" template="dsp.main.body.display.cfm" />
</views>
 
Something like that.

denstar

unread,
May 29, 2009, 6:35:41 PM5/29/09
to model...@googlegroups.com
On Fri, May 29, 2009 at 3:53 AM, andreacfm wrote:
>
> Denstar,
>
> 1) Exists avanced caching system that can easily be adapted to MG
> ( see ehCache for example ).
>    These systems are able to mange cache on ram as on disk as you
> require.
>    Do you think igh traffic site use only ram caching??
>    Is absolutely normal to craete more content caching in base of any
> n number of variables you need.

I was just saying that it seems (to me, Read: not an expert) that if
you store a lot of info in the session, you've got to replicate that
info , right? Maybe I'm wrong, and there's no more overhead to
replicating session data than say, application data-- from my limited
exploration of caching, that doesn't seem to be the case, but I'm
always 100% capable of being quite wrong.

> 2) We are not talking of breaking MVC pattern. MVC pattern do not tell
> you from which layer
>    an event can be invoked. What MG doeas is to adapt an MVC pattern
> to an url call.....that's it.

Yes, it's beautifully uncomplicated, isn't it?

> I will try again and I will let it go....

I'm not meaning to frustrate you. There is a little communication
barrier to deal with, nothing we can't handle.

> I want to cache a view ok??
> This view needs data to produce an output ok???

With you so far...

> I run my event first time.
> Controller is fired and make logic for preparing data.
> The views receives data make html and cache itself.

Alright...

> I recall the event.
> The view is cached so do not need data but ..... controller is fired
> in any case.
>
> Is that right???
> Is that efficient to you???

In an MVC pattern, I'd always expect the controller to be involved
between my model and my view, so I'm not quite following you here.

Are you suggesting that the view take over some (all?) of the
controller's responsibilities?

You want the view to handle cache control? If you "set it and forget
it", why not go the dynamic to static content route, and leave the
appserver out of the picture? The webserver itself can cache and
serve out requests at some pretty impressive speeds...

I guess what I'm not getting is how moving controller logic into a
view makes caching easier/more robust.

If I was going to get heavy into caching, I'd be doing the lion's
share in my model, versus a non-agnostic location, such as MG.

I love my MG stuff to be simple. I dislike how easy it is to start
putting logic in controllers, or views, compared to in the model,
where (IMHO) it belongs. So I think I'm a little biased, and probably
come off as such.

I always try to think (even tho I don't have to, really) "how would I
use this same code in mach-ii or fusebox?", and similar thoughts.

Heck, I like "helpers", but I know that when I rely on them, I'm
relying on MG (which is fine, as I said, since I use MG, and don't
really foresee moving frameworks-- but still. =])

Eh. I'm sorta wandering now, so I'll shut up. Sorry if I put you off
with my demeanor. It just seemed that what you wanted was something I
rail against in general. *blush*

--
Dignity belongs to the conquered.
Kenneth Burke

Reply all
Reply to author
Forward
0 new messages