Arguments for RunEvent or Viewlet

Hey all, I need some advice or help changing the way I'm thinking.

Context: an authenticated user main page that is composed of several
distinct views, for example, a list of products by date.

Goals: separate view and business logic; encapsulate business logic in
an event for each composing view so that it can be used in other areas
of the site without duplicating code and so that the main event for
the page isn't too big/complicated to easily maintain.

My first instinct was to use runEvent from the main event to pull in
all of the data needed to render each view. However, I don't see any
way to pass the variable(s) with runEvent. My instincts are against
putting the variable(s) into the request collection and pulling it out
again. It feels very procedural, and I'm concerned about collision.
To me it seems as though the called event should be able to recieve
arguments and should itself decide if it needs to place any of those
arguments into the request collection. If the delegated event were in
the same handler as the main event, I could call it directly as a
method, however it is (and should be) in a different handler.

My second instinct was to use the 'viewlet' pattern and run the event
at the top of the viewlet file. However that seems to put too much
logic into the view code for my comfort. Since this viewlet (search
results) may be reused in several places in the application, I would
have to figure out how it's being used to determine what values to
search by. And then I still have to put those into the request
collection and run the event.

Is there a way I can do this?

Where are the arguments that you’d want to pass to the event or the viewlet coming from? URL or Form values? Or something else?

  • Gabriel