RE: Rendering a component into a String

2013-11-21 Thread Mateusz Mieszkowski
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:mgrigo...@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 d...@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

Re: Rendering a component into a String

2013-11-21 Thread Martin Grigorov
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 
mmieszkow...@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:mgrigo...@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 d...@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

RE: Rendering a component into a String

2013-11-21 Thread Mateusz Mieszkowski
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:mgrigo...@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  
mmieszkow...@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:mgrigo...@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 d...@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

Re: Rendering a component into a String

2013-11-21 Thread Martin Grigorov
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 
mmieszkow...@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:mgrigo...@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 
 mmieszkow...@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:mgrigo...@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 d...@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

RE: Rendering a component into a String

2013-11-21 Thread Mateusz Mieszkowski
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:mgrigo...@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  
mmieszkow...@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:mgrigo...@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  
 mmieszkow...@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:mgrigo...@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 d...@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

Re: Rendering a component into a String

2013-11-21 Thread Martin Grigorov
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 
mmieszkow...@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:mgrigo...@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 
 mmieszkow...@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:mgrigo...@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 
  mmieszkow...@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:mgrigo...@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 d...@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

Re: Rendering a component into a String

2013-11-18 Thread MartinoSuperman
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:

TextFieldString tfExample = new TextFieldString(name, Model.of*))

This example code generates an empty text field.

It is easier to make your own textfield that extends TextFieldString

Here:

public class OpenTextField extends TextFieldString
{
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-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: Rendering a component into a String

2013-11-13 Thread Martin Grigorov
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 d...@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)
 

Re: Rendering a component into a String

2013-11-13 Thread Martin Dietze
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-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org