You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by "J.-F. Rompre" <jr...@gmail.com> on 2009/05/27 21:53:21 UTC

How do I reuse a rendered string, i.e. render once and past in multiple locations, e.g. paging nav at top and bottom?

 I am trying to do something that should be easy to do, and may already be
 available from the API (I am still usin 1.3.5).

 How can one duplicate rendered strings?

 In other words, I am trying to render once but copy a number of times for
 better performance - e.g., putting a page navigator both at the top and
 bottom of the list (the bottom is simply a label generated from copying the
 rendered top one) or something more complex such as a calendar.

 I tried using IBehavior.onRendered to copy getResponse.toString() for later
 reuse, but myComponent.renderComponent() throws IllegalStateException: Page
 not found - even though I am adding the component to a panel as instructed
 by Component.renderComponent() - any ideas? My code is below.

 I also thought of overriding one of the rendering methods to write directly
 to the response, but Component.renderXXX() methods are all final - there
 has to be a way to do this simply.

 Any ideas?

 Thanks!
 JF

 The containing panel java (groovy) code - 'ppn' is the component we want to
 render only once
 .....//ProductPanel
 //...
        productsContainer.add( products )
         ProductsPagingNavigator ppn = new ProductsPagingNavigator(
 "productsPagerTop", products)
         ppn.add( new MakeRenderedStringBehavior())

        productsContainer.add(  ppn)
        ppn.renderComponent()       //THOWS 'Page not found..." exc.
                   //save the rendering for reuse
        CharSequence ppnOut = ppn.getRendered()
                  //reuse it here
        productsContainer.add new Label( "productsPagerBottom", ppnOut)
 //....

 //***********************************
 The Behavior code attached to ppn above:
 .....// MakeRenderedStringBehavior
     //...
    public void onRendered(final Component component)
    {
  //....
            //  Copy the rendering if this component can store it..
            CharSequence output = response.toString();
            if ( component instanceof IRenderedString )
                ((IRenderedString )component ).setRendered( output);
            webResponse.write(output);
        }
 //....
 //*************************************
 The containing ProductPanel markup:
 <wicket:panel
 ....
 <div class="Products" wicket:id="products" id=""
    <div wicket:id="productsPagerTop" class="Navigation"</div <!--
 rendered --
    <ul
        <li wicket:id="productsList" id=""
             ...
        </div</li
    </ul
    <div wicket:id="productsPagerBottom" class="Navigation"</div <!--
 pasted in--
 </div
 </wicket:panel

Re: How do I reuse a rendered string, i.e. render once and past in multiple locations, e.g. paging nav at top and bottom?

Posted by Jeremy Thomerson <je...@wickettraining.com>.
If you're optimizing for optimization's sake, spend your time
optimizing where it is worth optimizing.

--
Jeremy Thomerson
http://www.wickettraining.com




