You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Erik Vullings <er...@gmail.com> on 2007/06/12 16:00:00 UTC

T5: Prototype's AJAX.updater question

Hi all,

Is it possible to use prototype's AJAX updater function to replace a div
with the output of a tapastry page or component?

I''ve tried the following:

I created a js function which should update the mainContent div
*function* showAJAX(index) {
*new* Ajax.Updater("mainContent", "GetContent.html", {
method : "post",
postBody : "index=" + index,
onSuccess : *function*(resp) {
},
onFailure : ajaxError
});
}

Whether GetContent.html is a valid T5 page or a component, in both cases I
get the following error (in the correct mainContent div, so that part works
:-):
 An unexpected application exception has occurred.

   - org.apache.tapestry.ioc.internal.util.TapestryException Component
   org.example.myapp.pages.GetContent does not contain an embedded
   component with id 'html'.

Stack trace

   -
   org.apache.tapestry.internal.structure.ComponentPageElementImpl.getEmbeddedElement
   (ComponentPageElementImpl.java:831)
   -
   org.apache.tapestry.internal.structure.PageImpl.getComponentElementByNestedId
   (PageImpl.java:83)
   - org.apache.tapestry.internal.services.ActionLinkHandlerImpl.handle(
   ActionLinkHandlerImpl.java:69)
   - ...

Any idea what I'm doing wrong?

Thanks
Erik

Re: T5: Prototype's AJAX.updater question

Posted by Howard Lewis Ship <hl...@gmail.com>.
You are formulating the URL incorrectly.

/GetContent.html looks like an "action" event on the "html" component
of page "GetContent".

See:

http://tapestry.apache.org/tapestry5/tapestry-core/guide/pagenav.html

The best way to get a URL is to inject ComponentResources and ask the
component to createPageLink().


On 6/12/07, Erik Vullings <er...@gmail.com> wrote:
> Hi all,
>
> Is it possible to use prototype's AJAX updater function to replace a div
> with the output of a tapastry page or component?
>
> I''ve tried the following:
>
> I created a js function which should update the mainContent div
> *function* showAJAX(index) {
> *new* Ajax.Updater("mainContent", "GetContent.html", {
> method : "post",
> postBody : "index=" + index,
> onSuccess : *function*(resp) {
> },
> onFailure : ajaxError
> });
> }
>
> Whether GetContent.html is a valid T5 page or a component, in both cases I
> get the following error (in the correct mainContent div, so that part works
> :-):
>  An unexpected application exception has occurred.
>
>    - org.apache.tapestry.ioc.internal.util.TapestryException Component
>    org.example.myapp.pages.GetContent does not contain an embedded
>    component with id 'html'.
>
> Stack trace
>
>    -
>    org.apache.tapestry.internal.structure.ComponentPageElementImpl.getEmbeddedElement
>    (ComponentPageElementImpl.java:831)
>    -
>    org.apache.tapestry.internal.structure.PageImpl.getComponentElementByNestedId
>    (PageImpl.java:83)
>    - org.apache.tapestry.internal.services.ActionLinkHandlerImpl.handle(
>    ActionLinkHandlerImpl.java:69)
>    - ...
>
> Any idea what I'm doing wrong?
>
> Thanks
> Erik
>


-- 
Howard M. Lewis Ship
TWD Consulting, Inc.
Independent J2EE / Open-Source Java Consultant
Creator and PMC Chair, Apache Tapestry
Creator, Apache HiveMind

Professional Tapestry training, mentoring, support
and project work.  http://howardlewisship.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5: Prototype's AJAX.updater question

