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 <[email protected]> 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: [email protected] For additional commands, e-mail: [email protected]
