wicket-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nick Pratt <nbpr...@gmail.com>
Subject Behavior rendering
Date Fri, 09 May 2014 18:34:11 GMT
I have a Behavior attached to a WebMarkupContainer with a bind() method as

public void bind( Component component )
this.boundComponent = component;

component.setOutputMarkupId( true );
 component.setOutputMarkupPlaceholderTag( true );


component.add( new BorderBehaviour() );


this.borderMarkupId = component.getMarkupId() + "_brd";

class BorderBehaviour extends Behavior
 public void beforeRender( Component component )
Response response = component.getResponse();

response.write( "<div id=\"" );
response.write( borderMarkupId ); // Generated from the bound component
 response.write( "\" class=\"popup\" style=\"display:none;\"><h1><span>" );
response.write( headerTextModel.getObject() );
 response.write( "</span><span class=\"close\"><a>X</a></span></h1>"

public void afterRender( Component component )
 component.getResponse().write( "</div>" );

When a page is initially loaded, beforeRender() and afterRender() get
executed just fine.  If the user hits the browser reload button, everything
still works (these two functions get executed).  However, during an Ajax
triggered event, I end up with duplicate markup being appended to the bound
component (since these two methods above run again, but the Component
hierarchy isn't re-generated, thus multiple copies of the additional markup
are written to the stream).

I tried making the behavior temporary, and while that fixes the Ajax case,
it breaks in the "user-presses-reload-button" case - since the behavior,
now temporary, gets detached from the request after the initial render and
doesnt get rerun when the user requests a page that is already

How can I make this work for all three cases -
1. Page load
2. Page reload (same page ID)
3. Ajax

I noticed that the response in (3) is an AbstractAjaxResponse - is the only
way to fix this to run an instanceof check on the response type or is there
an alternate way?


  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message