wicket-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nick Pratt <nbpr...@gmail.com>
Subject Re: Behavior rendering
Date Fri, 09 May 2014 18:45:55 GMT
in the beforeRender() and afterRender(), is there anything better than
adding something like:

WebRequest request = (WebRequest) component.getRequest();
 boolean ajax = request.isAjax();
if( ajax )
{
 return;
}

prior to appending the additional markup?



On Fri, May 9, 2014 at 2:34 PM, Nick Pratt <nbpratt@gmail.com> wrote:

> I have a Behavior attached to a WebMarkupContainer with a bind() method as
> follows:
>
> @Override
> 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
> {
> @Override
>  public void beforeRender( Component component )
> {
> Response response = component.getResponse();
>
> response.write( "<div id=\"" );
> response.write( borderMarkupId ); // Generated from the bound component
> above
>  response.write( "\" class=\"popup\" style=\"display:none;\"><h1><span>"
> );
> response.write( headerTextModel.getObject() );
>  response.write( "</span><span class=\"close\"><a>X</a></span></h1>"
);
> }
>
> @Override
> 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
> generated/cached.
>
> 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?
>
> N
>

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