On Wed, May 27, 2009 at 6:04 PM, J.-F. Rompre <jr...@gmail.com> wrote:
> I am optimizing for optimizing's sake - is there built-in efficiency that
> prevents duplicate rendering for component instances of the same type with
> different markup ids?
>
> Thanks,
>
> JF
>
> On Wed, May 27, 2009 at 6:04 PM, Martijn Dashorst <
> martijn.dashorst@gmail.com> wrote:
>
>> You don't. Did a profiler tell you that this is a hotspot? Or are you
>> optimizing for optimizing's sake?
>>
>> Martijn
>>
>> On Wed, May 27, 2009 at 9:53 PM, J.-F. Rompre <jr...@gmail.com> wrote:
>> >  I am trying to do something that should be easy to do, and may already
>> be
>> >  available from the API (I am still usin 1.3.5).
>> >
>> >  How can one duplicate rendered strings?
>> >
>> >  In other words, I am trying to render once but copy a number of times
>> for
>> >  better performance - e.g., putting a page navigator both at the top and
>> >  bottom of the list (the bottom is simply a label generated from copying
>> the
>> >  rendered top one) or something more complex such as a calendar.
>> >
>> >  I tried using IBehavior.onRendered to copy getResponse.toString() for
>> later
>> >  reuse, but myComponent.renderComponent() throws IllegalStateException:
>> Page
>> >  not found - even though I am adding the component to a panel as
>> instructed
>> >  by Component.renderComponent() - any ideas? My code is below.
>> >
>> >  I also thought of overriding one of the rendering methods to write
>> directly
>> >  to the response, but Component.renderXXX() methods are all final - there
>> >  has to be a way to do this simply.
>> >
>> >  Any ideas?
>> >
>> >  Thanks!
>> >  JF
>> >
>> >  The containing panel java (groovy) code - 'ppn' is the component we want
>> to
>> >  render only once
>> >  .....//ProductPanel
>> >  //...
>> >        productsContainer.add( products )
>> >         ProductsPagingNavigator ppn = new ProductsPagingNavigator(
>> >  "productsPagerTop", products)
>> >         ppn.add( new MakeRenderedStringBehavior())
>> >
>> >        productsContainer.add(  ppn)
>> >        ppn.renderComponent()       //THOWS 'Page not found..." exc.
>> >                   //save the rendering for reuse
>> >        CharSequence ppnOut = ppn.getRendered()
>> >                  //reuse it here
>> >        productsContainer.add new Label( "productsPagerBottom", ppnOut)
>> >  //....
>> >
>> >  //***********************************
>> >  The Behavior code attached to ppn above:
>> >  .....// MakeRenderedStringBehavior
>> >     //...
>> >    public void onRendered(final Component component)
>> >    {
>> >  //....
>> >            //  Copy the rendering if this component can store it..
>> >            CharSequence output = response.toString();
>> >            if ( component instanceof IRenderedString )
>> >                ((IRenderedString )component ).setRendered( output);
>> >            webResponse.write(output);
>> >        }
>> >  //....
>> >  //*************************************
>> >  The containing ProductPanel markup:
>> >  <wicket:panel
>> >  ....
>> >  <div class="Products" wicket:id="products" id=""
>> >    <div wicket:id="productsPagerTop" class="Navigation"</div <!--
>> >  rendered --
>> >    <ul
>> >        <li wicket:id="productsList" id=""
>> >             ...
>> >        </div</li
>> >    </ul
>> >    <div wicket:id="productsPagerBottom" class="Navigation"</div <!--
>> >  pasted in--
>> >  </div
>> >  </wicket:panel
>> >
>>
>>
>>
>> --
>> Become a Wicket expert, learn from the best: http://wicketinaction.com
>> Apache Wicket 1.3.5 is released
>> Get it now: http://www.apache.org/dyn/closer.cgi/wicket/1.3.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>
>
> --
> JF
> "Borrow money from pessimists - they don't expect it back." -- Steven Wright
>

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


Re: How do I reuse a rendered string, i.e. render once and past in multiple locations, e.g. paging nav at top and bottom?

Posted by "J.-F. Rompre" <jr...@gmail.com>.
I am optimizing for optimizing's sake - is there built-in efficiency that
prevents duplicate rendering for component instances of the same type with
different markup ids?

Thanks,

JF

On Wed, May 27, 2009 at 6:04 PM, Martijn Dashorst <
martijn.dashorst@gmail.com> wrote:

