The EnclosureResolver... container.autoAdd seems to be invoked only in the
parsing
phase of the original request, whereas the onBeforeRender is invoked during
handling
of the AjaxRequest (when the listener is attached to the AjaxRequestTarget).

I found out that the Enclosure is not a child of a Page, thus making it
quite elusive
to get hold of in the onBeforeRespond event. I even attempted to read
MarkupStream,
and indeed found the tag there. (source below) However, in order to add it
to the requestTarget, we
need to get hold of the component. I tried to read the path of the tag in
the document
using ComponentTag.getPath(), but it was null. This is where i hit brick
wall.

Is it possible to get hold of the Enclosure component with only
the WicketTag from the
MarkupStream as reference? If not, i think this approach might not be
viable.


// Override of the application class method newAjaxRequestTarget, trying to
find enclosures that have
// the child id of a component
// in the ajaxTarget:
//-----------------------
@Override
public AjaxRequestTarget newAjaxRequestTarget(Page page) {
    AjaxRequestTarget target = super.newAjaxRequestTarget(page);
    target.addListener(new AjaxRequestTarget.IListener() {

        public void onBeforeRespond(Map<String, Component> map,
AjaxRequestTarget target) { List<String> ids = new ArrayList<String>(); Page
page = null; // first read all the component id:s from the target for
(Component component : map.values()) { page = component.getPage();
ids.add(component.getId()); } // then traverse the markupStream to find
enclosureTags if (page != null) { MarkupStream stream =
page.getMarkupStream(); stream.setCurrentIndex(0); while (stream.hasMore())
{ stream.skipRawMarkup(); if (stream.hasMore()) { WicketTag tag = new
WicketTag(stream.getTag()); if (tag.isEnclosureTag()) { // Try to match the
enclosureTag:s child id to the ids in the target String childId =
tag.getAttribute("child"); if (childId != null) { String[] parts =
childId.split(":"); childId = parts[parts.length - 1]; for (String id : ids)
{ if (id.equals(childId)) { System.err .println("Found enclosure " +
tag.getId() + " at path:" + tag.getPath() + ", who's child is targeted Id="
+ childId); } } } } stream.next(); } } } }
public void onAfterRespond(Map<String, Component> map, IJavascriptResponse
response) { System.err.println("onAfterRespond"); } }); return target; }
//-------------


On Fri, Jan 21, 2011 at 3:58 PM, Martin Makundi <
[email protected]> wrote:

> Hi!
>
> EnclosureResolver....container.autoAdd is invoked at render phase?
> Would it be necessary to hook into a different event (instead of
> onBeforeRender) or could it be pre-sniffed at onBeforeRender?
>
> **
> Martin
>
> 2011/1/21 Joo Hama <[email protected]>:
> > I tested this idea by adding the code below to my web application
> > object. Problem was though,
> > that when viewing the variables in debugger, the enclosure object didn't
> > seem to be included in
> > the tree of the parent objects. It was as if the enclosure was invisible
> to
> > them. Perhaps because
> > Enclosure is a transparent resolver?
> >
> > object tree in my application:
> >
> > - page
> >  - enclosure
> >     - div (the parent of this was shown to be page, not the enclosure)
> >
> >
> > Code:
> > //-----------------------------
> > @Override public AjaxRequestTarget newAjaxRequestTarget(Page page) {
> > AjaxRequestTarget target = super.newAjaxRequestTarget(page);
> > target.addListener(new AjaxRequestTarget.IListener() { public void
> > onBeforeRespond(Map<String, Component> map, AjaxRequestTarget target) {
> > for(Component component : map.values()) { Enclosure parentEnclosure =
> > component.findParent(Enclosure.class); if (parentEnclosure != null) {
> > Enclosure topParent = new Enclosure("DUMMY", "DUMMY"); while (topParent
> !=
> > null) { topParent = parentEnclosure.findParent(Enclosure.class); if
> > (topParent != null) { parentEnclosure = topParent; } }
> > target.addComponent(parentEnclosure); } } } public void
> > onAfterRespond(Map<String, Component> map, IJavascriptResponse response)
> {}
> > }); return target; };
> > //-----------------------
> >
> >
> > On Fri, Jan 21, 2011 at 3:07 AM, Jeremy Thomerson <
> [email protected]
> >> wrote:
> >
> >> On Thu, Jan 20, 2011 at 1:51 PM, Igor Vaynberg <[email protected]
> >> >wrote:
> >>
> >> > interesting idea. i think this would require a bit of a trick.
> >> >
> >> > a) modify enclosure tag handler to accept an attribute instead of a
> tag
> >> > b) modify enclosure tag handler to add a bit of metadata to the
> >> > component marking that it belongs to an enclosure
> >> > c) add a ajaxrequesttarget.listener to the request target that checks
> >> > for this bit of metadata and adds the enclosure container to the ajax
> >> > request target.
> >> >
> >> > not sure how feasible this all is because the enclosure container is
> >> > an auto component. but, you are welcome to tinker around.
> >> >
> >> > -igor
> >>
> >>
> >> I, too, like the idea.  Couldn't it be simpler?  Couldn't he:
> >>
> >> 1: Override newAjaxRequestTarget in WebApplication
> >> 2: When he creates an ART, add a listener to it.
> >> 3: In the listener, in onBeforeRespond, do this:
> >>
> >> for(Component component : map.values()) {
> >>    Enclosure parentEnclosure = component.findParent(Enclosure.class);
> >>    while (parentEnclosure != null) {
> >>        Enclosure topParent =
> parentEnclosure.findParent(Enclosure.class);
> >>        if (topParent != null) {
> >>            parentEnclosure = topParent;
> >>        }
> >>    }
> >>    if (parentEnclosure != null) {
> >>        addComponent(parentEnclosure);
> >>    }
> >> }
> >>
> >>
> >>
> >> --
> >> Jeremy Thomerson
> >> http://wickettraining.com
> >> *Need a CMS for Wicket?  Use Brix! http://brixcms.org*
> >>
> >
>

Reply via email to