Posted by Erik Vullings <er...@gmail.com>.
Thanks for your replies - removing the html part already did the job,
and there was no need for a more advanced processing. The only
remaining problem so far is that I haven't managed to obtain my
persisted object (it's persisted in the main page), but the component
I get using AJAX doesn't seem to be able to retrieve it. I'll keep on
trying and I'll summarize it in the Wiki once I'm there.

With regard to Howard's last comment: does this mean that we can
expect something like an
<t:ajaxSubmit href="myComponent" div="myDiv" post="true" id="myId"
onsuccess="function..." onerror="function... " errorMessage="RTFM"/>

I already thought of making such a component myself, which would
include the Ajax.Updater javascript above and include a reference to
prototype.js: but I don't know yet how to prevent this javascript and
the prototype ref to be repeated every time I include such an
ajaxSubmit (except by including it separately in the main page). I
probably have to take a look at the Grid component...

BTW do you also plan to AJAX-ify the delegate option, e.g. when you
have a border/layout component, the <t:body/> will be replaced using
AJAX.

On 6/12/07, Howard Lewis Ship <hl...@gmail.com> wrote:
> Most of that logic will move into the framework pretty much invisibly.
>
> On 6/12/07, Kristian Marinkovic <kr...@porsche.co.at> wrote:
> > hi erik,
> >
> > GetContent.html is interpreted by T5 as: go to component "html"
> > on page "GetContent".
> >
> > if you know beforehand what your link looks like (eg. what component
> > and what page) you can use following code snippet to perform partial
> > page rendering:
> >
> >
> > @Component
> > private ActionLink UpdateLink;
> >
> > // to retrieve page instances
> > @Inject private RequestPageCache _cache;
> > // returns markupwriter
> > @Inject private MarkupWriterFactory _mwf;
> > // sets the environment
> > @Inject private PageRenderInitializer initializer;
> >
> > public Object onActionFromUpdateLink {
> >      initializer.setup(markupWriter);
> >     Page page = _cache.get("anypage");
> >
> >     ComponentPageElement element =
> >         page.getRootElement().getEmbeddedElement("anyelement");
> >
> >     RenderQueueImpl queue =
> >         new RenderQueueImpl(page.getLog());
> >
> >     element.queueRender(queue);
> >
> >     queue.run(markupWriter);
> >     markupWriter.end();
> >     initializer.cleanup(markupWriter);
> >
> >     return new TextStreamResponse("text/html",markupWriter.toString());
> > }
> >
> > it works but i don't know if it's the T5 way of doing it :)
> >
> > g,
> > kris
> >
> >
> >
> >
> > "Erik Vullings" <er...@gmail.com>
> > 12.06.2007 16:00
> > Bitte antworten an
> > "Tapestry users" <us...@tapestry.apache.org>
> >
> >
> > An
> > "Tapestry users" <us...@tapestry.apache.org>
> > Kopie
> >
> > Thema
> > T5: Prototype's AJAX.updater question
> >
> >
> >
> >
> >
> >
> > Hi all,
> >
> > Is it possible to use prototype's AJAX updater function to replace a div
> > with the output of a tapastry page or component?
> >
> > I''ve tried the following:
> >
> > I created a js function which should update the mainContent div
> > *function* showAJAX(index) {
> > *new* Ajax.Updater("mainContent", "GetContent.html", {
> > method : "post",
> > postBody : "index=" + index,
> > onSuccess : *function*(resp) {
> > },
> > onFailure : ajaxError
> > });
> > }
> >
> > Whether GetContent.html is a valid T5 page or a component, in both cases I
> > get the following error (in the correct mainContent div, so that part
> > works
> > :-):
> >  An unexpected application exception has occurred.
> >
> >    - org.apache.tapestry.ioc.internal.util.TapestryException Component
> >    org.example.myapp.pages.GetContent does not contain an embedded
> >    component with id 'html'.
> >
> > Stack trace
> >
> >    -
> >
> >
> org.apache.tapestry.internal.structure.ComponentPageElementImpl.getEmbeddedElement
> >    (ComponentPageElementImpl.java:831)
> >    -
> >
> >
> org.apache.tapestry.internal.structure.PageImpl.getComponentElementByNestedId
> >    (PageImpl.java:83)
> >    - org.apache.tapestry.internal.services.ActionLinkHandlerImpl.handle(
> >    ActionLinkHandlerImpl.java:69)
> >    - ...
> >
> > Any idea what I'm doing wrong?
> >
> > Thanks
> > Erik
> >
> >
>
>
> --
> Howard M. Lewis Ship
> TWD Consulting, Inc.
> Independent J2EE / Open-Source Java Consultant
> Creator and PMC Chair, Apache Tapestry
> Creator, Apache HiveMind
>
> Professional Tapestry training, mentoring, support
> and project work.  http://howardlewisship.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5: Prototype's AJAX.updater question

Posted by Howard Lewis Ship <hl...@gmail.com>.
Most of that logic will move into the framework pretty much invisibly.