> You don't. Did a profiler tell you that this is a hotspot? Or are you
> optimizing for optimizing's sake?
>
> Martijn
>
> On Wed, May 27, 2009 at 9:53 PM, J.-F. Rompre <jr...@gmail.com> wrote:
> >  I am trying to do something that should be easy to do, and may already
> be
> >  available from the API (I am still usin 1.3.5).
> >
> >  How can one duplicate rendered strings?
> >
> >  In other words, I am trying to render once but copy a number of times
> for
> >  better performance - e.g., putting a page navigator both at the top and
> >  bottom of the list (the bottom is simply a label generated from copying
> the
> >  rendered top one) or something more complex such as a calendar.
> >
> >  I tried using IBehavior.onRendered to copy getResponse.toString() for
> later
> >  reuse, but myComponent.renderComponent() throws IllegalStateException:
> Page
> >  not found - even though I am adding the component to a panel as
> instructed
> >  by Component.renderComponent() - any ideas? My code is below.
> >
> >  I also thought of overriding one of the rendering methods to write
> directly
> >  to the response, but Component.renderXXX() methods are all final - there
> >  has to be a way to do this simply.
> >
> >  Any ideas?
> >
> >  Thanks!
> >  JF
> >
> >  The containing panel java (groovy) code - 'ppn' is the component we want
> to
> >  render only once
> >  .....//ProductPanel
> >  //...
> >        productsContainer.add( products )
> >         ProductsPagingNavigator ppn = new ProductsPagingNavigator(
> >  "productsPagerTop", products)
> >         ppn.add( new MakeRenderedStringBehavior())
> >
> >        productsContainer.add(  ppn)
> >        ppn.renderComponent()       //THOWS 'Page not found..." exc.
> >                   //save the rendering for reuse
> >        CharSequence ppnOut = ppn.getRendered()
> >                  //reuse it here
> >        productsContainer.add new Label( "productsPagerBottom", ppnOut)
> >  //....
> >
> >  //***********************************
> >  The Behavior code attached to ppn above:
> >  .....// MakeRenderedStringBehavior
> >     //...
> >    public void onRendered(final Component component)
> >    {
> >  //....
> >            //  Copy the rendering if this component can store it..
> >            CharSequence output = response.toString();
> >            if ( component instanceof IRenderedString )
> >                ((IRenderedString )component ).setRendered( output);
> >            webResponse.write(output);
> >        }
> >  //....
> >  //*************************************
> >  The containing ProductPanel markup:
> >  <wicket:panel
> >  ....
> >  <div class="Products" wicket:id="products" id=""
> >    <div wicket:id="productsPagerTop" class="Navigation"</div <!--
> >  rendered --
> >    <ul
> >        <li wicket:id="productsList" id=""
> >             ...
> >        </div</li
> >    </ul
> >    <div wicket:id="productsPagerBottom" class="Navigation"</div <!--
> >  pasted in--
> >  </div
> >  </wicket:panel
> >
>
>
>
> --
> Become a Wicket expert, learn from the best: http://wicketinaction.com
> Apache Wicket 1.3.5 is released
> Get it now: http://www.apache.org/dyn/closer.cgi/wicket/1.3.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>


-- 
JF
"Borrow money from pessimists - they don't expect it back." -- Steven Wright

Re: How do I reuse a rendered string, i.e. render once and past in multiple locations, e.g. paging nav at top and bottom?

Posted by Martijn Dashorst <ma...@gmail.com>.
You don't. Did a profiler tell you that this is a hotspot? Or are you
optimizing for optimizing's sake?

Martijn

On Wed, May 27, 2009 at 9:53 PM, J.-F. Rompre <jr...@gmail.com> wrote:
>  I am trying to do something that should be easy to do, and may already be
>  available from the API (I am still usin 1.3.5).
>
>  How can one duplicate rendered strings?
>
>  In other words, I am trying to render once but copy a number of times for
>  better performance - e.g., putting a page navigator both at the top and
>  bottom of the list (the bottom is simply a label generated from copying the
>  rendered top one) or something more complex such as a calendar.
>
>  I tried using IBehavior.onRendered to copy getResponse.toString() for later
>  reuse, but myComponent.renderComponent() throws IllegalStateException: Page
>  not found - even though I am adding the component to a panel as instructed
>  by Component.renderComponent() - any ideas? My code is below.
>
>  I also thought of overriding one of the rendering methods to write directly
>  to the response, but Component.renderXXX() methods are all final - there
>  has to be a way to do this simply.
>
>  Any ideas?
>
>  Thanks!
>  JF
>
>  The containing panel java (groovy) code - 'ppn' is the component we want to
>  render only once
>  .....//ProductPanel
>  //...
>        productsContainer.add( products )
>         ProductsPagingNavigator ppn = new ProductsPagingNavigator(
>  "productsPagerTop", products)
>         ppn.add( new MakeRenderedStringBehavior())
>
>        productsContainer.add(  ppn)
>        ppn.renderComponent()       //THOWS 'Page not found..." exc.
>                   //save the rendering for reuse
>        CharSequence ppnOut = ppn.getRendered()
>                  //reuse it here
>        productsContainer.add new Label( "productsPagerBottom", ppnOut)
>  //....
>
>  //***********************************
>  The Behavior code attached to ppn above:
>  .....// MakeRenderedStringBehavior
>     //...
>    public void onRendered(final Component component)
>    {
>  //....
>            //  Copy the rendering if this component can store it..
>            CharSequence output = response.toString();
>            if ( component instanceof IRenderedString )
>                ((IRenderedString )component ).setRendered( output);
>            webResponse.write(output);
>        }
>  //....
>  //*************************************
>  The containing ProductPanel markup:
>  <wicket:panel
>  ....
>  <div class="Products" wicket:id="products" id=""
>    <div wicket:id="productsPagerTop" class="Navigation"</div <!--
>  rendered --
>    <ul
>        <li wicket:id="productsList" id=""
>             ...
>        </div</li
>    </ul
>    <div wicket:id="productsPagerBottom" class="Navigation"</div <!--
>  pasted in--
>  </div
>  </wicket:panel
>



