You can also return a StreamResponse, which is probably easier to implement
that ActionResponseGenerator.

On 5/22/07, Ben Sommerville <[EMAIL PROTECTED]> wrote:

Bill,

When you return void from an actionLink method the default response
of tapestry is to render the page.

To just return the editor value you need to return an
ActionResponseGenerator
that outputs your desired response.

e.g.

    ActionResponseGenerator onInPlaceEditorSubmit() throws IOException {
        final String val = _request.getParameter("value");
        System.out.println("text is:" + val);
        return new ActionResponseGenerator() {
            public void sendClientResponse(Response response) throws
IOException {
                // Note we are using Response parameter, not the injected
response
                PrintWriter writer =
response.getPrintWriter("text/plain");
                writer.print(val);
            }
        };
    }

Now when you submit your changed value the web page will be updated.

May I highly recommend Firebug to help with this sort of thing, being able
to see the requests & responses makes debugging much easier.



Also, if you are not actually submitting a form you don't need the form
element in your page.
You can change your template to

<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd";>
<body>
    <p id="editme2">Click me to edit this nice long text.</p>

    <script type="text/javascript">
        new Ajax.InPlaceEditor('editme2', '${actionURL}',
{rows:15,cols:40});
    </script>

</body>
</html>

and add the following to the page class to include the required javascript

    @Inject
    private PageRenderSupport pageRender;
    @Inject
    @Path("${tapestry.scriptaculous}/prototype.js")
    private Asset prototype;
    @Inject
    @Path("${tapestry.scriptaculous}/scriptaculous.js")
    private Asset scriptaculous;

    public void beginRender() {
        pageRender.addScriptLink(prototype, scriptaculous);
    }

cheers
Ben

> -----Original Message-----
> From: Bill Holloway [mailto:[EMAIL PROTECTED]
> Sent: Wednesday, 23 May 2007 10:38 AM
> To: Tapestry users
> Subject: Re: T5: PrintWriter weirdness
>
> Actually, the exception goes away on the client side only (No stack
> trace dumped to the web page) if I use writer.close().  writer.flush()
> dumps the trace to both the console and the web page.
>
> Bill
>
> On 5/22/07, Bill Holloway <[EMAIL PROTECTED]> wrote:
> > I'm using an in-place-editor under script.aculo.us to edit some text
> > printed to the browser.  In my page class I have
> >
> > public String getActionURL ()
> >         {
> >                 Link inPlaceLink = _resources.createActionLink
> > ("inPlaceEditorSubmit", false, (Object[]) null);
> >                 return inPlaceLink.toURI();
> >         }
> >
> >         void onInPlaceEditorSubmit () throws IOException
> >         {
> >                 String val = _request.getParameter ("value");
> >                 System.out.println ("text is:" + val);
> >                 PrintWriter writer =
> _response.getPrintWriter ("text/plain");
> >                 writer.print (val);
> >                 writer.flush();
> >         }
> >
> > My page template is
> >
> > <html
> xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd";>
> > <body>
> >
> >
> > <form t:type="form" t:id="inPlaceForm">
> >
> >         <p id="editme2">Click me to edit this nice long text.</p>
> >
> >         <script type="text/javascript">
> >                 new Ajax.InPlaceEditor('editme2',
> '${actionURL}', {rows:15,cols:40});
> >         </script>
> >
> > </form>
> >
> > </body>
> > </html>
> >
> > This all works just fine except that there is an
> > "IllegalStateException" thrown when I submit the changed field.  It
> > complains about that the printwriter (I guess) is "Committed".  A
> > partial stack trace starting at the top is shown below.  I
> notice that
> > if I omit the call to writer.flush(), there is no exception, but the
> > text on the web page does not reflect the changed value --
> it reverts
> > to the initial value before the change -- doubtlessly
> because without
> > the flush, the stream never gets back to the client-side response
> > handler.
> >
> > #
> org.mortbay.jetty.servlet.ServletHttpResponse.resetBuffer(Serv
> letHttpResponse.java:212)
> > #
> org.mortbay.jetty.servlet.ServletHttpResponse.sendRedirect(Ser
> vletHttpResponse.java:458)
> > #
> org.apache.tapestry.internal.services.ResponseImpl.sendRedirec
> t(ResponseImpl.java:63)
> > #
> org.apache.tapestry.internal.services.LinkActionResponseGenera
> tor.sendClientResponse(LinkActionResponseGenerator.java:39)
> > #
> org.apache.tapestry.internal.services.ComponentActionDispatche
> r.dispatch(ComponentActionDispatcher.java:122)
> >
> > Thoughts?
> >
> > Bill
> > --
> > "The future is here.  It's just not evenly distributed yet."
> >
> >      -- Traditional
> >
>
>
> --
> "The future is here.  It's just not evenly distributed yet."
>
>      -- Traditional
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




--
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

Reply via email to