You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by Ryan Wynn <bi...@gmail.com> on 2005/11/16 21:15:04 UTC

[shale] ClayViewHandler listener

From my experience using clay I think it would be nice if the
ClayViewHandler accepted listeners that get invoked after the clay
component has been created but before rendering to the outputstream.

This is the case that I have.  I have a render phase listener that
adds javascript, stylesheets, etc before the render phase.  I would
like this listener to know about the faces tree so that I can add
certain javascript only if the tree contains certain components.  The
phase listener doesn't work because it only gives me hooks into before
render and after render.  Before render the tree has not been created
yet, and after render it has already been commited to the stream.  So
in ClayViewHandler I would need something like

UIComponent component = view.findComponent(CLAY_VIEW_ID);
if (component == null) {
  // create clay
}

// start new
Iterator i = getClayListeners().iterator();
while (i.hasNext()) {
   ClayListener next = (ClayListener) i.next();
   next.afterClayCreated(context);
}
// end new

ServletResponse response = ...

This would allow me to inspect the tree and add the appropriate
javascript to the view.

Thanks,
Ryan

Re: [shale] ClayViewHandler listener

Posted by Ryan Wynn <bi...@gmail.com>.
Okay, the override Clay class idea won't work.

My last alternative is to use Clay's chain integration.  I noticed
that in the clay-chain.config I can plug a Filter command into the
addComponent chain that would do the trick.  I read up on Chain and it
seems that I can't just plug a command into an existing chain.  I
tried just adding my own chain-config.xml and putting the command into
the appropriate catalog/chain.  Unfortunately, Clay then finds my
partial chain instead of aggregating.  Is there any way have the chain
parser aggregate chains or is this just not supported?  My workaround
was to copy the entire shale-clay-config.xml into mine and then add
the Filter command.  This works but obviously is not the best
approach.




On 11/16/05, Ryan Wynn <bi...@gmail.com> wrote:
> Actually, the more I look at this I think I can may be able to achieve
> the same thing by extending the Clay class.  Does anyone know if you
> can override the component class associated with a component-type in
> faces-config.xml?
>
> I could add
>
> <component>
>  <component-type>org.apache.shale.clay.component.Clay</component-type>
>  <component-class>foo.bar.MyClayExtension</component-class>
> </component>
>
> If you can override component classes like renderer classes then I
> might be in luck.
> I can add what I was trying to do in encodeEnd.
>
>
>
>
> On 11/16/05, Ryan Wynn <bi...@gmail.com> wrote:
> > From my experience using clay I think it would be nice if the
> > ClayViewHandler accepted listeners that get invoked after the clay
> > component has been created but before rendering to the outputstream.
> >
> > This is the case that I have.  I have a render phase listener that
> > adds javascript, stylesheets, etc before the render phase.  I would
> > like this listener to know about the faces tree so that I can add
> > certain javascript only if the tree contains certain components.  The
> > phase listener doesn't work because it only gives me hooks into before
> > render and after render.  Before render the tree has not been created
> > yet, and after render it has already been commited to the stream.  So
> > in ClayViewHandler I would need something like
> >
> > UIComponent component = view.findComponent(CLAY_VIEW_ID);
> > if (component == null) {
> >  // create clay
> > }
> >
> > // start new
> > Iterator i = getClayListeners().iterator();
> > while (i.hasNext()) {
> >   ClayListener next = (ClayListener) i.next();
> >   next.afterClayCreated(context);
> > }
> > // end new
> >
> > ServletResponse response = ...
> >
> > This would allow me to inspect the tree and add the appropriate
> > javascript to the view.
> >
> > Thanks,
> > Ryan
> >
>

Re: [shale] ClayViewHandler listener

Posted by Ryan Wynn <bi...@gmail.com>.
Actually, the more I look at this I think I can may be able to achieve
the same thing by extending the Clay class.  Does anyone know if you
can override the component class associated with a component-type in
faces-config.xml?

I could add

<component>
  <component-type>org.apache.shale.clay.component.Clay</component-type>
  <component-class>foo.bar.MyClayExtension</component-class>
</component>

If you can override component classes like renderer classes then I
might be in luck.
I can add what I was trying to do in encodeEnd.




On 11/16/05, Ryan Wynn <bi...@gmail.com> wrote:
> From my experience using clay I think it would be nice if the
> ClayViewHandler accepted listeners that get invoked after the clay
> component has been created but before rendering to the outputstream.
>
> This is the case that I have.  I have a render phase listener that
> adds javascript, stylesheets, etc before the render phase.  I would
> like this listener to know about the faces tree so that I can add
> certain javascript only if the tree contains certain components.  The
> phase listener doesn't work because it only gives me hooks into before
> render and after render.  Before render the tree has not been created
> yet, and after render it has already been commited to the stream.  So
> in ClayViewHandler I would need something like
>
> UIComponent component = view.findComponent(CLAY_VIEW_ID);
> if (component == null) {
>  // create clay
> }
>
> // start new
> Iterator i = getClayListeners().iterator();
> while (i.hasNext()) {
>   ClayListener next = (ClayListener) i.next();
>   next.afterClayCreated(context);
> }
> // end new
>
> ServletResponse response = ...
>
> This would allow me to inspect the tree and add the appropriate
> javascript to the view.
>
> Thanks,
> Ryan
>