-- 
Become a Wicket expert, learn from the best: http://wicketinaction.com
Apache Wicket 1.3.5 is released
Get it now: http://www.apache.org/dyn/closer.cgi/wicket/1.3.

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


Re: How do I reuse a rendered string, i.e. render once and past in multiple locations, e.g. paging nav at top and bottom?

Posted by "J.-F. Rompre" <jr...@gmail.com>.
Thanks Igor for the straight answer - much appreciated.

Thanks,

JF




On Wed, May 27, 2009 at 9:59 PM, Igor Vaynberg <ig...@gmail.com>wrote:

> no it is not possible and does not make sense to do so.
>
> imagine you have a panel that renders <div id="1"><div id="2"></div></div>
>
> not only would you have to rewrite the id of the top tag, but also of
> the inner tags. this becomes even more complicated if components
> output header contributors, eg javascript, that depends on those ids.
>
> if you are instantiating components with the same state then you
> should simply connect them all to the same state via models so the
> state is reused and does not present overhead.
>
> makes sense?
>
> -igor
>
> On Wed, May 27, 2009 at 5:03 PM, J.-F. Rompre <jr...@gmail.com> wrote:
> > OK, thanks Martjin and Jeremy - I think mentioning performance was a
> mistake
> > on my part..let me try again.
> >
> > I am not trying to couple different components, only to reuse what I know
> is
> > never going to change within the same rendering - actually, avoiding the
> use
> > of multiple component instances of the same subtype where a single
> instance
> > would suffice.
> >
> > My question is: Is it possible to capture a rendered string for reuse? In
> > other words, if I have a component subtype that I am currently
> instantiating
> > multiple times with exactly the same state (therefore the output is
> exactly
> > the same), is it possible to render it once and once only and reuse the
> > string from that rendering within the same container or page?
> >
> > At this stage I am only trying to know how to do something instead of why
> > (optimization or other reason, such as saving markup coding, or some
> other
> > reason). I went through the source and searched on forums as well to find
> > out, but didn't.
> >
> > My apologies if that question has been answered elsewhere - please let me
> > know where I can look.
> >
> > Thanks,
> >
> > JF
> >
> > On Wed, May 27, 2009 at 6:33 PM, Jeremy Thomerson <
> jeremy@wickettraining.com
> >> wrote:
> >
> >> The real question that has been asked time and time again on this list
> >> when such a question is received is this:
> >>
> >> WHY?  It's premature (and almost certainly unnecessary) optimization.
> >> Doing it needlessly couples multiple components together - reducing
> >> reuse.
> >>
> >> As always, we are more than interested in seeing any results of
> >> performance analysis that you have done that says that this will
> >> reduce your page load time by any significant factor.
> >>
> >> --
> >> Jeremy Thomerson
> >> http://www.wickettraining.com
> >>
> >>
> >>
> >>
> >> On Wed, May 27, 2009 at 2:53 PM, J.-F. Rompre <jr...@gmail.com>
> wrote:
> >> >  I am trying to do something that should be easy to do, and may
> already
> >> be
> >> >  available from the API (I am still usin 1.3.5).
> >> >
> >> >  How can one duplicate rendered strings?
> >> >
> >> >  In other words, I am trying to render once but copy a number of times
> >> for
> >> >  better performance - e.g., putting a page navigator both at the top
> and
> >> >  bottom of the list (the bottom is simply a label generated from
> copying
> >> the
> >> >  rendered top one) or something more complex such as a calendar.
> >> >
> >> >  I tried using IBehavior.onRendered to copy getResponse.toString() for
> >> later
> >> >  reuse, but myComponent.renderComponent() throws
> IllegalStateException:
> >> Page
> >> >  not found - even though I am adding the component to a panel as
> >> instructed
> >> >  by Component.renderComponent() - any ideas? My code is below.
> >> >
> >> >  I also thought of overriding one of the rendering methods to write
> >> directly
> >> >  to the response, but Component.renderXXX() methods are all final -
> there
> >> >  has to be a way to do this simply.
> >> >
> >> >  Any ideas?
> >> >
> >> >  Thanks!
> >> >  JF
> >> >
> >> >  The containing panel java (groovy) code - 'ppn' is the component we
> want
> >> to
> >> >  render only once
> >> >  .....//ProductPanel
> >> >  //...
> >> >        productsContainer.add( products )
> >> >         ProductsPagingNavigator ppn = new ProductsPagingNavigator(
> >> >  "productsPagerTop", products)
> >> >         ppn.add( new MakeRenderedStringBehavior())
> >> >
> >> >        productsContainer.add(  ppn)
> >> >        ppn.renderComponent()       //THOWS 'Page not found..." exc.
> >> >                   //save the rendering for reuse
> >> >        CharSequence ppnOut = ppn.getRendered()
> >> >                  //reuse it here
> >> >        productsContainer.add new Label( "productsPagerBottom", ppnOut)
> >> >  //....
> >> >
> >> >  //***********************************
> >> >  The Behavior code attached to ppn above:
> >> >  .....// MakeRenderedStringBehavior
> >> >     //...
> >> >    public void onRendered(final Component component)
> >> >    {
> >> >  //....
> >> >            //  Copy the rendering if this component can store it..
> >> >            CharSequence output = response.toString();
> >> >            if ( component instanceof IRenderedString )
> >> >                ((IRenderedString )component ).setRendered( output);
> >> >            webResponse.write(output);
> >> >        }
> >> >  //....
> >> >  //*************************************
> >> >  The containing ProductPanel markup:
> >> >  <wicket:panel
> >> >  ....
> >> >  <div class="Products" wicket:id="products" id=""
> >> >    <div wicket:id="productsPagerTop" class="Navigation"</div <!--
> >> >  rendered --
> >> >    <ul
> >> >        <li wicket:id="productsList" id=""
> >> >             ...
> >> >        </div</li
> >> >    </ul
> >> >    <div wicket:id="productsPagerBottom" class="Navigation"</div <!--
> >> >  pasted in--
> >> >  </div
> >> >  </wicket:panel
> >> >
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> >> For additional commands, e-mail: users-help@wicket.apache.org
> >>
> >>
> >
> >
> > --
> > JF
> > "Half the people you know are below average." -- Steven Wright
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: How do I reuse a rendered string, i.e. render once and past in multiple locations, e.g. paging nav at top and bottom?

