You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Martin Dietze <di...@fh-wedel.de> on 2013/11/13 14:04:39 UTC
Rendering a component into a String
In a legacy project I've inherited I've got a piece of code that
no longer works since the project was upgraded from Wicket 1.4 to
Wicket 6.
It's about rendering a component (a Wicket panel) into a string
in order to return it wrapped into a webservice reply.
The webservice is based on Wicket, too. The webservice is based
on a Javascript handshake - the client calls the service using a
token connecting the user to his current session he has on the
application, the service replies are rendered into an iframe and
deliver their data through postMessage.
Thus, when rendering a reply, I am basically rendering a Wicket
page within the context of my session.
Now one of my API's calls requires me to render a Wicket panel
into a String, which is then wrapped into JSON as part of the
respective call's reply.
The legacy code used to do this roughly like this (changes for
using the Wicket 6 API were applied, but this nevertheless never
worked):
- create a mock RequestCycle by creating a MockHttpSession, a
MockHttpServletRequest and a MockHttpServletResponse, glue
this all together to obtain a ServletWebRequest and a
BufferedWebResponse and finaly use use Application.createRequestCycle()
to create the RequestCycle object
- the component wrapped into a ComponentRenderingRequestHandler
- then this code is executed:
| try {
| requestCycle.scheduleRequestHandlerAfterCurrent(requestHandler);
| try {
| if ( !requestCycle.processRequestAndDetach() ) {
| requestCycle.scheduleRequestHandlerAfterCurrent(new ErrorCodeRequestHandler((HttpServletResponse.SC_NOT_FOUND));
| }
| } finally {
| requestCycle.getResponse().close();
| }
| return requestCycle.getResponse().toString();
| } finally {
| requestCycle.detach();
| }
I must admit I could not have written this myself :)
Now when running this code, I run into two different
exceptions:
org.apache.wicket.WicketRuntimeException: Exception in rendering component: [Profile [Component id = profile]]
at org.apache.wicket.Component.internalRenderComponent(Component.java:2576) [wicket-core-6.9.1.jar:6.9.1]
at org.apache.wicket.MarkupContainer.onRender(MarkupContainer.java:1493) ~[wicket-core-6.9.1.jar:6.9.1]
at org.apache.wicket.Component.internalRender(Component.java:2379) [wicket-core-6.9.1.jar:6.9.1]
at org.apache.wicket.Component.render(Component.java:2307) [wicket-core-6.9.1.jar:6.9.1]
[...]
Caused by: java.lang.NullPointerException: null
at org.apache.wicket.markup.html.internal.Enclosure.isVisible(Enclosure.java:143) ~[wicket-core-6.9.1.jar:6.9.1]
at org.apache.wicket.Component.determineVisibility(Component.java:4363) [wicket-core-6.9.1.jar:6.9.1]
at org.apache.wicket.Component.internalBeforeRender(Component.java:916) [wicket-core-6.9.1.jar:6.9.1]
at org.apache.wicket.Component.beforeRender(Component.java:991) [wicket-core-6.9.1.jar:6.9.1]
at org.apache.wicket.Component.internalPrepareForRender(Component.java:2214) [wicket-core-6.9.1.jar:6.9.1]
at org.apache.wicket.Component.render(Component.java:2303) [wicket-core-6.9.1.jar:6.9.1]
at org.apache.wicket.MarkupContainer.renderNext(MarkupContainer.java:1390) ~[wicket-core-6.9.1.jar:6.9.1]
at org.apache.wicket.MarkupContainer.renderAll(MarkupContainer.java:1554) ~[wicket-core-6.9.1.jar:6.9.1]
at org.apache.wicket.MarkupContainer.renderComponentTagBody(MarkupContainer.java:1529) ~[wicket-core-6.9.1.jar:6.9.1]
at org.apache.wicket.MarkupContainer.onComponentTagBody(MarkupContainer.java:1484) ~[wicket-core-6.9.1.jar:6.9.1]
at org.apache.wicket.markup.html.panel.DefaultMarkupSourcingStrategy.onComponentTagBody(DefaultMarkupSourcingStrategy.java:71) ~[wicket-core-6.9.1.jar:6.9.1]
at org.apache.wicket.Component.internalRenderComponent(Component.java:2549) [wicket-core-6.9.1.jar:6.9.1]
The enclosure's child component is null, as we see here:
| @Override
| public boolean isVisible()
| {
| return childComponent.determineVisibility() && super.isVisible();
| }
Below that exception I find the markup of a stack trace page in my logs.
Below that markup I get another stack trace:
java.lang.NullPointerException: null
at org.apache.wicket.Component.internalPrepareForRender(Component.java:2224) ~[wicket-core-6.9.1.jar:6.9.1]
at org.apache.wicket.Page.internalPrepareForRender(Page.java:241) ~[wicket-core-6.9.1.jar:6.9.1]
at org.apache.wicket.Component.render(Component.java:2303) ~[wicket-core-6.9.1.jar:6.9.1]
at org.apache.wicket.Page.renderPage(Page.java:1010) ~[wicket-core-6.9.1.jar:6.9.1]
at org.apache.wicket.request.handler.render.WebPageRenderer.renderPage(WebPageRenderer.java:121) ~[wicket-core-6.9.1.jar:6.9.1]
at org.apache.wicket.request.handler.render.WebPageRenderer.respond(WebPageRenderer.java:271) ~[wicket-core-6.9.1.jar:6.9.1]
at org.apache.wicket.core.request.handler.RenderPageRequestHandler.respond(RenderPageRequestHandler.java:165) ~[wicket-core-6.9.1.jar:6.9.1]
at org.apache.wicket.request.cycle.RequestCycle$HandlerExecutor.respond(RequestCycle.java:861) ~[wicket-core-6.9.1.jar:6.9.1]
at org.apache.wicket.request.RequestHandlerStack.execute(RequestHandlerStack.java:64) ~[wicket-request-6.9.1.jar:6.9.1]
at org.apache.wicket.request.cycle.RequestCycle.execute(RequestCycle.java:261) [wicket-core-6.9.1.jar:6.9.1]
at org.apache.wicket.request.cycle.RequestCycle.processRequest(RequestCycle.java:218) [wicket-core-6.9.1.jar:6.9.1]
at org.apache.wicket.request.cycle.RequestCycle.processRequestAndDetach(RequestCycle.java:289) [wicket-core-6.9.1.jar:6.9.1]
at org.apache.wicket.protocol.http.WicketFilter.processRequestCycle(WicketFilter.java:259) [wicket-core-6.9.1.jar:6.9.1]
at org.apache.wicket.protocol.http.WicketFilter.processRequest(WicketFilter.java:201) [wicket-core-6.9.1.jar:6.9.1]
at org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:282) [wicket-core-6.9.1.jar:6.9.1]
Here the RequestCycle is null:
| if (setRenderingFlag)
| {
| // only process feedback panel when we are about to be rendered.
| // setRenderingFlag is false in case prepareForRender is called only to build component
| // hierarchy (i.e. in BookmarkableListenerInterfaceRequestTarget).
| // prepareForRender(true) is always called before the actual rendering is done so
| // that's where feedback panels gather the messages
|
| List<Component> feedbacks = getRequestCycle().getMetaData(FEEDBACK_LIST);
To me it seems like I've got two different problems here:
- the component cannot be rendered because I'm doing something
fundamentally wrong, thus I'm not getting the expected output
- after the mock-RequestCycle's done with its work, there's no
RequestCycle set anymore, thus I cannot render the reply
I understand that my problem may be rather specific. And since
this is webservice that is already in use, I cannot just rewrite
it completely. Thus I would greatly appreciate any hint how i could
accomplish what the old code used to do before the Wicket upgrade?
Cheers,
M'bert
--
----------- / http://herbert.the-little-red-haired-girl.org / -------------
=+=
Pilot: Call me a fuel truck.
Tower: You're a fuel truck.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Rendering a component into a String
Posted by Martin Grigorov <mg...@apache.org>.
I think the fix for 6.13 will be something similar.
The page should report that it is stateless no matter what
components/behaviors it renders.
On Thu, Nov 21, 2013 at 1:33 PM, Mateusz Mieszkowski <
mmieszkowski@objectivity.co.uk> wrote:
> Just a quick update for those with the same problem:
> Option 1 did not work as the page is not bookmarkable.
> I used option 2 and override isBookmarkable() method in RenderPage to
> return true. Page is set to stateless on its own.
>
> It's not too clean but in my case should be enough. Martin, please let me
> know if you see any danger in such solution.
>
> Mateusz
>
>
> -----Original Message-----
> From: Martin Grigorov [mailto:mgrigorov@apache.org]
> Sent: Thursday, November 21, 2013 10:56 AM
> To: users@wicket.apache.org
> Subject: Re: Rendering a component into a String
>
> Option 1) Override your component's onInitialize/onConfigure and call
> page.setStatelessHint(true)
> Option 2) Copy/paste ComponentRenderer.java locally and do something
> similar directly in RenderPage
>
>
> On Thu, Nov 21, 2013 at 11:29 AM, Mateusz Mieszkowski <
> mmieszkowski@objectivity.co.uk> wrote:
>
> > Martin,
> >
> > Ticket created: https://issues.apache.org/jira/browse/WICKET-5422
> > Can you advise a workaround for now?
> >
> > Cheers,
> > Mateusz
> >
> >
> > -----Original Message-----
> > From: Martin Grigorov [mailto:mgrigorov@apache.org]
> > Sent: Thursday, November 21, 2013 9:49 AM
> > To: users@wicket.apache.org
> > Cc: Martin Dietze
> > Subject: Re: Rendering a component into a String
> >
> > Please create a ticket.
> > The page should be marked as stateless to avoid storing it.
> >
> >
> > On Thu, Nov 21, 2013 at 10:40 AM, Mateusz Mieszkowski <
> > mmieszkowski@objectivity.co.uk> wrote:
> >
> > > Hi guys,
> > >
> > > I noticed a problem with ComponentRenderer.renderComponent(). It is
> > > possible that I'm missing something but this is what I get for now:
> > > I'm using ComponenetRenderer withing CustomTooltipBehavior
> > > (wicket-jquery-ui) to generate tooltip content. I add this to about
> > > 50 rows in my table so I run renderComponent() method as many times.
> > > All worked fine but there was a problem with performance when I used
> > > Fragment component with markup attached to the WebPage. I did some
> > > digging and finally checked
> > > http://localhost:8080/context/wicket/internal/debug/diskDataStore
> > > and it appeared that for one request, Wicket stores 51 pages in it.
> > > All of the size of the whole page (about 300kB) and all of them
> > > named org.apache.wicket.core.util.string.ComponentRenderer$RenderPage.
> > >
> > > I changed implementation from Fragment to Panel componenet and the
> > > size was reduced to (1kB) but still all of these items were stored
> > > in the DataStore.
> > >
> > > It seems that this method is creating a dummy page in order to
> > > create the markup, but how can I avoid storing these pages?
> > >
> > > Best regards,
> > > Mateusz
> > >
> > > -----Original Message-----
> > > From: Martin Grigorov [mailto:mgrigorov@apache.org]
> > > Sent: Wednesday, November 13, 2013 2:09 PM
> > > To: users@wicket.apache.org; Martin Dietze
> > > Subject: Re: Rendering a component into a String
> > >
> > > Hi,
> > >
> > > See the source of
> > > http://www.wicket-library.com/wicket-examples-6.0.x/mailtemplate/?2e
> > > xa
> > > mple
> > >
> > >
> > > On Wed, Nov 13, 2013 at 3:04 PM, Martin Dietze <di...@fh-wedel.de> wrote:
> > >
> > > > In a legacy project I've inherited I've got a piece of code that
> > > > no longer works since the project was upgraded from Wicket 1.4 to
> > > > Wicket 6.
> > > >
> > > > It's about rendering a component (a Wicket panel) into a string in
> > > > order to return it wrapped into a webservice reply.
> > > >
> > > > The webservice is based on Wicket, too. The webservice is based on
> > > > a Javascript handshake - the client calls the service using a
> > > > token connecting the user to his current session he has on the
> > > > application, the service replies are rendered into an iframe and
> > > > deliver their data through postMessage.
> > > >
> > > > Thus, when rendering a reply, I am basically rendering a Wicket
> > > > page within the context of my session.
> > > >
> > > > Now one of my API's calls requires me to render a Wicket panel
> > > > into a String, which is then wrapped into JSON as part of the
> > > > respective call's reply.
> > > >
> > > > The legacy code used to do this roughly like this (changes for
> > > > using the Wicket 6 API were applied, but this nevertheless never
> > > > worked):
> > > >
> > > > - create a mock RequestCycle by creating a MockHttpSession, a
> > > > MockHttpServletRequest and a MockHttpServletResponse, glue
> > > > this all together to obtain a ServletWebRequest and a
> > > > BufferedWebResponse and finaly use use
> > Application.createRequestCycle()
> > > > to create the RequestCycle object
> > > >
> > > > - the component wrapped into a ComponentRenderingRequestHandler
> > > >
> > > > - then this code is executed:
> > > >
> > > > | try {
> > > > |
> > requestCycle.scheduleRequestHandlerAfterCurrent(requestHandler);
> > > > | try {
> > > > | if ( !requestCycle.processRequestAndDetach() ) {
> > > > |
> > > > | requestCycle.scheduleRequestHandlerAfterCurrent(new
> > > > ErrorCodeRequestHandler((HttpServletResponse.SC_NOT_FOUND));
> > > > | }
> > > > | } finally {
> > > > | requestCycle.getResponse().close();
> > > > | }
> > > > | return requestCycle.getResponse().toString();
> > > > | } finally {
> > > > | requestCycle.detach();
> > > > | }
> > > >
> > > > I must admit I could not have written this myself :)
> > > >
> > > > Now when running this code, I run into two different
> > > > exceptions:
> > > >
> > > > org.apache.wicket.WicketRuntimeException: Exception in rendering
> > > > component: [Profile [Component id = profile]]
> > > > at
> > > > org.apache.wicket.Component.internalRenderComponent(Component.java
> > > > :2
> > > > 57
> > > > 6)
> > > > [wicket-core-6.9.1.jar:6.9.1]
> > > > at
> > > > org.apache.wicket.MarkupContainer.onRender(MarkupContainer.java:14
> > > > 93
> > > > )
> > > > ~[wicket-core-6.9.1.jar:6.9.1]
> > > > at
> > > > org.apache.wicket.Component.internalRender(Component.java:2379)
> > > > [wicket-core-6.9.1.jar:6.9.1]
> > > > at org.apache.wicket.Component.render(Component.java:2307)
> > > > [wicket-core-6.9.1.jar:6.9.1]
> > > > [...]
> > > > Caused by: java.lang.NullPointerException: null
> > > > at
> > > > org.apache.wicket.markup.html.internal.Enclosure.isVisible(Enclosu
> > > > re
> > > > .j
> > > > ava:143)
> > > > ~[wicket-core-6.9.1.jar:6.9.1]
> > > > at
> > > > org.apache.wicket.Component.determineVisibility(Component.java:436
> > > > 3)
> > > > [wicket-core-6.9.1.jar:6.9.1]
> > > > at
> > > > org.apache.wicket.Component.internalBeforeRender(Component.java:91
> > > > 6)
> > > > [wicket-core-6.9.1.jar:6.9.1]
> > > > at
> > > > org.apache.wicket.Component.beforeRender(Component.java:991)
> > > > [wicket-core-6.9.1.jar:6.9.1]
> > > > at
> > > > org.apache.wicket.Component.internalPrepareForRender(Component.java:
> > > > 22
> > > > 14)
> > > > [wicket-core-6.9.1.jar:6.9.1]
> > > > at org.apache.wicket.Component.render(Component.java:2303)
> > > > [wicket-core-6.9.1.jar:6.9.1]
> > > > at
> > > > org.apache.wicket.MarkupContainer.renderNext(MarkupContainer.java:
> > > > 13
> > > > 90
> > > > )
> > > > ~[wicket-core-6.9.1.jar:6.9.1]
> > > > at
> > > > org.apache.wicket.MarkupContainer.renderAll(MarkupContainer.java:1
> > > > 55
> > > > 4)
> > > > ~[wicket-core-6.9.1.jar:6.9.1]
> > > > at
> > > > org.apache.wicket.MarkupContainer.renderComponentTagBody(MarkupCon
> > > > ta
> > > > in
> > > > er.java:1529)
> > > > ~[wicket-core-6.9.1.jar:6.9.1]
> > > > at
> > > > org.apache.wicket.MarkupContainer.onComponentTagBody(MarkupContain
> > > > er
> > > > .j
> > > > ava:1484)
> > > > ~[wicket-core-6.9.1.jar:6.9.1]
> > > > at
> > > > org.apache.wicket.markup.html.panel.DefaultMarkupSourcingStrategy.
> > > > on
> > > > Co
> > > > mponentTagBody(DefaultMarkupSourcingStrategy.java:71)
> > > > ~[wicket-core-6.9.1.jar:6.9.1]
> > > > at
> > > > org.apache.wicket.Component.internalRenderComponent(Component.java
> > > > :2
> > > > 54
> > > > 9)
> > > > [wicket-core-6.9.1.jar:6.9.1]
> > > >
> > > > The enclosure's child component is null, as we see here:
> > > > | @Override
> > > > | public boolean isVisible()
> > > > | {
> > > > | return childComponent.determineVisibility() &&
> > > > super.isVisible();
> > > > | }
> > > >
> > > > Below that exception I find the markup of a stack trace page in my
> > logs.
> > > > Below that markup I get another stack trace:
> > > >
> > > > java.lang.NullPointerException: null
> > > > at
> > > > org.apache.wicket.Component.internalPrepareForRender(Component.java:
> > > > 22
> > > > 24)
> > > > ~[wicket-core-6.9.1.jar:6.9.1]
> > > > at
> > > > org.apache.wicket.Page.internalPrepareForRender(Page.java:241)
> > > > ~[wicket-core-6.9.1.jar:6.9.1]
> > > > at org.apache.wicket.Component.render(Component.java:2303)
> > > > ~[wicket-core-6.9.1.jar:6.9.1]
> > > > at org.apache.wicket.Page.renderPage(Page.java:1010)
> > > > ~[wicket-core-6.9.1.jar:6.9.1]
> > > > at
> > > > org.apache.wicket.request.handler.render.WebPageRenderer.renderPag
> > > > e(
> > > > We
> > > > bPageRenderer.java:121)
> > > > ~[wicket-core-6.9.1.jar:6.9.1]
> > > > at
> > > > org.apache.wicket.request.handler.render.WebPageRenderer.respond(W
> > > > eb
> > > > Pa
> > > > geRenderer.java:271)
> > > > ~[wicket-core-6.9.1.jar:6.9.1]
> > > > at
> > > > org.apache.wicket.core.request.handler.RenderPageRequestHandler.re
> > > > sp
> > > > on
> > > > d(RenderPageRequestHandler.java:165)
> > > > ~[wicket-core-6.9.1.jar:6.9.1]
> > > > at
> > > > org.apache.wicket.request.cycle.RequestCycle$HandlerExecutor.respo
> > > > nd
> > > > (R
> > > > equestCycle.java:861)
> > > > ~[wicket-core-6.9.1.jar:6.9.1]
> > > > at
> > > > org.apache.wicket.request.RequestHandlerStack.execute(RequestHandl
> > > > er
> > > > St
> > > > ack.java:64)
> > > > ~[wicket-request-6.9.1.jar:6.9.1]
> > > > at
> > > > org.apache.wicket.request.cycle.RequestCycle.execute(RequestCycle.
> > > > ja
> > > > va
> > > > :261)
> > > > [wicket-core-6.9.1.jar:6.9.1]
> > > > at
> > > > org.apache.wicket.request.cycle.RequestCycle.processRequest(Reques
> > > > tC
> > > > yc
> > > > le.java:218)
> > > > [wicket-core-6.9.1.jar:6.9.1]
> > > > at
> > > > org.apache.wicket.request.cycle.RequestCycle.processRequestAndDeta
> > > > ch
> > > > (R
> > > > equestCycle.java:289)
> > > > [wicket-core-6.9.1.jar:6.9.1]
> > > > at
> > > > org.apache.wicket.protocol.http.WicketFilter.processRequestCycle(W
> > > > ic
> > > > ke
> > > > tFilter.java:259)
> > > > [wicket-core-6.9.1.jar:6.9.1]
> > > > at
> > > > org.apache.wicket.protocol.http.WicketFilter.processRequest(Wicket
> > > > Fi
> > > > lt
> > > > er.java:201)
> > > > [wicket-core-6.9.1.jar:6.9.1]
> > > > at
> > > > org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter
> > > > .j
> > > > av
> > > > a:282)
> > > > [wicket-core-6.9.1.jar:6.9.1]
> > > >
> > > > Here the RequestCycle is null:
> > > > | if (setRenderingFlag)
> > > > | {
> > > > | // only process feedback panel when we are about
> > > > | to be
> > > > rendered.
> > > > | // setRenderingFlag is false in case
> > > > | prepareForRender is
> > > > called only to build component
> > > > | // hierarchy (i.e. in
> > > > BookmarkableListenerInterfaceRequestTarget).
> > > > | // prepareForRender(true) is always called before
> > > > | the
> > > > actual rendering is done so
> > > > | // that's where feedback panels gather the
> > > > | messages
> > > > |
> > > > | List<Component> feedbacks =
> > > > getRequestCycle().getMetaData(FEEDBACK_LIST);
> > > >
> > > > To me it seems like I've got two different problems here:
> > > >
> > > > - the component cannot be rendered because I'm doing something
> > > > fundamentally wrong, thus I'm not getting the expected output
> > > >
> > > > - after the mock-RequestCycle's done with its work, there's no
> > > > RequestCycle set anymore, thus I cannot render the reply
> > > >
> > > >
> > > > I understand that my problem may be rather specific. And since
> > > > this is webservice that is already in use, I cannot just rewrite
> > > > it completely. Thus I would greatly appreciate any hint how i
> > > > could accomplish what the old code used to do before the Wicket
> upgrade?
> > > >
> > > > Cheers,
> > > >
> > > > M'bert
> > > >
> > > > --
> > > > ----------- / http://herbert.the-little-red-haired-girl.org /
> > > > -------------
> > > > =+=
> > > > Pilot: Call me a fuel truck.
> > > > Tower: You're a fuel truck.
> > > >
> > > > ------------------------------------------------------------------
> > > > --
> > > > - To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> > > > For additional commands, e-mail: users-help@wicket.apache.org
> > > >
> > > >
> > >
> > > --------------------------------------------------------------------
> > > - To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> > > For additional commands, e-mail: users-help@wicket.apache.org
> > >
> > >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
RE: Rendering a component into a String
Posted by Mateusz Mieszkowski <mm...@objectivity.co.uk>.
Just a quick update for those with the same problem:
Option 1 did not work as the page is not bookmarkable.
I used option 2 and override isBookmarkable() method in RenderPage to return true. Page is set to stateless on its own.
It's not too clean but in my case should be enough. Martin, please let me know if you see any danger in such solution.
Mateusz
-----Original Message-----
From: Martin Grigorov [mailto:mgrigorov@apache.org]
Sent: Thursday, November 21, 2013 10:56 AM
To: users@wicket.apache.org
Subject: Re: Rendering a component into a String
Option 1) Override your component's onInitialize/onConfigure and call
page.setStatelessHint(true)
Option 2) Copy/paste ComponentRenderer.java locally and do something similar directly in RenderPage
On Thu, Nov 21, 2013 at 11:29 AM, Mateusz Mieszkowski < mmieszkowski@objectivity.co.uk> wrote:
> Martin,
>
> Ticket created: https://issues.apache.org/jira/browse/WICKET-5422
> Can you advise a workaround for now?
>
> Cheers,
> Mateusz
>
>
> -----Original Message-----
> From: Martin Grigorov [mailto:mgrigorov@apache.org]
> Sent: Thursday, November 21, 2013 9:49 AM
> To: users@wicket.apache.org
> Cc: Martin Dietze
> Subject: Re: Rendering a component into a String
>
> Please create a ticket.
> The page should be marked as stateless to avoid storing it.
>
>
> On Thu, Nov 21, 2013 at 10:40 AM, Mateusz Mieszkowski <
> mmieszkowski@objectivity.co.uk> wrote:
>
> > Hi guys,
> >
> > I noticed a problem with ComponentRenderer.renderComponent(). It is
> > possible that I'm missing something but this is what I get for now:
> > I'm using ComponenetRenderer withing CustomTooltipBehavior
> > (wicket-jquery-ui) to generate tooltip content. I add this to about
> > 50 rows in my table so I run renderComponent() method as many times.
> > All worked fine but there was a problem with performance when I used
> > Fragment component with markup attached to the WebPage. I did some
> > digging and finally checked
> > http://localhost:8080/context/wicket/internal/debug/diskDataStore
> > and it appeared that for one request, Wicket stores 51 pages in it.
> > All of the size of the whole page (about 300kB) and all of them
> > named org.apache.wicket.core.util.string.ComponentRenderer$RenderPage.
> >
> > I changed implementation from Fragment to Panel componenet and the
> > size was reduced to (1kB) but still all of these items were stored
> > in the DataStore.
> >
> > It seems that this method is creating a dummy page in order to
> > create the markup, but how can I avoid storing these pages?
> >
> > Best regards,
> > Mateusz
> >
> > -----Original Message-----
> > From: Martin Grigorov [mailto:mgrigorov@apache.org]
> > Sent: Wednesday, November 13, 2013 2:09 PM
> > To: users@wicket.apache.org; Martin Dietze
> > Subject: Re: Rendering a component into a String
> >
> > Hi,
> >
> > See the source of
> > http://www.wicket-library.com/wicket-examples-6.0.x/mailtemplate/?2e
> > xa
> > mple
> >
> >
> > On Wed, Nov 13, 2013 at 3:04 PM, Martin Dietze <di...@fh-wedel.de> wrote:
> >
> > > In a legacy project I've inherited I've got a piece of code that
> > > no longer works since the project was upgraded from Wicket 1.4 to
> > > Wicket 6.
> > >
> > > It's about rendering a component (a Wicket panel) into a string in
> > > order to return it wrapped into a webservice reply.
> > >
> > > The webservice is based on Wicket, too. The webservice is based on
> > > a Javascript handshake - the client calls the service using a
> > > token connecting the user to his current session he has on the
> > > application, the service replies are rendered into an iframe and
> > > deliver their data through postMessage.
> > >
> > > Thus, when rendering a reply, I am basically rendering a Wicket
> > > page within the context of my session.
> > >
> > > Now one of my API's calls requires me to render a Wicket panel
> > > into a String, which is then wrapped into JSON as part of the
> > > respective call's reply.
> > >
> > > The legacy code used to do this roughly like this (changes for
> > > using the Wicket 6 API were applied, but this nevertheless never
> > > worked):
> > >
> > > - create a mock RequestCycle by creating a MockHttpSession, a
> > > MockHttpServletRequest and a MockHttpServletResponse, glue
> > > this all together to obtain a ServletWebRequest and a
> > > BufferedWebResponse and finaly use use
> Application.createRequestCycle()
> > > to create the RequestCycle object
> > >
> > > - the component wrapped into a ComponentRenderingRequestHandler
> > >
> > > - then this code is executed:
> > >
> > > | try {
> > > |
> requestCycle.scheduleRequestHandlerAfterCurrent(requestHandler);
> > > | try {
> > > | if ( !requestCycle.processRequestAndDetach() ) {
> > > |
> > > | requestCycle.scheduleRequestHandlerAfterCurrent(new
> > > ErrorCodeRequestHandler((HttpServletResponse.SC_NOT_FOUND));
> > > | }
> > > | } finally {
> > > | requestCycle.getResponse().close();
> > > | }
> > > | return requestCycle.getResponse().toString();
> > > | } finally {
> > > | requestCycle.detach();
> > > | }
> > >
> > > I must admit I could not have written this myself :)
> > >
> > > Now when running this code, I run into two different
> > > exceptions:
> > >
> > > org.apache.wicket.WicketRuntimeException: Exception in rendering
> > > component: [Profile [Component id = profile]]
> > > at
> > > org.apache.wicket.Component.internalRenderComponent(Component.java
> > > :2
> > > 57
> > > 6)
> > > [wicket-core-6.9.1.jar:6.9.1]
> > > at
> > > org.apache.wicket.MarkupContainer.onRender(MarkupContainer.java:14
> > > 93
> > > )
> > > ~[wicket-core-6.9.1.jar:6.9.1]
> > > at
> > > org.apache.wicket.Component.internalRender(Component.java:2379)
> > > [wicket-core-6.9.1.jar:6.9.1]
> > > at org.apache.wicket.Component.render(Component.java:2307)
> > > [wicket-core-6.9.1.jar:6.9.1]
> > > [...]
> > > Caused by: java.lang.NullPointerException: null
> > > at
> > > org.apache.wicket.markup.html.internal.Enclosure.isVisible(Enclosu
> > > re
> > > .j
> > > ava:143)
> > > ~[wicket-core-6.9.1.jar:6.9.1]
> > > at
> > > org.apache.wicket.Component.determineVisibility(Component.java:436
> > > 3)
> > > [wicket-core-6.9.1.jar:6.9.1]
> > > at
> > > org.apache.wicket.Component.internalBeforeRender(Component.java:91
> > > 6)
> > > [wicket-core-6.9.1.jar:6.9.1]
> > > at
> > > org.apache.wicket.Component.beforeRender(Component.java:991)
> > > [wicket-core-6.9.1.jar:6.9.1]
> > > at
> > > org.apache.wicket.Component.internalPrepareForRender(Component.java:
> > > 22
> > > 14)
> > > [wicket-core-6.9.1.jar:6.9.1]
> > > at org.apache.wicket.Component.render(Component.java:2303)
> > > [wicket-core-6.9.1.jar:6.9.1]
> > > at
> > > org.apache.wicket.MarkupContainer.renderNext(MarkupContainer.java:
> > > 13
> > > 90
> > > )
> > > ~[wicket-core-6.9.1.jar:6.9.1]
> > > at
> > > org.apache.wicket.MarkupContainer.renderAll(MarkupContainer.java:1
> > > 55
> > > 4)
> > > ~[wicket-core-6.9.1.jar:6.9.1]
> > > at
> > > org.apache.wicket.MarkupContainer.renderComponentTagBody(MarkupCon
> > > ta
> > > in
> > > er.java:1529)
> > > ~[wicket-core-6.9.1.jar:6.9.1]
> > > at
> > > org.apache.wicket.MarkupContainer.onComponentTagBody(MarkupContain
> > > er
> > > .j
> > > ava:1484)
> > > ~[wicket-core-6.9.1.jar:6.9.1]
> > > at
> > > org.apache.wicket.markup.html.panel.DefaultMarkupSourcingStrategy.
> > > on
> > > Co
> > > mponentTagBody(DefaultMarkupSourcingStrategy.java:71)
> > > ~[wicket-core-6.9.1.jar:6.9.1]
> > > at
> > > org.apache.wicket.Component.internalRenderComponent(Component.java
> > > :2
> > > 54
> > > 9)
> > > [wicket-core-6.9.1.jar:6.9.1]
> > >
> > > The enclosure's child component is null, as we see here:
> > > | @Override
> > > | public boolean isVisible()
> > > | {
> > > | return childComponent.determineVisibility() &&
> > > super.isVisible();
> > > | }
> > >
> > > Below that exception I find the markup of a stack trace page in my
> logs.
> > > Below that markup I get another stack trace:
> > >
> > > java.lang.NullPointerException: null
> > > at
> > > org.apache.wicket.Component.internalPrepareForRender(Component.java:
> > > 22
> > > 24)
> > > ~[wicket-core-6.9.1.jar:6.9.1]
> > > at
> > > org.apache.wicket.Page.internalPrepareForRender(Page.java:241)
> > > ~[wicket-core-6.9.1.jar:6.9.1]
> > > at org.apache.wicket.Component.render(Component.java:2303)
> > > ~[wicket-core-6.9.1.jar:6.9.1]
> > > at org.apache.wicket.Page.renderPage(Page.java:1010)
> > > ~[wicket-core-6.9.1.jar:6.9.1]
> > > at
> > > org.apache.wicket.request.handler.render.WebPageRenderer.renderPag
> > > e(
> > > We
> > > bPageRenderer.java:121)
> > > ~[wicket-core-6.9.1.jar:6.9.1]
> > > at
> > > org.apache.wicket.request.handler.render.WebPageRenderer.respond(W
> > > eb
> > > Pa
> > > geRenderer.java:271)
> > > ~[wicket-core-6.9.1.jar:6.9.1]
> > > at
> > > org.apache.wicket.core.request.handler.RenderPageRequestHandler.re
> > > sp
> > > on
> > > d(RenderPageRequestHandler.java:165)
> > > ~[wicket-core-6.9.1.jar:6.9.1]
> > > at
> > > org.apache.wicket.request.cycle.RequestCycle$HandlerExecutor.respo
> > > nd
> > > (R
> > > equestCycle.java:861)
> > > ~[wicket-core-6.9.1.jar:6.9.1]
> > > at
> > > org.apache.wicket.request.RequestHandlerStack.execute(RequestHandl
> > > er
> > > St
> > > ack.java:64)
> > > ~[wicket-request-6.9.1.jar:6.9.1]
> > > at
> > > org.apache.wicket.request.cycle.RequestCycle.execute(RequestCycle.
> > > ja
> > > va
> > > :261)
> > > [wicket-core-6.9.1.jar:6.9.1]
> > > at
> > > org.apache.wicket.request.cycle.RequestCycle.processRequest(Reques
> > > tC
> > > yc
> > > le.java:218)
> > > [wicket-core-6.9.1.jar:6.9.1]
> > > at
> > > org.apache.wicket.request.cycle.RequestCycle.processRequestAndDeta
> > > ch
> > > (R
> > > equestCycle.java:289)
> > > [wicket-core-6.9.1.jar:6.9.1]
> > > at
> > > org.apache.wicket.protocol.http.WicketFilter.processRequestCycle(W
> > > ic
> > > ke
> > > tFilter.java:259)
> > > [wicket-core-6.9.1.jar:6.9.1]
> > > at
> > > org.apache.wicket.protocol.http.WicketFilter.processRequest(Wicket
> > > Fi
> > > lt
> > > er.java:201)
> > > [wicket-core-6.9.1.jar:6.9.1]
> > > at
> > > org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter
> > > .j
> > > av
> > > a:282)
> > > [wicket-core-6.9.1.jar:6.9.1]
> > >
> > > Here the RequestCycle is null:
> > > | if (setRenderingFlag)
> > > | {
> > > | // only process feedback panel when we are about
> > > | to be
> > > rendered.
> > > | // setRenderingFlag is false in case
> > > | prepareForRender is
> > > called only to build component
> > > | // hierarchy (i.e. in
> > > BookmarkableListenerInterfaceRequestTarget).
> > > | // prepareForRender(true) is always called before
> > > | the
> > > actual rendering is done so
> > > | // that's where feedback panels gather the
> > > | messages
> > > |
> > > | List<Component> feedbacks =
> > > getRequestCycle().getMetaData(FEEDBACK_LIST);
> > >
> > > To me it seems like I've got two different problems here:
> > >
> > > - the component cannot be rendered because I'm doing something
> > > fundamentally wrong, thus I'm not getting the expected output
> > >
> > > - after the mock-RequestCycle's done with its work, there's no
> > > RequestCycle set anymore, thus I cannot render the reply
> > >
> > >
> > > I understand that my problem may be rather specific. And since
> > > this is webservice that is already in use, I cannot just rewrite
> > > it completely. Thus I would greatly appreciate any hint how i
> > > could accomplish what the old code used to do before the Wicket upgrade?
> > >
> > > Cheers,
> > >
> > > M'bert
> > >
> > > --
> > > ----------- / http://herbert.the-little-red-haired-girl.org /
> > > -------------
> > > =+=
> > > Pilot: Call me a fuel truck.
> > > Tower: You're a fuel truck.
> > >
> > > ------------------------------------------------------------------
> > > --
> > > - To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> > > For additional commands, e-mail: users-help@wicket.apache.org
> > >
> > >
> >
> > --------------------------------------------------------------------
> > - To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> > For additional commands, e-mail: users-help@wicket.apache.org
> >
> >
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Rendering a component into a String
Posted by Martin Grigorov <mg...@apache.org>.
Option 1) Override your component's onInitialize/onConfigure and call
page.setStatelessHint(true)
Option 2) Copy/paste ComponentRenderer.java locally and do something
similar directly in RenderPage
On Thu, Nov 21, 2013 at 11:29 AM, Mateusz Mieszkowski <
mmieszkowski@objectivity.co.uk> wrote:
> Martin,
>
> Ticket created: https://issues.apache.org/jira/browse/WICKET-5422
> Can you advise a workaround for now?
>
> Cheers,
> Mateusz
>
>
> -----Original Message-----
> From: Martin Grigorov [mailto:mgrigorov@apache.org]
> Sent: Thursday, November 21, 2013 9:49 AM
> To: users@wicket.apache.org
> Cc: Martin Dietze
> Subject: Re: Rendering a component into a String
>
> Please create a ticket.
> The page should be marked as stateless to avoid storing it.
>
>
> On Thu, Nov 21, 2013 at 10:40 AM, Mateusz Mieszkowski <
> mmieszkowski@objectivity.co.uk> wrote:
>
> > Hi guys,
> >
> > I noticed a problem with ComponentRenderer.renderComponent(). It is
> > possible that I'm missing something but this is what I get for now:
> > I'm using ComponenetRenderer withing CustomTooltipBehavior
> > (wicket-jquery-ui) to generate tooltip content. I add this to about 50
> > rows in my table so I run renderComponent() method as many times.
> > All worked fine but there was a problem with performance when I used
> > Fragment component with markup attached to the WebPage. I did some
> > digging and finally checked
> > http://localhost:8080/context/wicket/internal/debug/diskDataStore and
> > it appeared that for one request, Wicket stores 51 pages in it. All of
> > the size of the whole page (about 300kB) and all of them named
> > org.apache.wicket.core.util.string.ComponentRenderer$RenderPage.
> >
> > I changed implementation from Fragment to Panel componenet and the
> > size was reduced to (1kB) but still all of these items were stored in
> > the DataStore.
> >
> > It seems that this method is creating a dummy page in order to create
> > the markup, but how can I avoid storing these pages?
> >
> > Best regards,
> > Mateusz
> >
> > -----Original Message-----
> > From: Martin Grigorov [mailto:mgrigorov@apache.org]
> > Sent: Wednesday, November 13, 2013 2:09 PM
> > To: users@wicket.apache.org; Martin Dietze
> > Subject: Re: Rendering a component into a String
> >
> > Hi,
> >
> > See the source of
> > http://www.wicket-library.com/wicket-examples-6.0.x/mailtemplate/?2exa
> > mple
> >
> >
> > On Wed, Nov 13, 2013 at 3:04 PM, Martin Dietze <di...@fh-wedel.de> wrote:
> >
> > > In a legacy project I've inherited I've got a piece of code that no
> > > longer works since the project was upgraded from Wicket 1.4 to
> > > Wicket 6.
> > >
> > > It's about rendering a component (a Wicket panel) into a string in
> > > order to return it wrapped into a webservice reply.
> > >
> > > The webservice is based on Wicket, too. The webservice is based on a
> > > Javascript handshake - the client calls the service using a token
> > > connecting the user to his current session he has on the
> > > application, the service replies are rendered into an iframe and
> > > deliver their data through postMessage.
> > >
> > > Thus, when rendering a reply, I am basically rendering a Wicket page
> > > within the context of my session.
> > >
> > > Now one of my API's calls requires me to render a Wicket panel into
> > > a String, which is then wrapped into JSON as part of the respective
> > > call's reply.
> > >
> > > The legacy code used to do this roughly like this (changes for using
> > > the Wicket 6 API were applied, but this nevertheless never
> > > worked):
> > >
> > > - create a mock RequestCycle by creating a MockHttpSession, a
> > > MockHttpServletRequest and a MockHttpServletResponse, glue
> > > this all together to obtain a ServletWebRequest and a
> > > BufferedWebResponse and finaly use use
> Application.createRequestCycle()
> > > to create the RequestCycle object
> > >
> > > - the component wrapped into a ComponentRenderingRequestHandler
> > >
> > > - then this code is executed:
> > >
> > > | try {
> > > |
> requestCycle.scheduleRequestHandlerAfterCurrent(requestHandler);
> > > | try {
> > > | if ( !requestCycle.processRequestAndDetach() ) {
> > > | requestCycle.scheduleRequestHandlerAfterCurrent(new
> > > ErrorCodeRequestHandler((HttpServletResponse.SC_NOT_FOUND));
> > > | }
> > > | } finally {
> > > | requestCycle.getResponse().close();
> > > | }
> > > | return requestCycle.getResponse().toString();
> > > | } finally {
> > > | requestCycle.detach();
> > > | }
> > >
> > > I must admit I could not have written this myself :)
> > >
> > > Now when running this code, I run into two different
> > > exceptions:
> > >
> > > org.apache.wicket.WicketRuntimeException: Exception in rendering
> > > component: [Profile [Component id = profile]]
> > > at
> > > org.apache.wicket.Component.internalRenderComponent(Component.java:2
> > > 57
> > > 6)
> > > [wicket-core-6.9.1.jar:6.9.1]
> > > at
> > > org.apache.wicket.MarkupContainer.onRender(MarkupContainer.java:1493
> > > )
> > > ~[wicket-core-6.9.1.jar:6.9.1]
> > > at
> > > org.apache.wicket.Component.internalRender(Component.java:2379)
> > > [wicket-core-6.9.1.jar:6.9.1]
> > > at org.apache.wicket.Component.render(Component.java:2307)
> > > [wicket-core-6.9.1.jar:6.9.1]
> > > [...]
> > > Caused by: java.lang.NullPointerException: null
> > > at
> > > org.apache.wicket.markup.html.internal.Enclosure.isVisible(Enclosure
> > > .j
> > > ava:143)
> > > ~[wicket-core-6.9.1.jar:6.9.1]
> > > at
> > > org.apache.wicket.Component.determineVisibility(Component.java:4363)
> > > [wicket-core-6.9.1.jar:6.9.1]
> > > at
> > > org.apache.wicket.Component.internalBeforeRender(Component.java:916)
> > > [wicket-core-6.9.1.jar:6.9.1]
> > > at
> > > org.apache.wicket.Component.beforeRender(Component.java:991)
> > > [wicket-core-6.9.1.jar:6.9.1]
> > > at
> > > org.apache.wicket.Component.internalPrepareForRender(Component.java:
> > > 22
> > > 14)
> > > [wicket-core-6.9.1.jar:6.9.1]
> > > at org.apache.wicket.Component.render(Component.java:2303)
> > > [wicket-core-6.9.1.jar:6.9.1]
> > > at
> > > org.apache.wicket.MarkupContainer.renderNext(MarkupContainer.java:13
> > > 90
> > > )
> > > ~[wicket-core-6.9.1.jar:6.9.1]
> > > at
> > > org.apache.wicket.MarkupContainer.renderAll(MarkupContainer.java:155
> > > 4)
> > > ~[wicket-core-6.9.1.jar:6.9.1]
> > > at
> > > org.apache.wicket.MarkupContainer.renderComponentTagBody(MarkupConta
> > > in
> > > er.java:1529)
> > > ~[wicket-core-6.9.1.jar:6.9.1]
> > > at
> > > org.apache.wicket.MarkupContainer.onComponentTagBody(MarkupContainer
> > > .j
> > > ava:1484)
> > > ~[wicket-core-6.9.1.jar:6.9.1]
> > > at
> > > org.apache.wicket.markup.html.panel.DefaultMarkupSourcingStrategy.on
> > > Co
> > > mponentTagBody(DefaultMarkupSourcingStrategy.java:71)
> > > ~[wicket-core-6.9.1.jar:6.9.1]
> > > at
> > > org.apache.wicket.Component.internalRenderComponent(Component.java:2
> > > 54
> > > 9)
> > > [wicket-core-6.9.1.jar:6.9.1]
> > >
> > > The enclosure's child component is null, as we see here:
> > > | @Override
> > > | public boolean isVisible()
> > > | {
> > > | return childComponent.determineVisibility() &&
> > > super.isVisible();
> > > | }
> > >
> > > Below that exception I find the markup of a stack trace page in my
> logs.
> > > Below that markup I get another stack trace:
> > >
> > > java.lang.NullPointerException: null
> > > at
> > > org.apache.wicket.Component.internalPrepareForRender(Component.java:
> > > 22
> > > 24)
> > > ~[wicket-core-6.9.1.jar:6.9.1]
> > > at
> > > org.apache.wicket.Page.internalPrepareForRender(Page.java:241)
> > > ~[wicket-core-6.9.1.jar:6.9.1]
> > > at org.apache.wicket.Component.render(Component.java:2303)
> > > ~[wicket-core-6.9.1.jar:6.9.1]
> > > at org.apache.wicket.Page.renderPage(Page.java:1010)
> > > ~[wicket-core-6.9.1.jar:6.9.1]
> > > at
> > > org.apache.wicket.request.handler.render.WebPageRenderer.renderPage(
> > > We
> > > bPageRenderer.java:121)
> > > ~[wicket-core-6.9.1.jar:6.9.1]
> > > at
> > > org.apache.wicket.request.handler.render.WebPageRenderer.respond(Web
> > > Pa
> > > geRenderer.java:271)
> > > ~[wicket-core-6.9.1.jar:6.9.1]
> > > at
> > > org.apache.wicket.core.request.handler.RenderPageRequestHandler.resp
> > > on
> > > d(RenderPageRequestHandler.java:165)
> > > ~[wicket-core-6.9.1.jar:6.9.1]
> > > at
> > > org.apache.wicket.request.cycle.RequestCycle$HandlerExecutor.respond
> > > (R
> > > equestCycle.java:861)
> > > ~[wicket-core-6.9.1.jar:6.9.1]
> > > at
> > > org.apache.wicket.request.RequestHandlerStack.execute(RequestHandler
> > > St
> > > ack.java:64)
> > > ~[wicket-request-6.9.1.jar:6.9.1]
> > > at
> > > org.apache.wicket.request.cycle.RequestCycle.execute(RequestCycle.ja
> > > va
> > > :261)
> > > [wicket-core-6.9.1.jar:6.9.1]
> > > at
> > > org.apache.wicket.request.cycle.RequestCycle.processRequest(RequestC
> > > yc
> > > le.java:218)
> > > [wicket-core-6.9.1.jar:6.9.1]
> > > at
> > > org.apache.wicket.request.cycle.RequestCycle.processRequestAndDetach
> > > (R
> > > equestCycle.java:289)
> > > [wicket-core-6.9.1.jar:6.9.1]
> > > at
> > > org.apache.wicket.protocol.http.WicketFilter.processRequestCycle(Wic
> > > ke
> > > tFilter.java:259)
> > > [wicket-core-6.9.1.jar:6.9.1]
> > > at
> > > org.apache.wicket.protocol.http.WicketFilter.processRequest(WicketFi
> > > lt
> > > er.java:201)
> > > [wicket-core-6.9.1.jar:6.9.1]
> > > at
> > > org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.j
> > > av
> > > a:282)
> > > [wicket-core-6.9.1.jar:6.9.1]
> > >
> > > Here the RequestCycle is null:
> > > | if (setRenderingFlag)
> > > | {
> > > | // only process feedback panel when we are about to
> > > | be
> > > rendered.
> > > | // setRenderingFlag is false in case
> > > | prepareForRender is
> > > called only to build component
> > > | // hierarchy (i.e. in
> > > BookmarkableListenerInterfaceRequestTarget).
> > > | // prepareForRender(true) is always called before
> > > | the
> > > actual rendering is done so
> > > | // that's where feedback panels gather the messages
> > > |
> > > | List<Component> feedbacks =
> > > getRequestCycle().getMetaData(FEEDBACK_LIST);
> > >
> > > To me it seems like I've got two different problems here:
> > >
> > > - the component cannot be rendered because I'm doing something
> > > fundamentally wrong, thus I'm not getting the expected output
> > >
> > > - after the mock-RequestCycle's done with its work, there's no
> > > RequestCycle set anymore, thus I cannot render the reply
> > >
> > >
> > > I understand that my problem may be rather specific. And since this
> > > is webservice that is already in use, I cannot just rewrite it
> > > completely. Thus I would greatly appreciate any hint how i could
> > > accomplish what the old code used to do before the Wicket upgrade?
> > >
> > > Cheers,
> > >
> > > M'bert
> > >
> > > --
> > > ----------- / http://herbert.the-little-red-haired-girl.org /
> > > -------------
> > > =+=
> > > Pilot: Call me a fuel truck.
> > > Tower: You're a fuel truck.
> > >
> > > --------------------------------------------------------------------
> > > - To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> > > For additional commands, e-mail: users-help@wicket.apache.org
> > >
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> > For additional commands, e-mail: users-help@wicket.apache.org
> >
> >
>
RE: Rendering a component into a String
Posted by Mateusz Mieszkowski <mm...@objectivity.co.uk>.
Martin,
Ticket created: https://issues.apache.org/jira/browse/WICKET-5422
Can you advise a workaround for now?
Cheers,
Mateusz
-----Original Message-----
From: Martin Grigorov [mailto:mgrigorov@apache.org]
Sent: Thursday, November 21, 2013 9:49 AM
To: users@wicket.apache.org
Cc: Martin Dietze
Subject: Re: Rendering a component into a String
Please create a ticket.
The page should be marked as stateless to avoid storing it.
On Thu, Nov 21, 2013 at 10:40 AM, Mateusz Mieszkowski < mmieszkowski@objectivity.co.uk> wrote:
> Hi guys,
>
> I noticed a problem with ComponentRenderer.renderComponent(). It is
> possible that I'm missing something but this is what I get for now:
> I'm using ComponenetRenderer withing CustomTooltipBehavior
> (wicket-jquery-ui) to generate tooltip content. I add this to about 50
> rows in my table so I run renderComponent() method as many times.
> All worked fine but there was a problem with performance when I used
> Fragment component with markup attached to the WebPage. I did some
> digging and finally checked
> http://localhost:8080/context/wicket/internal/debug/diskDataStore and
> it appeared that for one request, Wicket stores 51 pages in it. All of
> the size of the whole page (about 300kB) and all of them named
> org.apache.wicket.core.util.string.ComponentRenderer$RenderPage.
>
> I changed implementation from Fragment to Panel componenet and the
> size was reduced to (1kB) but still all of these items were stored in
> the DataStore.
>
> It seems that this method is creating a dummy page in order to create
> the markup, but how can I avoid storing these pages?
>
> Best regards,
> Mateusz
>
> -----Original Message-----
> From: Martin Grigorov [mailto:mgrigorov@apache.org]
> Sent: Wednesday, November 13, 2013 2:09 PM
> To: users@wicket.apache.org; Martin Dietze
> Subject: Re: Rendering a component into a String
>
> Hi,
>
> See the source of
> http://www.wicket-library.com/wicket-examples-6.0.x/mailtemplate/?2exa
> mple
>
>
> On Wed, Nov 13, 2013 at 3:04 PM, Martin Dietze <di...@fh-wedel.de> wrote:
>
> > In a legacy project I've inherited I've got a piece of code that no
> > longer works since the project was upgraded from Wicket 1.4 to
> > Wicket 6.
> >
> > It's about rendering a component (a Wicket panel) into a string in
> > order to return it wrapped into a webservice reply.
> >
> > The webservice is based on Wicket, too. The webservice is based on a
> > Javascript handshake - the client calls the service using a token
> > connecting the user to his current session he has on the
> > application, the service replies are rendered into an iframe and
> > deliver their data through postMessage.
> >
> > Thus, when rendering a reply, I am basically rendering a Wicket page
> > within the context of my session.
> >
> > Now one of my API's calls requires me to render a Wicket panel into
> > a String, which is then wrapped into JSON as part of the respective
> > call's reply.
> >
> > The legacy code used to do this roughly like this (changes for using
> > the Wicket 6 API were applied, but this nevertheless never
> > worked):
> >
> > - create a mock RequestCycle by creating a MockHttpSession, a
> > MockHttpServletRequest and a MockHttpServletResponse, glue
> > this all together to obtain a ServletWebRequest and a
> > BufferedWebResponse and finaly use use Application.createRequestCycle()
> > to create the RequestCycle object
> >
> > - the component wrapped into a ComponentRenderingRequestHandler
> >
> > - then this code is executed:
> >
> > | try {
> > | requestCycle.scheduleRequestHandlerAfterCurrent(requestHandler);
> > | try {
> > | if ( !requestCycle.processRequestAndDetach() ) {
> > | requestCycle.scheduleRequestHandlerAfterCurrent(new
> > ErrorCodeRequestHandler((HttpServletResponse.SC_NOT_FOUND));
> > | }
> > | } finally {
> > | requestCycle.getResponse().close();
> > | }
> > | return requestCycle.getResponse().toString();
> > | } finally {
> > | requestCycle.detach();
> > | }
> >
> > I must admit I could not have written this myself :)
> >
> > Now when running this code, I run into two different
> > exceptions:
> >
> > org.apache.wicket.WicketRuntimeException: Exception in rendering
> > component: [Profile [Component id = profile]]
> > at
> > org.apache.wicket.Component.internalRenderComponent(Component.java:2
> > 57
> > 6)
> > [wicket-core-6.9.1.jar:6.9.1]
> > at
> > org.apache.wicket.MarkupContainer.onRender(MarkupContainer.java:1493
> > )
> > ~[wicket-core-6.9.1.jar:6.9.1]
> > at
> > org.apache.wicket.Component.internalRender(Component.java:2379)
> > [wicket-core-6.9.1.jar:6.9.1]
> > at org.apache.wicket.Component.render(Component.java:2307)
> > [wicket-core-6.9.1.jar:6.9.1]
> > [...]
> > Caused by: java.lang.NullPointerException: null
> > at
> > org.apache.wicket.markup.html.internal.Enclosure.isVisible(Enclosure
> > .j
> > ava:143)
> > ~[wicket-core-6.9.1.jar:6.9.1]
> > at
> > org.apache.wicket.Component.determineVisibility(Component.java:4363)
> > [wicket-core-6.9.1.jar:6.9.1]
> > at
> > org.apache.wicket.Component.internalBeforeRender(Component.java:916)
> > [wicket-core-6.9.1.jar:6.9.1]
> > at
> > org.apache.wicket.Component.beforeRender(Component.java:991)
> > [wicket-core-6.9.1.jar:6.9.1]
> > at
> > org.apache.wicket.Component.internalPrepareForRender(Component.java:
> > 22
> > 14)
> > [wicket-core-6.9.1.jar:6.9.1]
> > at org.apache.wicket.Component.render(Component.java:2303)
> > [wicket-core-6.9.1.jar:6.9.1]
> > at
> > org.apache.wicket.MarkupContainer.renderNext(MarkupContainer.java:13
> > 90
> > )
> > ~[wicket-core-6.9.1.jar:6.9.1]
> > at
> > org.apache.wicket.MarkupContainer.renderAll(MarkupContainer.java:155
> > 4)
> > ~[wicket-core-6.9.1.jar:6.9.1]
> > at
> > org.apache.wicket.MarkupContainer.renderComponentTagBody(MarkupConta
> > in
> > er.java:1529)
> > ~[wicket-core-6.9.1.jar:6.9.1]
> > at
> > org.apache.wicket.MarkupContainer.onComponentTagBody(MarkupContainer
> > .j
> > ava:1484)
> > ~[wicket-core-6.9.1.jar:6.9.1]
> > at
> > org.apache.wicket.markup.html.panel.DefaultMarkupSourcingStrategy.on
> > Co
> > mponentTagBody(DefaultMarkupSourcingStrategy.java:71)
> > ~[wicket-core-6.9.1.jar:6.9.1]
> > at
> > org.apache.wicket.Component.internalRenderComponent(Component.java:2
> > 54
> > 9)
> > [wicket-core-6.9.1.jar:6.9.1]
> >
> > The enclosure's child component is null, as we see here:
> > | @Override
> > | public boolean isVisible()
> > | {
> > | return childComponent.determineVisibility() &&
> > super.isVisible();
> > | }
> >
> > Below that exception I find the markup of a stack trace page in my logs.
> > Below that markup I get another stack trace:
> >
> > java.lang.NullPointerException: null
> > at
> > org.apache.wicket.Component.internalPrepareForRender(Component.java:
> > 22
> > 24)
> > ~[wicket-core-6.9.1.jar:6.9.1]
> > at
> > org.apache.wicket.Page.internalPrepareForRender(Page.java:241)
> > ~[wicket-core-6.9.1.jar:6.9.1]
> > at org.apache.wicket.Component.render(Component.java:2303)
> > ~[wicket-core-6.9.1.jar:6.9.1]
> > at org.apache.wicket.Page.renderPage(Page.java:1010)
> > ~[wicket-core-6.9.1.jar:6.9.1]
> > at
> > org.apache.wicket.request.handler.render.WebPageRenderer.renderPage(
> > We
> > bPageRenderer.java:121)
> > ~[wicket-core-6.9.1.jar:6.9.1]
> > at
> > org.apache.wicket.request.handler.render.WebPageRenderer.respond(Web
> > Pa
> > geRenderer.java:271)
> > ~[wicket-core-6.9.1.jar:6.9.1]
> > at
> > org.apache.wicket.core.request.handler.RenderPageRequestHandler.resp
> > on
> > d(RenderPageRequestHandler.java:165)
> > ~[wicket-core-6.9.1.jar:6.9.1]
> > at
> > org.apache.wicket.request.cycle.RequestCycle$HandlerExecutor.respond
> > (R
> > equestCycle.java:861)
> > ~[wicket-core-6.9.1.jar:6.9.1]
> > at
> > org.apache.wicket.request.RequestHandlerStack.execute(RequestHandler
> > St
> > ack.java:64)
> > ~[wicket-request-6.9.1.jar:6.9.1]
> > at
> > org.apache.wicket.request.cycle.RequestCycle.execute(RequestCycle.ja
> > va
> > :261)
> > [wicket-core-6.9.1.jar:6.9.1]
> > at
> > org.apache.wicket.request.cycle.RequestCycle.processRequest(RequestC
> > yc
> > le.java:218)
> > [wicket-core-6.9.1.jar:6.9.1]
> > at
> > org.apache.wicket.request.cycle.RequestCycle.processRequestAndDetach
> > (R
> > equestCycle.java:289)
> > [wicket-core-6.9.1.jar:6.9.1]
> > at
> > org.apache.wicket.protocol.http.WicketFilter.processRequestCycle(Wic
> > ke
> > tFilter.java:259)
> > [wicket-core-6.9.1.jar:6.9.1]
> > at
> > org.apache.wicket.protocol.http.WicketFilter.processRequest(WicketFi
> > lt
> > er.java:201)
> > [wicket-core-6.9.1.jar:6.9.1]
> > at
> > org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.j
> > av
> > a:282)
> > [wicket-core-6.9.1.jar:6.9.1]
> >
> > Here the RequestCycle is null:
> > | if (setRenderingFlag)
> > | {
> > | // only process feedback panel when we are about to
> > | be
> > rendered.
> > | // setRenderingFlag is false in case
> > | prepareForRender is
> > called only to build component
> > | // hierarchy (i.e. in
> > BookmarkableListenerInterfaceRequestTarget).
> > | // prepareForRender(true) is always called before
> > | the
> > actual rendering is done so
> > | // that's where feedback panels gather the messages
> > |
> > | List<Component> feedbacks =
> > getRequestCycle().getMetaData(FEEDBACK_LIST);
> >
> > To me it seems like I've got two different problems here:
> >
> > - the component cannot be rendered because I'm doing something
> > fundamentally wrong, thus I'm not getting the expected output
> >
> > - after the mock-RequestCycle's done with its work, there's no
> > RequestCycle set anymore, thus I cannot render the reply
> >
> >
> > I understand that my problem may be rather specific. And since this
> > is webservice that is already in use, I cannot just rewrite it
> > completely. Thus I would greatly appreciate any hint how i could
> > accomplish what the old code used to do before the Wicket upgrade?
> >
> > Cheers,
> >
> > M'bert
> >
> > --
> > ----------- / http://herbert.the-little-red-haired-girl.org /
> > -------------
> > =+=
> > Pilot: Call me a fuel truck.
> > Tower: You're a fuel truck.
> >
> > --------------------------------------------------------------------
> > - To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> > For additional commands, e-mail: users-help@wicket.apache.org
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
Re: Rendering a component into a String
Posted by Martin Grigorov <mg...@apache.org>.
Please create a ticket.
The page should be marked as stateless to avoid storing it.
On Thu, Nov 21, 2013 at 10:40 AM, Mateusz Mieszkowski <
mmieszkowski@objectivity.co.uk> wrote:
> Hi guys,
>
> I noticed a problem with ComponentRenderer.renderComponent(). It is
> possible that I'm missing something but this is what I get for now:
> I'm using ComponenetRenderer withing CustomTooltipBehavior
> (wicket-jquery-ui) to generate tooltip content. I add this to about 50 rows
> in my table so I run renderComponent() method as many times.
> All worked fine but there was a problem with performance when I used
> Fragment component with markup attached to the WebPage. I did some digging
> and finally checked
> http://localhost:8080/context/wicket/internal/debug/diskDataStore and it
> appeared that for one request, Wicket stores 51 pages in it. All of the
> size of the whole page (about 300kB) and all of them named
> org.apache.wicket.core.util.string.ComponentRenderer$RenderPage.
>
> I changed implementation from Fragment to Panel componenet and the size
> was reduced to (1kB) but still all of these items were stored in the
> DataStore.
>
> It seems that this method is creating a dummy page in order to create the
> markup, but how can I avoid storing these pages?
>
> Best regards,
> Mateusz
>
> -----Original Message-----
> From: Martin Grigorov [mailto:mgrigorov@apache.org]
> Sent: Wednesday, November 13, 2013 2:09 PM
> To: users@wicket.apache.org; Martin Dietze
> Subject: Re: Rendering a component into a String
>
> Hi,
>
> See the source of
> http://www.wicket-library.com/wicket-examples-6.0.x/mailtemplate/?2example
>
>
> On Wed, Nov 13, 2013 at 3:04 PM, Martin Dietze <di...@fh-wedel.de> wrote:
>
> > In a legacy project I've inherited I've got a piece of code that no
> > longer works since the project was upgraded from Wicket 1.4 to Wicket
> > 6.
> >
> > It's about rendering a component (a Wicket panel) into a string in
> > order to return it wrapped into a webservice reply.
> >
> > The webservice is based on Wicket, too. The webservice is based on a
> > Javascript handshake - the client calls the service using a token
> > connecting the user to his current session he has on the application,
> > the service replies are rendered into an iframe and deliver their data
> > through postMessage.
> >
> > Thus, when rendering a reply, I am basically rendering a Wicket page
> > within the context of my session.
> >
> > Now one of my API's calls requires me to render a Wicket panel into a
> > String, which is then wrapped into JSON as part of the respective
> > call's reply.
> >
> > The legacy code used to do this roughly like this (changes for using
> > the Wicket 6 API were applied, but this nevertheless never
> > worked):
> >
> > - create a mock RequestCycle by creating a MockHttpSession, a
> > MockHttpServletRequest and a MockHttpServletResponse, glue
> > this all together to obtain a ServletWebRequest and a
> > BufferedWebResponse and finaly use use Application.createRequestCycle()
> > to create the RequestCycle object
> >
> > - the component wrapped into a ComponentRenderingRequestHandler
> >
> > - then this code is executed:
> >
> > | try {
> > | requestCycle.scheduleRequestHandlerAfterCurrent(requestHandler);
> > | try {
> > | if ( !requestCycle.processRequestAndDetach() ) {
> > | requestCycle.scheduleRequestHandlerAfterCurrent(new
> > ErrorCodeRequestHandler((HttpServletResponse.SC_NOT_FOUND));
> > | }
> > | } finally {
> > | requestCycle.getResponse().close();
> > | }
> > | return requestCycle.getResponse().toString();
> > | } finally {
> > | requestCycle.detach();
> > | }
> >
> > I must admit I could not have written this myself :)
> >
> > Now when running this code, I run into two different
> > exceptions:
> >
> > org.apache.wicket.WicketRuntimeException: Exception in rendering
> > component: [Profile [Component id = profile]]
> > at
> > org.apache.wicket.Component.internalRenderComponent(Component.java:257
> > 6)
> > [wicket-core-6.9.1.jar:6.9.1]
> > at
> > org.apache.wicket.MarkupContainer.onRender(MarkupContainer.java:1493)
> > ~[wicket-core-6.9.1.jar:6.9.1]
> > at
> > org.apache.wicket.Component.internalRender(Component.java:2379)
> > [wicket-core-6.9.1.jar:6.9.1]
> > at org.apache.wicket.Component.render(Component.java:2307)
> > [wicket-core-6.9.1.jar:6.9.1]
> > [...]
> > Caused by: java.lang.NullPointerException: null
> > at
> > org.apache.wicket.markup.html.internal.Enclosure.isVisible(Enclosure.j
> > ava:143)
> > ~[wicket-core-6.9.1.jar:6.9.1]
> > at
> > org.apache.wicket.Component.determineVisibility(Component.java:4363)
> > [wicket-core-6.9.1.jar:6.9.1]
> > at
> > org.apache.wicket.Component.internalBeforeRender(Component.java:916)
> > [wicket-core-6.9.1.jar:6.9.1]
> > at
> > org.apache.wicket.Component.beforeRender(Component.java:991)
> > [wicket-core-6.9.1.jar:6.9.1]
> > at
> > org.apache.wicket.Component.internalPrepareForRender(Component.java:22
> > 14)
> > [wicket-core-6.9.1.jar:6.9.1]
> > at org.apache.wicket.Component.render(Component.java:2303)
> > [wicket-core-6.9.1.jar:6.9.1]
> > at
> > org.apache.wicket.MarkupContainer.renderNext(MarkupContainer.java:1390
> > )
> > ~[wicket-core-6.9.1.jar:6.9.1]
> > at
> > org.apache.wicket.MarkupContainer.renderAll(MarkupContainer.java:1554)
> > ~[wicket-core-6.9.1.jar:6.9.1]
> > at
> > org.apache.wicket.MarkupContainer.renderComponentTagBody(MarkupContain
> > er.java:1529)
> > ~[wicket-core-6.9.1.jar:6.9.1]
> > at
> > org.apache.wicket.MarkupContainer.onComponentTagBody(MarkupContainer.j
> > ava:1484)
> > ~[wicket-core-6.9.1.jar:6.9.1]
> > at
> > org.apache.wicket.markup.html.panel.DefaultMarkupSourcingStrategy.onCo
> > mponentTagBody(DefaultMarkupSourcingStrategy.java:71)
> > ~[wicket-core-6.9.1.jar:6.9.1]
> > at
> > org.apache.wicket.Component.internalRenderComponent(Component.java:254
> > 9)
> > [wicket-core-6.9.1.jar:6.9.1]
> >
> > The enclosure's child component is null, as we see here:
> > | @Override
> > | public boolean isVisible()
> > | {
> > | return childComponent.determineVisibility() &&
> > super.isVisible();
> > | }
> >
> > Below that exception I find the markup of a stack trace page in my logs.
> > Below that markup I get another stack trace:
> >
> > java.lang.NullPointerException: null
> > at
> > org.apache.wicket.Component.internalPrepareForRender(Component.java:22
> > 24)
> > ~[wicket-core-6.9.1.jar:6.9.1]
> > at
> > org.apache.wicket.Page.internalPrepareForRender(Page.java:241)
> > ~[wicket-core-6.9.1.jar:6.9.1]
> > at org.apache.wicket.Component.render(Component.java:2303)
> > ~[wicket-core-6.9.1.jar:6.9.1]
> > at org.apache.wicket.Page.renderPage(Page.java:1010)
> > ~[wicket-core-6.9.1.jar:6.9.1]
> > at
> > org.apache.wicket.request.handler.render.WebPageRenderer.renderPage(We
> > bPageRenderer.java:121)
> > ~[wicket-core-6.9.1.jar:6.9.1]
> > at
> > org.apache.wicket.request.handler.render.WebPageRenderer.respond(WebPa
> > geRenderer.java:271)
> > ~[wicket-core-6.9.1.jar:6.9.1]
> > at
> > org.apache.wicket.core.request.handler.RenderPageRequestHandler.respon
> > d(RenderPageRequestHandler.java:165)
> > ~[wicket-core-6.9.1.jar:6.9.1]
> > at
> > org.apache.wicket.request.cycle.RequestCycle$HandlerExecutor.respond(R
> > equestCycle.java:861)
> > ~[wicket-core-6.9.1.jar:6.9.1]
> > at
> > org.apache.wicket.request.RequestHandlerStack.execute(RequestHandlerSt
> > ack.java:64)
> > ~[wicket-request-6.9.1.jar:6.9.1]
> > at
> > org.apache.wicket.request.cycle.RequestCycle.execute(RequestCycle.java
> > :261)
> > [wicket-core-6.9.1.jar:6.9.1]
> > at
> > org.apache.wicket.request.cycle.RequestCycle.processRequest(RequestCyc
> > le.java:218)
> > [wicket-core-6.9.1.jar:6.9.1]
> > at
> > org.apache.wicket.request.cycle.RequestCycle.processRequestAndDetach(R
> > equestCycle.java:289)
> > [wicket-core-6.9.1.jar:6.9.1]
> > at
> > org.apache.wicket.protocol.http.WicketFilter.processRequestCycle(Wicke
> > tFilter.java:259)
> > [wicket-core-6.9.1.jar:6.9.1]
> > at
> > org.apache.wicket.protocol.http.WicketFilter.processRequest(WicketFilt
> > er.java:201)
> > [wicket-core-6.9.1.jar:6.9.1]
> > at
> > org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.jav
> > a:282)
> > [wicket-core-6.9.1.jar:6.9.1]
> >
> > Here the RequestCycle is null:
> > | if (setRenderingFlag)
> > | {
> > | // only process feedback panel when we are about to
> > | be
> > rendered.
> > | // setRenderingFlag is false in case prepareForRender
> > | is
> > called only to build component
> > | // hierarchy (i.e. in
> > BookmarkableListenerInterfaceRequestTarget).
> > | // prepareForRender(true) is always called before the
> > actual rendering is done so
> > | // that's where feedback panels gather the messages
> > |
> > | List<Component> feedbacks =
> > getRequestCycle().getMetaData(FEEDBACK_LIST);
> >
> > To me it seems like I've got two different problems here:
> >
> > - the component cannot be rendered because I'm doing something
> > fundamentally wrong, thus I'm not getting the expected output
> >
> > - after the mock-RequestCycle's done with its work, there's no
> > RequestCycle set anymore, thus I cannot render the reply
> >
> >
> > I understand that my problem may be rather specific. And since this is
> > webservice that is already in use, I cannot just rewrite it
> > completely. Thus I would greatly appreciate any hint how i could
> > accomplish what the old code used to do before the Wicket upgrade?
> >
> > Cheers,
> >
> > M'bert
> >
> > --
> > ----------- / http://herbert.the-little-red-haired-girl.org /
> > -------------
> > =+=
> > Pilot: Call me a fuel truck.
> > Tower: You're a fuel truck.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> > For additional commands, e-mail: users-help@wicket.apache.org
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
RE: Rendering a component into a String
Posted by Mateusz Mieszkowski <mm...@objectivity.co.uk>.
Hi guys,
I noticed a problem with ComponentRenderer.renderComponent(). It is possible that I'm missing something but this is what I get for now:
I'm using ComponenetRenderer withing CustomTooltipBehavior (wicket-jquery-ui) to generate tooltip content. I add this to about 50 rows in my table so I run renderComponent() method as many times.
All worked fine but there was a problem with performance when I used Fragment component with markup attached to the WebPage. I did some digging and finally checked http://localhost:8080/context/wicket/internal/debug/diskDataStore and it appeared that for one request, Wicket stores 51 pages in it. All of the size of the whole page (about 300kB) and all of them named org.apache.wicket.core.util.string.ComponentRenderer$RenderPage.
I changed implementation from Fragment to Panel componenet and the size was reduced to (1kB) but still all of these items were stored in the DataStore.
It seems that this method is creating a dummy page in order to create the markup, but how can I avoid storing these pages?
Best regards,
Mateusz
-----Original Message-----
From: Martin Grigorov [mailto:mgrigorov@apache.org]
Sent: Wednesday, November 13, 2013 2:09 PM
To: users@wicket.apache.org; Martin Dietze
Subject: Re: Rendering a component into a String
Hi,
See the source of
http://www.wicket-library.com/wicket-examples-6.0.x/mailtemplate/?2 example
On Wed, Nov 13, 2013 at 3:04 PM, Martin Dietze <di...@fh-wedel.de> wrote:
> In a legacy project I've inherited I've got a piece of code that no
> longer works since the project was upgraded from Wicket 1.4 to Wicket
> 6.
>
> It's about rendering a component (a Wicket panel) into a string in
> order to return it wrapped into a webservice reply.
>
> The webservice is based on Wicket, too. The webservice is based on a
> Javascript handshake - the client calls the service using a token
> connecting the user to his current session he has on the application,
> the service replies are rendered into an iframe and deliver their data
> through postMessage.
>
> Thus, when rendering a reply, I am basically rendering a Wicket page
> within the context of my session.
>
> Now one of my API's calls requires me to render a Wicket panel into a
> String, which is then wrapped into JSON as part of the respective
> call's reply.
>
> The legacy code used to do this roughly like this (changes for using
> the Wicket 6 API were applied, but this nevertheless never
> worked):
>
> - create a mock RequestCycle by creating a MockHttpSession, a
> MockHttpServletRequest and a MockHttpServletResponse, glue
> this all together to obtain a ServletWebRequest and a
> BufferedWebResponse and finaly use use Application.createRequestCycle()
> to create the RequestCycle object
>
> - the component wrapped into a ComponentRenderingRequestHandler
>
> - then this code is executed:
>
> | try {
> | requestCycle.scheduleRequestHandlerAfterCurrent(requestHandler);
> | try {
> | if ( !requestCycle.processRequestAndDetach() ) {
> | requestCycle.scheduleRequestHandlerAfterCurrent(new
> ErrorCodeRequestHandler((HttpServletResponse.SC_NOT_FOUND));
> | }
> | } finally {
> | requestCycle.getResponse().close();
> | }
> | return requestCycle.getResponse().toString();
> | } finally {
> | requestCycle.detach();
> | }
>
> I must admit I could not have written this myself :)
>
> Now when running this code, I run into two different
> exceptions:
>
> org.apache.wicket.WicketRuntimeException: Exception in rendering
> component: [Profile [Component id = profile]]
> at
> org.apache.wicket.Component.internalRenderComponent(Component.java:257
> 6)
> [wicket-core-6.9.1.jar:6.9.1]
> at
> org.apache.wicket.MarkupContainer.onRender(MarkupContainer.java:1493)
> ~[wicket-core-6.9.1.jar:6.9.1]
> at
> org.apache.wicket.Component.internalRender(Component.java:2379)
> [wicket-core-6.9.1.jar:6.9.1]
> at org.apache.wicket.Component.render(Component.java:2307)
> [wicket-core-6.9.1.jar:6.9.1]
> [...]
> Caused by: java.lang.NullPointerException: null
> at
> org.apache.wicket.markup.html.internal.Enclosure.isVisible(Enclosure.j
> ava:143)
> ~[wicket-core-6.9.1.jar:6.9.1]
> at
> org.apache.wicket.Component.determineVisibility(Component.java:4363)
> [wicket-core-6.9.1.jar:6.9.1]
> at
> org.apache.wicket.Component.internalBeforeRender(Component.java:916)
> [wicket-core-6.9.1.jar:6.9.1]
> at
> org.apache.wicket.Component.beforeRender(Component.java:991)
> [wicket-core-6.9.1.jar:6.9.1]
> at
> org.apache.wicket.Component.internalPrepareForRender(Component.java:22
> 14)
> [wicket-core-6.9.1.jar:6.9.1]
> at org.apache.wicket.Component.render(Component.java:2303)
> [wicket-core-6.9.1.jar:6.9.1]
> at
> org.apache.wicket.MarkupContainer.renderNext(MarkupContainer.java:1390
> )
> ~[wicket-core-6.9.1.jar:6.9.1]
> at
> org.apache.wicket.MarkupContainer.renderAll(MarkupContainer.java:1554)
> ~[wicket-core-6.9.1.jar:6.9.1]
> at
> org.apache.wicket.MarkupContainer.renderComponentTagBody(MarkupContain
> er.java:1529)
> ~[wicket-core-6.9.1.jar:6.9.1]
> at
> org.apache.wicket.MarkupContainer.onComponentTagBody(MarkupContainer.j
> ava:1484)
> ~[wicket-core-6.9.1.jar:6.9.1]
> at
> org.apache.wicket.markup.html.panel.DefaultMarkupSourcingStrategy.onCo
> mponentTagBody(DefaultMarkupSourcingStrategy.java:71)
> ~[wicket-core-6.9.1.jar:6.9.1]
> at
> org.apache.wicket.Component.internalRenderComponent(Component.java:254
> 9)
> [wicket-core-6.9.1.jar:6.9.1]
>
> The enclosure's child component is null, as we see here:
> | @Override
> | public boolean isVisible()
> | {
> | return childComponent.determineVisibility() &&
> super.isVisible();
> | }
>
> Below that exception I find the markup of a stack trace page in my logs.
> Below that markup I get another stack trace:
>
> java.lang.NullPointerException: null
> at
> org.apache.wicket.Component.internalPrepareForRender(Component.java:22
> 24)
> ~[wicket-core-6.9.1.jar:6.9.1]
> at
> org.apache.wicket.Page.internalPrepareForRender(Page.java:241)
> ~[wicket-core-6.9.1.jar:6.9.1]
> at org.apache.wicket.Component.render(Component.java:2303)
> ~[wicket-core-6.9.1.jar:6.9.1]
> at org.apache.wicket.Page.renderPage(Page.java:1010)
> ~[wicket-core-6.9.1.jar:6.9.1]
> at
> org.apache.wicket.request.handler.render.WebPageRenderer.renderPage(We
> bPageRenderer.java:121)
> ~[wicket-core-6.9.1.jar:6.9.1]
> at
> org.apache.wicket.request.handler.render.WebPageRenderer.respond(WebPa
> geRenderer.java:271)
> ~[wicket-core-6.9.1.jar:6.9.1]
> at
> org.apache.wicket.core.request.handler.RenderPageRequestHandler.respon
> d(RenderPageRequestHandler.java:165)
> ~[wicket-core-6.9.1.jar:6.9.1]
> at
> org.apache.wicket.request.cycle.RequestCycle$HandlerExecutor.respond(R
> equestCycle.java:861)
> ~[wicket-core-6.9.1.jar:6.9.1]
> at
> org.apache.wicket.request.RequestHandlerStack.execute(RequestHandlerSt
> ack.java:64)
> ~[wicket-request-6.9.1.jar:6.9.1]
> at
> org.apache.wicket.request.cycle.RequestCycle.execute(RequestCycle.java
> :261)
> [wicket-core-6.9.1.jar:6.9.1]
> at
> org.apache.wicket.request.cycle.RequestCycle.processRequest(RequestCyc
> le.java:218)
> [wicket-core-6.9.1.jar:6.9.1]
> at
> org.apache.wicket.request.cycle.RequestCycle.processRequestAndDetach(R
> equestCycle.java:289)
> [wicket-core-6.9.1.jar:6.9.1]
> at
> org.apache.wicket.protocol.http.WicketFilter.processRequestCycle(Wicke
> tFilter.java:259)
> [wicket-core-6.9.1.jar:6.9.1]
> at
> org.apache.wicket.protocol.http.WicketFilter.processRequest(WicketFilt
> er.java:201)
> [wicket-core-6.9.1.jar:6.9.1]
> at
> org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.jav
> a:282)
> [wicket-core-6.9.1.jar:6.9.1]
>
> Here the RequestCycle is null:
> | if (setRenderingFlag)
> | {
> | // only process feedback panel when we are about to
> | be
> rendered.
> | // setRenderingFlag is false in case prepareForRender
> | is
> called only to build component
> | // hierarchy (i.e. in
> BookmarkableListenerInterfaceRequestTarget).
> | // prepareForRender(true) is always called before the
> actual rendering is done so
> | // that's where feedback panels gather the messages
> |
> | List<Component> feedbacks =
> getRequestCycle().getMetaData(FEEDBACK_LIST);
>
> To me it seems like I've got two different problems here:
>
> - the component cannot be rendered because I'm doing something
> fundamentally wrong, thus I'm not getting the expected output
>
> - after the mock-RequestCycle's done with its work, there's no
> RequestCycle set anymore, thus I cannot render the reply
>
>
> I understand that my problem may be rather specific. And since this is
> webservice that is already in use, I cannot just rewrite it
> completely. Thus I would greatly appreciate any hint how i could
> accomplish what the old code used to do before the Wicket upgrade?
>
> Cheers,
>
> M'bert
>
> --
> ----------- / http://herbert.the-little-red-haired-girl.org /
> -------------
> =+=
> Pilot: Call me a fuel truck.
> Tower: You're a fuel truck.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Rendering a component into a String
Posted by MartinoSuperman <ma...@live.nl>.
What I do in solving such problems, is making my own custom component class
in Java, in which extension takes place.
Example:
I wanted to get text out of a TextField.
Example code:
TextField<String> tfExample = new TextField<String>("name", Model.of*""))
This example code generates an empty text field.
It is easier to make your own textfield that extends TextField<String>
Here:
public class OpenTextField extends TextField<String>
{
public OpenTextField(String id, String text)
{
super(id);
....
Etc.
}
Here you make your own setText and getText. Then, you do not have to convert
to or back from Model again. That is much easier!
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Rendering-a-component-into-a-String-tp4662391p4662490.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Rendering a component into a String
Posted by Martin Dietze <di...@fh-wedel.de>.
On Wed, November 13, 2013, Martin Grigorov wrote:
> See the source of
> http://www.wicket-library.com/wicket-examples-6.0.x/mailtemplate/?2 example
In short: instanciate my component, put it into a
ComponentRenderer, be happy. That was astonishingly simple :)
Cheers,
M'bert
--
----------- / http://herbert.the-little-red-haired-girl.org / -------------
=+=
Steht ein Bratscher vor 'ner Kneipe.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Rendering a component into a String
Posted by Martin Grigorov <mg...@apache.org>.
Hi,
See the source of
http://www.wicket-library.com/wicket-examples-6.0.x/mailtemplate/?2 example
On Wed, Nov 13, 2013 at 3:04 PM, Martin Dietze <di...@fh-wedel.de> wrote:
> In a legacy project I've inherited I've got a piece of code that
> no longer works since the project was upgraded from Wicket 1.4 to
> Wicket 6.
>
> It's about rendering a component (a Wicket panel) into a string
> in order to return it wrapped into a webservice reply.
>
> The webservice is based on Wicket, too. The webservice is based
> on a Javascript handshake - the client calls the service using a
> token connecting the user to his current session he has on the
> application, the service replies are rendered into an iframe and
> deliver their data through postMessage.
>
> Thus, when rendering a reply, I am basically rendering a Wicket
> page within the context of my session.
>
> Now one of my API's calls requires me to render a Wicket panel
> into a String, which is then wrapped into JSON as part of the
> respective call's reply.
>
> The legacy code used to do this roughly like this (changes for
> using the Wicket 6 API were applied, but this nevertheless never
> worked):
>
> - create a mock RequestCycle by creating a MockHttpSession, a
> MockHttpServletRequest and a MockHttpServletResponse, glue
> this all together to obtain a ServletWebRequest and a
> BufferedWebResponse and finaly use use Application.createRequestCycle()
> to create the RequestCycle object
>
> - the component wrapped into a ComponentRenderingRequestHandler
>
> - then this code is executed:
>
> | try {
> | requestCycle.scheduleRequestHandlerAfterCurrent(requestHandler);
> | try {
> | if ( !requestCycle.processRequestAndDetach() ) {
> | requestCycle.scheduleRequestHandlerAfterCurrent(new
> ErrorCodeRequestHandler((HttpServletResponse.SC_NOT_FOUND));
> | }
> | } finally {
> | requestCycle.getResponse().close();
> | }
> | return requestCycle.getResponse().toString();
> | } finally {
> | requestCycle.detach();
> | }
>
> I must admit I could not have written this myself :)
>
> Now when running this code, I run into two different
> exceptions:
>
> org.apache.wicket.WicketRuntimeException: Exception in rendering
> component: [Profile [Component id = profile]]
> at
> org.apache.wicket.Component.internalRenderComponent(Component.java:2576)
> [wicket-core-6.9.1.jar:6.9.1]
> at
> org.apache.wicket.MarkupContainer.onRender(MarkupContainer.java:1493)
> ~[wicket-core-6.9.1.jar:6.9.1]
> at org.apache.wicket.Component.internalRender(Component.java:2379)
> [wicket-core-6.9.1.jar:6.9.1]
> at org.apache.wicket.Component.render(Component.java:2307)
> [wicket-core-6.9.1.jar:6.9.1]
> [...]
> Caused by: java.lang.NullPointerException: null
> at
> org.apache.wicket.markup.html.internal.Enclosure.isVisible(Enclosure.java:143)
> ~[wicket-core-6.9.1.jar:6.9.1]
> at
> org.apache.wicket.Component.determineVisibility(Component.java:4363)
> [wicket-core-6.9.1.jar:6.9.1]
> at
> org.apache.wicket.Component.internalBeforeRender(Component.java:916)
> [wicket-core-6.9.1.jar:6.9.1]
> at org.apache.wicket.Component.beforeRender(Component.java:991)
> [wicket-core-6.9.1.jar:6.9.1]
> at
> org.apache.wicket.Component.internalPrepareForRender(Component.java:2214)
> [wicket-core-6.9.1.jar:6.9.1]
> at org.apache.wicket.Component.render(Component.java:2303)
> [wicket-core-6.9.1.jar:6.9.1]
> at
> org.apache.wicket.MarkupContainer.renderNext(MarkupContainer.java:1390)
> ~[wicket-core-6.9.1.jar:6.9.1]
> at
> org.apache.wicket.MarkupContainer.renderAll(MarkupContainer.java:1554)
> ~[wicket-core-6.9.1.jar:6.9.1]
> at
> org.apache.wicket.MarkupContainer.renderComponentTagBody(MarkupContainer.java:1529)
> ~[wicket-core-6.9.1.jar:6.9.1]
> at
> org.apache.wicket.MarkupContainer.onComponentTagBody(MarkupContainer.java:1484)
> ~[wicket-core-6.9.1.jar:6.9.1]
> at
> org.apache.wicket.markup.html.panel.DefaultMarkupSourcingStrategy.onComponentTagBody(DefaultMarkupSourcingStrategy.java:71)
> ~[wicket-core-6.9.1.jar:6.9.1]
> at
> org.apache.wicket.Component.internalRenderComponent(Component.java:2549)
> [wicket-core-6.9.1.jar:6.9.1]
>
> The enclosure's child component is null, as we see here:
> | @Override
> | public boolean isVisible()
> | {
> | return childComponent.determineVisibility() &&
> super.isVisible();
> | }
>
> Below that exception I find the markup of a stack trace page in my logs.
> Below that markup I get another stack trace:
>
> java.lang.NullPointerException: null
> at
> org.apache.wicket.Component.internalPrepareForRender(Component.java:2224)
> ~[wicket-core-6.9.1.jar:6.9.1]
> at org.apache.wicket.Page.internalPrepareForRender(Page.java:241)
> ~[wicket-core-6.9.1.jar:6.9.1]
> at org.apache.wicket.Component.render(Component.java:2303)
> ~[wicket-core-6.9.1.jar:6.9.1]
> at org.apache.wicket.Page.renderPage(Page.java:1010)
> ~[wicket-core-6.9.1.jar:6.9.1]
> at
> org.apache.wicket.request.handler.render.WebPageRenderer.renderPage(WebPageRenderer.java:121)
> ~[wicket-core-6.9.1.jar:6.9.1]
> at
> org.apache.wicket.request.handler.render.WebPageRenderer.respond(WebPageRenderer.java:271)
> ~[wicket-core-6.9.1.jar:6.9.1]
> at
> org.apache.wicket.core.request.handler.RenderPageRequestHandler.respond(RenderPageRequestHandler.java:165)
> ~[wicket-core-6.9.1.jar:6.9.1]
> at
> org.apache.wicket.request.cycle.RequestCycle$HandlerExecutor.respond(RequestCycle.java:861)
> ~[wicket-core-6.9.1.jar:6.9.1]
> at
> org.apache.wicket.request.RequestHandlerStack.execute(RequestHandlerStack.java:64)
> ~[wicket-request-6.9.1.jar:6.9.1]
> at
> org.apache.wicket.request.cycle.RequestCycle.execute(RequestCycle.java:261)
> [wicket-core-6.9.1.jar:6.9.1]
> at
> org.apache.wicket.request.cycle.RequestCycle.processRequest(RequestCycle.java:218)
> [wicket-core-6.9.1.jar:6.9.1]
> at
> org.apache.wicket.request.cycle.RequestCycle.processRequestAndDetach(RequestCycle.java:289)
> [wicket-core-6.9.1.jar:6.9.1]
> at
> org.apache.wicket.protocol.http.WicketFilter.processRequestCycle(WicketFilter.java:259)
> [wicket-core-6.9.1.jar:6.9.1]
> at
> org.apache.wicket.protocol.http.WicketFilter.processRequest(WicketFilter.java:201)
> [wicket-core-6.9.1.jar:6.9.1]
> at
> org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:282)
> [wicket-core-6.9.1.jar:6.9.1]
>
> Here the RequestCycle is null:
> | if (setRenderingFlag)
> | {
> | // only process feedback panel when we are about to be
> rendered.
> | // setRenderingFlag is false in case prepareForRender is
> called only to build component
> | // hierarchy (i.e. in
> BookmarkableListenerInterfaceRequestTarget).
> | // prepareForRender(true) is always called before the
> actual rendering is done so
> | // that's where feedback panels gather the messages
> |
> | List<Component> feedbacks =
> getRequestCycle().getMetaData(FEEDBACK_LIST);
>
> To me it seems like I've got two different problems here:
>
> - the component cannot be rendered because I'm doing something
> fundamentally wrong, thus I'm not getting the expected output
>
> - after the mock-RequestCycle's done with its work, there's no
> RequestCycle set anymore, thus I cannot render the reply
>
>
> I understand that my problem may be rather specific. And since
> this is webservice that is already in use, I cannot just rewrite
> it completely. Thus I would greatly appreciate any hint how i could
> accomplish what the old code used to do before the Wicket upgrade?
>
> Cheers,
>
> M'bert
>
> --
> ----------- / http://herbert.the-little-red-haired-girl.org /
> -------------
> =+=
> Pilot: Call me a fuel truck.
> Tower: You're a fuel truck.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>