You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Bill Holloway <bi...@gmail.com> on 2007/05/23 02:31:31 UTC
T5: PrintWriter weirdness
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(ServletHttpResponse.java:212)
# org.mortbay.jetty.servlet.ServletHttpResponse.sendRedirect(ServletHttpResponse.java:458)
# org.apache.tapestry.internal.services.ResponseImpl.sendRedirect(ResponseImpl.java:63)
# org.apache.tapestry.internal.services.LinkActionResponseGenerator.sendClientResponse(LinkActionResponseGenerator.java:39)
# org.apache.tapestry.internal.services.ComponentActionDispatcher.dispatch(ComponentActionDispatcher.java:122)
Thoughts?
Bill
--
"The future is here. It's just not evenly distributed yet."
-- Traditional
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: T5: PrintWriter weirdness
Posted by Bill Holloway <bi...@gmail.com>.
Yuppers. That's working!
Bill
On 5/23/07, Bill Holloway <bi...@gmail.com> wrote:
> I was getting html tags encoded as entities. I.e., "<p>" would come
> back as "<p>". I hadn't thought of passing the html mime type!
> I'll try it and report back.
>
> Bill
>
> On 5/23/07, Nick Westgate <ni...@key-planning.co.jp> wrote:
> > What are you losing?
> > I'm sending back html fine with:
> >
> > return TextStreamResponse("text/html", html.toString());
> >
> > Cheers,
> > Nick.
> >
> >
> > Bill Holloway wrote:
> > > Well, the value being written out contains markup that I want passed
> > > through with no changes. writer,print() and TextStreamResponse both
> > > encode the markup. writer.writeRaw(value) does it nicely.
> > >
> > > Bill
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> > For additional commands, e-mail: users-help@tapestry.apache.org
> >
> >
>
>
> --
> "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: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: T5: PrintWriter weirdness
Posted by Bill Holloway <bi...@gmail.com>.
I was getting html tags encoded as entities. I.e., "<p>" would come
back as "<p>". I hadn't thought of passing the html mime type!
I'll try it and report back.
Bill
On 5/23/07, Nick Westgate <ni...@key-planning.co.jp> wrote:
> What are you losing?
> I'm sending back html fine with:
>
> return TextStreamResponse("text/html", html.toString());
>
> Cheers,
> Nick.
>
>
> Bill Holloway wrote:
> > Well, the value being written out contains markup that I want passed
> > through with no changes. writer,print() and TextStreamResponse both
> > encode the markup. writer.writeRaw(value) does it nicely.
> >
> > Bill
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>
--
"The future is here. It's just not evenly distributed yet."
-- Traditional
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: T5: PrintWriter weirdness
Posted by Nick Westgate <ni...@key-planning.co.jp>.
What are you losing?
I'm sending back html fine with:
return TextStreamResponse("text/html", html.toString());
Cheers,
Nick.
Bill Holloway wrote:
> Well, the value being written out contains markup that I want passed
> through with no changes. writer,print() and TextStreamResponse both
> encode the markup. writer.writeRaw(value) does it nicely.
>
> Bill
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: T5: PrintWriter weirdness
Posted by Bill Holloway <bi...@gmail.com>.
Well, the value being written out contains markup that I want passed
through with no changes. writer,print() and TextStreamResponse both
encode the markup. writer.writeRaw(value) does it nicely.
Bill
On 5/23/07, Ben Sommerville <be...@bulletproof.com.au> wrote:
> Doh!
> I missed that.
>
> StreamResponse is much better.
> i.e.
> return new TextStreamResponse("text/plain",val);
>
> thanks
> Ben
>
> > -----Original Message-----
> > From: Howard Lewis Ship [mailto:hlship@gmail.com]
> > Sent: Wednesday, 23 May 2007 4:20 PM
> > To: Tapestry users
> > Subject: Re: T5: PrintWriter weirdness
> >
> > You can also return a StreamResponse, which is probably
> > easier to implement
> > that ActionResponseGenerator.
> >
> > On 5/22/07, Ben Sommerville <be...@bulletproof.com.au> 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:bill.holloway@gmail.com]
> > > > 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 <bi...@gmail.com> 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: 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
> > >
> > >
> >
> >
> > --
> > 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
>
>
--
"The future is here. It's just not evenly distributed yet."
-- Traditional
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
RE: T5: PrintWriter weirdness
Posted by Ben Sommerville <be...@bulletproof.com.au>.
Doh!
I missed that.
StreamResponse is much better.
i.e.
return new TextStreamResponse("text/plain",val);
thanks
Ben
> -----Original Message-----
> From: Howard Lewis Ship [mailto:hlship@gmail.com]
> Sent: Wednesday, 23 May 2007 4:20 PM
> To: Tapestry users
> Subject: Re: T5: PrintWriter weirdness
>
> You can also return a StreamResponse, which is probably
> easier to implement
> that ActionResponseGenerator.
>
> On 5/22/07, Ben Sommerville <be...@bulletproof.com.au> 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:bill.holloway@gmail.com]
> > > 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 <bi...@gmail.com> 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: 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
> >
> >
>
>
> --
> 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: PrintWriter weirdness
Posted by Howard Lewis Ship <hl...@gmail.com>.
You can also return a StreamResponse, which is probably easier to implement
that ActionResponseGenerator.
On 5/22/07, Ben Sommerville <be...@bulletproof.com.au> 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:bill.holloway@gmail.com]
> > 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 <bi...@gmail.com> 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: 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
>
>
--
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
RE: T5: PrintWriter weirdness
Posted by Ben Sommerville <be...@bulletproof.com.au>.
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:bill.holloway@gmail.com]
> 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 <bi...@gmail.com> 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: 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: PrintWriter weirdness
Posted by Bill Holloway <bi...@gmail.com>.
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 <bi...@gmail.com> 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(ServletHttpResponse.java:212)
> # org.mortbay.jetty.servlet.ServletHttpResponse.sendRedirect(ServletHttpResponse.java:458)
> # org.apache.tapestry.internal.services.ResponseImpl.sendRedirect(ResponseImpl.java:63)
> # org.apache.tapestry.internal.services.LinkActionResponseGenerator.sendClientResponse(LinkActionResponseGenerator.java:39)
> # org.apache.tapestry.internal.services.ComponentActionDispatcher.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: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org