Posted by Igor Vaynberg <ig...@gmail.com>.
no it is not possible and does not make sense to do so.

imagine you have a panel that renders <div id="1"><div id="2"></div></div>

not only would you have to rewrite the id of the top tag, but also of
the inner tags. this becomes even more complicated if components
output header contributors, eg javascript, that depends on those ids.

if you are instantiating components with the same state then you
should simply connect them all to the same state via models so the
state is reused and does not present overhead.

makes sense?

-igor

On Wed, May 27, 2009 at 5:03 PM, J.-F. Rompre <jr...@gmail.com> wrote:
> OK, thanks Martjin and Jeremy - I think mentioning performance was a mistake
> on my part..let me try again.
>
> I am not trying to couple different components, only to reuse what I know is
> never going to change within the same rendering - actually, avoiding the use
> of multiple component instances of the same subtype where a single instance
> would suffice.
>
> My question is: Is it possible to capture a rendered string for reuse? In
> other words, if I have a component subtype that I am currently instantiating
> multiple times with exactly the same state (therefore the output is exactly
> the same), is it possible to render it once and once only and reuse the
> string from that rendering within the same container or page?
>
> At this stage I am only trying to know how to do something instead of why
> (optimization or other reason, such as saving markup coding, or some other
> reason). I went through the source and searched on forums as well to find
> out, but didn't.
>
> My apologies if that question has been answered elsewhere - please let me
> know where I can look.
>
> Thanks,
>
> JF
>
> On Wed, May 27, 2009 at 6:33 PM, Jeremy Thomerson <jeremy@wickettraining.com
>> wrote:
>
>> The real question that has been asked time and time again on this list
>> when such a question is received is this:
>>
>> WHY?  It's premature (and almost certainly unnecessary) optimization.
>> Doing it needlessly couples multiple components together - reducing
>> reuse.
>>
>> As always, we are more than interested in seeing any results of
>> performance analysis that you have done that says that this will
>> reduce your page load time by any significant factor.
>>
>> --
>> Jeremy Thomerson
>> http://www.wickettraining.com
>>
>>
>>
>>
>> On Wed, May 27, 2009 at 2:53 PM, J.-F. Rompre <jr...@gmail.com> wrote:
>> >  I am trying to do something that should be easy to do, and may already
>> be
>> >  available from the API (I am still usin 1.3.5).
>> >
>> >  How can one duplicate rendered strings?
>> >
>> >  In other words, I am trying to render once but copy a number of times
>> for
>> >  better performance - e.g., putting a page navigator both at the top and
>> >  bottom of the list (the bottom is simply a label generated from copying
>> the
>> >  rendered top one) or something more complex such as a calendar.
>> >
>> >  I tried using IBehavior.onRendered to copy getResponse.toString() for
>> later
>> >  reuse, but myComponent.renderComponent() throws IllegalStateException:
>> Page
>> >  not found - even though I am adding the component to a panel as
>> instructed
>> >  by Component.renderComponent() - any ideas? My code is below.
>> >
>> >  I also thought of overriding one of the rendering methods to write
>> directly
>> >  to the response, but Component.renderXXX() methods are all final - there
>> >  has to be a way to do this simply.
>> >
>> >  Any ideas?
>> >
>> >  Thanks!
>> >  JF
>> >
>> >  The containing panel java (groovy) code - 'ppn' is the component we want
>> to
>> >  render only once
>> >  .....//ProductPanel
>> >  //...
>> >        productsContainer.add( products )
>> >         ProductsPagingNavigator ppn = new ProductsPagingNavigator(
>> >  "productsPagerTop", products)
>> >         ppn.add( new MakeRenderedStringBehavior())
>> >
>> >        productsContainer.add(  ppn)
>> >        ppn.renderComponent()       //THOWS 'Page not found..." exc.
>> >                   //save the rendering for reuse
>> >        CharSequence ppnOut = ppn.getRendered()
>> >                  //reuse it here
>> >        productsContainer.add new Label( "productsPagerBottom", ppnOut)
>> >  //....
>> >
>> >  //***********************************
>> >  The Behavior code attached to ppn above:
>> >  .....// MakeRenderedStringBehavior
>> >     //...
>> >    public void onRendered(final Component component)
>> >    {
>> >  //....
>> >            //  Copy the rendering if this component can store it..
>> >            CharSequence output = response.toString();
>> >            if ( component instanceof IRenderedString )
>> >                ((IRenderedString )component ).setRendered( output);
>> >            webResponse.write(output);
>> >        }
>> >  //....
>> >  //*************************************
>> >  The containing ProductPanel markup:
>> >  <wicket:panel
>> >  ....
>> >  <div class="Products" wicket:id="products" id=""
>> >    <div wicket:id="productsPagerTop" class="Navigation"</div <!--
>> >  rendered --
>> >    <ul
>> >        <li wicket:id="productsList" id=""
>> >             ...
>> >        </div</li
>> >    </ul
>> >    <div wicket:id="productsPagerBottom" class="Navigation"</div <!--
>> >  pasted in--
>> >  </div
>> >  </wicket:panel
>> >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>
>
> --
> JF
> "Half the people you know are below average." -- Steven Wright
>

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