On 6/12/07, Kristian Marinkovic <kr...@porsche.co.at> wrote:
> hi erik,
>
> GetContent.html is interpreted by T5 as: go to component "html"
> on page "GetContent".
>
> if you know beforehand what your link looks like (eg. what component
> and what page) you can use following code snippet to perform partial
> page rendering:
>
>
> @Component
> private ActionLink UpdateLink;
>
> // to retrieve page instances
> @Inject private RequestPageCache _cache;
> // returns markupwriter
> @Inject private MarkupWriterFactory _mwf;
> // sets the environment
> @Inject private PageRenderInitializer initializer;
>
> public Object onActionFromUpdateLink {
>      initializer.setup(markupWriter);
>     Page page = _cache.get("anypage");
>
>     ComponentPageElement element =
>         page.getRootElement().getEmbeddedElement("anyelement");
>
>     RenderQueueImpl queue =
>         new RenderQueueImpl(page.getLog());
>
>     element.queueRender(queue);
>
>     queue.run(markupWriter);
>     markupWriter.end();
>     initializer.cleanup(markupWriter);
>
>     return new TextStreamResponse("text/html",markupWriter.toString());
> }
>
> it works but i don't know if it's the T5 way of doing it :)
>
> g,
> kris
>
>
>
>
> "Erik Vullings" <er...@gmail.com>
> 12.06.2007 16:00
> Bitte antworten an
> "Tapestry users" <us...@tapestry.apache.org>
>
>
> An
> "Tapestry users" <us...@tapestry.apache.org>
> Kopie
>
> Thema
> T5: Prototype's AJAX.updater question
>
>
>
>
>
>
> Hi all,
>
> Is it possible to use prototype's AJAX updater function to replace a div
> with the output of a tapastry page or component?
>
> I''ve tried the following:
>
> I created a js function which should update the mainContent div
> *function* showAJAX(index) {
> *new* Ajax.Updater("mainContent", "GetContent.html", {
> method : "post",
> postBody : "index=" + index,
> onSuccess : *function*(resp) {
> },
> onFailure : ajaxError
> });
> }
>
> Whether GetContent.html is a valid T5 page or a component, in both cases I
> get the following error (in the correct mainContent div, so that part
> works
> :-):
>  An unexpected application exception has occurred.
>
>    - org.apache.tapestry.ioc.internal.util.TapestryException Component
>    org.example.myapp.pages.GetContent does not contain an embedded
>    component with id 'html'.
>
> Stack trace
>
>    -
>
> org.apache.tapestry.internal.structure.ComponentPageElementImpl.getEmbeddedElement
>    (ComponentPageElementImpl.java:831)
>    -
>
> org.apache.tapestry.internal.structure.PageImpl.getComponentElementByNestedId
>    (PageImpl.java:83)
>    - org.apache.tapestry.internal.services.ActionLinkHandlerImpl.handle(
>    ActionLinkHandlerImpl.java:69)
>    - ...
>
> Any idea what I'm doing wrong?
>
> Thanks
> Erik
>
>


-- 
Howard M. Lewis Ship
TWD Consulting, Inc.
Independent J2EE / Open-Source Java Consultant
Creator and PMC Chair, Apache Tapestry
Creator, Apache HiveMind

Professional Tapestry training, mentoring, support
and project work.  http://howardlewisship.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Antwort: T5: Prototype's AJAX.updater question

Posted by Kristian Marinkovic <kr...@porsche.co.at>.
hi erik,

GetContent.html is interpreted by T5 as: go to component "html" 
on page "GetContent".

if you know beforehand what your link looks like (eg. what component
and what page) you can use following code snippet to perform partial
page rendering:


@Component
private ActionLink UpdateLink;

// to retrieve page instances
@Inject private RequestPageCache _cache;
// returns markupwriter
@Inject private MarkupWriterFactory _mwf;
// sets the environment 
@Inject private PageRenderInitializer initializer;

public Object onActionFromUpdateLink {
     initializer.setup(markupWriter);
    Page page = _cache.get("anypage");
 
    ComponentPageElement element = 
        page.getRootElement().getEmbeddedElement("anyelement");
 
    RenderQueueImpl queue = 
        new RenderQueueImpl(page.getLog());
 
    element.queueRender(queue);

    queue.run(markupWriter); 
    markupWriter.end();
    initializer.cleanup(markupWriter);
 
    return new TextStreamResponse("text/html",markupWriter.toString());
}

it works but i don't know if it's the T5 way of doing it :)

g,
kris




"Erik Vullings" <er...@gmail.com> 
12.06.2007 16:00
Bitte antworten an
"Tapestry users" <us...@tapestry.apache.org>


An
"Tapestry users" <us...@tapestry.apache.org>
Kopie

Thema
T5: Prototype's AJAX.updater question






Hi all,

Is it possible to use prototype's AJAX updater function to replace a div
with the output of a tapastry page or component?

I''ve tried the following:

I created a js function which should update the mainContent div
*function* showAJAX(index) {
*new* Ajax.Updater("mainContent", "GetContent.html", {
method : "post",
postBody : "index=" + index,
onSuccess : *function*(resp) {
},
onFailure : ajaxError
});
}

Whether GetContent.html is a valid T5 page or a component, in both cases I
get the following error (in the correct mainContent div, so that part 
works
:-):
 An unexpected application exception has occurred.

   - org.apache.tapestry.ioc.internal.util.TapestryException Component
   org.example.myapp.pages.GetContent does not contain an embedded
   component with id 'html'.

Stack trace

   -
 
org.apache.tapestry.internal.structure.ComponentPageElementImpl.getEmbeddedElement
   (ComponentPageElementImpl.java:831)
   -
 
org.apache.tapestry.internal.structure.PageImpl.getComponentElementByNestedId
   (PageImpl.java:83)
   - org.apache.tapestry.internal.services.ActionLinkHandlerImpl.handle(
   ActionLinkHandlerImpl.java:69)
   - ...

Any idea what I'm doing wrong?

Thanks
Erik