Re: How do I reuse a rendered string, i.e. render once and past in multiple locations, e.g. paging nav at top and bottom?

Posted by "J.-F. Rompre" <jr...@gmail.com>.
OK, thanks Martjin and Jeremy - I think mentioning performance was a mistake
on my part..let me try again.

I am not trying to couple different components, only to reuse what I know is
never going to change within the same rendering - actually, avoiding the use
of multiple component instances of the same subtype where a single instance
would suffice.

My question is: Is it possible to capture a rendered string for reuse? In
other words, if I have a component subtype that I am currently instantiating
multiple times with exactly the same state (therefore the output is exactly
the same), is it possible to render it once and once only and reuse the
string from that rendering within the same container or page?

At this stage I am only trying to know how to do something instead of why
(optimization or other reason, such as saving markup coding, or some other
reason). I went through the source and searched on forums as well to find
out, but didn't.

My apologies if that question has been answered elsewhere - please let me
know where I can look.

Thanks,

JF

On Wed, May 27, 2009 at 6:33 PM, Jeremy Thomerson <jeremy@wickettraining.com
> wrote:

> The real question that has been asked time and time again on this list
> when such a question is received is this:
>
> WHY?  It's premature (and almost certainly unnecessary) optimization.
> Doing it needlessly couples multiple components together - reducing
> reuse.
>
> As always, we are more than interested in seeing any results of
> performance analysis that you have done that says that this will
> reduce your page load time by any significant factor.
>
> --
> Jeremy Thomerson
> http://www.wickettraining.com
>
>
>
>
> On Wed, May 27, 2009 at 2:53 PM, J.-F. Rompre <jr...@gmail.com> wrote:
> >  I am trying to do something that should be easy to do, and may already
> be
> >  available from the API (I am still usin 1.3.5).
> >
> >  How can one duplicate rendered strings?
> >
> >  In other words, I am trying to render once but copy a number of times
> for
> >  better performance - e.g., putting a page navigator both at the top and
> >  bottom of the list (the bottom is simply a label generated from copying
> the
> >  rendered top one) or something more complex such as a calendar.
> >
> >  I tried using IBehavior.onRendered to copy getResponse.toString() for
> later
> >  reuse, but myComponent.renderComponent() throws IllegalStateException:
> Page
> >  not found - even though I am adding the component to a panel as
> instructed
> >  by Component.renderComponent() - any ideas? My code is below.
> >
> >  I also thought of overriding one of the rendering methods to write
> directly
> >  to the response, but Component.renderXXX() methods are all final - there
> >  has to be a way to do this simply.
> >
> >  Any ideas?
> >
> >  Thanks!
> >  JF
> >
> >  The containing panel java (groovy) code - 'ppn' is the component we want
> to
> >  render only once
> >  .....//ProductPanel
> >  //...
> >        productsContainer.add( products )
> >         ProductsPagingNavigator ppn = new ProductsPagingNavigator(
> >  "productsPagerTop", products)
> >         ppn.add( new MakeRenderedStringBehavior())
> >
> >        productsContainer.add(  ppn)
> >        ppn.renderComponent()       //THOWS 'Page not found..." exc.
> >                   //save the rendering for reuse
> >        CharSequence ppnOut = ppn.getRendered()
> >                  //reuse it here
> >        productsContainer.add new Label( "productsPagerBottom", ppnOut)
> >  //....
> >
> >  //***********************************
> >  The Behavior code attached to ppn above:
> >  .....// MakeRenderedStringBehavior
> >     //...
> >    public void onRendered(final Component component)
> >    {
> >  //....
> >            //  Copy the rendering if this component can store it..
> >            CharSequence output = response.toString();
> >            if ( component instanceof IRenderedString )
> >                ((IRenderedString )component ).setRendered( output);
> >            webResponse.write(output);
> >        }
> >  //....
> >  //*************************************
> >  The containing ProductPanel markup:
> >  <wicket:panel
> >  ....
> >  <div class="Products" wicket:id="products" id=""
> >    <div wicket:id="productsPagerTop" class="Navigation"</div <!--
> >  rendered --
> >    <ul
> >        <li wicket:id="productsList" id=""
> >             ...
> >        </div</li
> >    </ul
> >    <div wicket:id="productsPagerBottom" class="Navigation"</div <!--
> >  pasted in--
> >  </div
> >  </wicket:panel
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>


-- 
JF
"Half the people you know are below average." -- Steven Wright

Re: How do I reuse a rendered string, i.e. render once and past in multiple locations, e.g. paging nav at top and bottom?

Posted by Jeremy Thomerson <je...@wickettraining.com>.
The real question that has been asked time and time again on this list
when such a question is received is this:

WHY?  It's premature (and almost certainly unnecessary) optimization.
Doing it needlessly couples multiple components together - reducing
reuse.

As always, we are more than interested in seeing any results of
performance analysis that you have done that says that this will
reduce your page load time by any significant factor.

--
Jeremy Thomerson
http://www.wickettraining.com




On Wed, May 27, 2009 at 2:53 PM, J.-F. Rompre <jr...@gmail.com> wrote:
>  I am trying to do something that should be easy to do, and may already be
>  available from the API (I am still usin 1.3.5).
>
>  How can one duplicate rendered strings?
>
>  In other words, I am trying to render once but copy a number of times for
>  better performance - e.g., putting a page navigator both at the top and
>  bottom of the list (the bottom is simply a label generated from copying the
>  rendered top one) or something more complex such as a calendar.
>
>  I tried using IBehavior.onRendered to copy getResponse.toString() for later
>  reuse, but myComponent.renderComponent() throws IllegalStateException: Page
>  not found - even though I am adding the component to a panel as instructed
>  by Component.renderComponent() - any ideas? My code is below.
>
>  I also thought of overriding one of the rendering methods to write directly
>  to the response, but Component.renderXXX() methods are all final - there
>  has to be a way to do this simply.
>
>  Any ideas?
>
>  Thanks!
>  JF
>
>  The containing panel java (groovy) code - 'ppn' is the component we want to
>  render only once
>  .....//ProductPanel
>  //...
>        productsContainer.add( products )
>         ProductsPagingNavigator ppn = new ProductsPagingNavigator(
>  "productsPagerTop", products)
>         ppn.add( new MakeRenderedStringBehavior())
>
>        productsContainer.add(  ppn)
>        ppn.renderComponent()       //THOWS 'Page not found..." exc.
>                   //save the rendering for reuse
>        CharSequence ppnOut = ppn.getRendered()
>                  //reuse it here
>        productsContainer.add new Label( "productsPagerBottom", ppnOut)
>  //....
>
>  //***********************************
>  The Behavior code attached to ppn above:
>  .....// MakeRenderedStringBehavior
>     //...
>    public void onRendered(final Component component)
>    {
>  //....
>            //  Copy the rendering if this component can store it..
>            CharSequence output = response.toString();
>            if ( component instanceof IRenderedString )
>                ((IRenderedString )component ).setRendered( output);
>            webResponse.write(output);
>        }
>  //....
>  //*************************************
>  The containing ProductPanel markup:
>  <wicket:panel
>  ....
>  <div class="Products" wicket:id="products" id=""
>    <div wicket:id="productsPagerTop" class="Navigation"</div <!--
>  rendered --
>    <ul
>        <li wicket:id="productsList" id=""
>             ...
>        </div</li
>    </ul
>    <div wicket:id="productsPagerBottom" class="Navigation"</div <!--
>  pasted in--
>  </div
>  </wicket:panel
>

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