Re: AbstractAjaxTimerBehavior causes exception

2009-11-11 Thread Ernesto Reinaldo Barreiro
Hi Chris,

Maybe it is because you are adding  the timer to the label and later on
replacing it is another component. Then the second AJAX round trip to the
page will look for the AbstractAjaxTimerBehavior associated to the message
component, but the new one does not have associated such a behavior. And you
do not need to replace the label component (just udpate it via AJAX): just
write a model that displays If you see this message wicket is properly
configured and running if count =0 and Test  + testCounter if 0.

Best,

Ernesto

On Wed, Nov 11, 2009 at 9:21 AM, Giambalvo, Christian 
christian.giamba...@excelsisnet.com wrote:

 Hi all,



 maybe i found a bug.

 Don't know if I'm doing something wrong.

 But it's a simple usecase.



 Following code produces an exception:



 public class HomePage extends WebPage {



private static final long serialVersionUID = 1L;



private static int testCounter = 0;



public HomePage(final PageParameters parameters) {



// Add the simplest type of label

final Label test = new Label(message, If you see this message
 wicket is properly configured and running);

test.add(new AbstractAjaxTimerBehavior(Duration.seconds(1))

{

@Override

protected void onTimer(AjaxRequestTarget target)

{

Label t2 = new Label(message, Test  + testCounter);

test.replaceWith(t2);

testCounter++;

target.addComponent(test);

}

});



add(test);

}

 }



 Exception:

 Root cause:

 java.lang.IllegalStateException: No Page found for component [Component
 id = message]
 at org.apache.wicket.Component.getPage(Component.java:1754)
 at org.apache.wicket.RequestCycle.urlFor(RequestCycle.java:872)
 at org.apache.wicket.Component.urlFor(Component.java:3286)
 at
 org.apache.wicket.behavior.AbstractAjaxBehavior.getCallbackUrl(AbstractA
 jaxBehavior.java:124)
 at
 org.apache.wicket.ajax.AbstractAjaxTimerBehavior.getCallbackScript(Abstr
 actAjaxTimerBehavior.java:127)
 at
 org.apache.wicket.ajax.AbstractAjaxTimerBehavior.getJsTimeoutCall(Abstra
 ctAjaxTimerBehavior.java:120)
 at
 org.apache.wicket.ajax.AbstractAjaxTimerBehavior.respond(AbstractAjaxTim
 erBehavior.java:163)
 at
 org.apache.wicket.ajax.AbstractDefaultAjaxBehavior.onRequest(AbstractDef
 aultAjaxBehavior.java:299)
 at
 org.apache.wicket.request.target.component.listener.BehaviorRequestTarge
 t.processEvents(BehaviorRequestTarget.java:119)
 at
 org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(Ab
 stractRequestCycleProcessor.java:92)
 at
 org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java
 :1250)
 at org.apache.wicket.RequestCycle.step(RequestCycle.java:1329)
 at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1428)
 at org.apache.wicket.RequestCycle.request(RequestCycle.java:545)
 at
 org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:468
 )
 at
 org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:
 301)
 at
 org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHan
 dler.java:1157)
 at
 org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
 at
 org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:2
 16)
 at
 org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
 at
 org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
 at
 org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
 at
 org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandler
 Collection.java:230)
 at
 org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.jav
 a:114)
 at
 org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
 at org.mortbay.jetty.Server.handle(Server.java:326)
 at
 org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:536)
 at
 org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConne
 ction.java:915)
 at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:539)
 at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
 at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:405)
 at
 org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:
 409)
 at
 org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java
 :582)



 Greets

 Chris




Re: AbstractAjaxTimerBehavior causes exception

2009-11-11 Thread Ernesto Reinaldo Barreiro
Following example works fine

public class TestCounter extends WebPage {

private int counter = 0;

private Label message;
/**
 *
 */
public TestCounter() {

message = new Label(message, new AbstractReadOnlyModelString(){

private static final long serialVersionUID = 1L;

public String getObject() {
counter++;
if(TestCounter.this.getCounter() == 0) {
return Hi!;
} else {
return I have been update  + getCounter();
}
};
});
message.setOutputMarkupId(true);
add(message);
message.add(new AbstractAjaxTimerBehavior(Duration.seconds(3)) {

private static final long serialVersionUID = 1L;

@Override
protected void onTimer(AjaxRequestTarget target) {
if(target != null) {
target.addComponent(message);
}
}
});
}

public int getCounter() {
return counter;
}
}

and

html xmlns:wicket=org.apache.wicket
body
span wicket:id=message/span
/body
/html

On Wed, Nov 11, 2009 at 9:43 AM, Giambalvo, Christian 
christian.giamba...@excelsisnet.com wrote:

 Btw, the exception is thrown on first call not on second round trip.


 -Ursprüngliche Nachricht-
 Von: Giambalvo, Christian [mailto:christian.giamba...@excelsisnet.com]
 Gesendet: Mittwoch, 11. November 2009 09:39
 An: users@wicket.apache.org
 Betreff: AW: AbstractAjaxTimerBehavior causes exception

 Hi Ernesto,

 the label was just an example.
 In my app i try to replace the navigation (you remember your suggestion
 with a timer?)
 The navigation is a panel. So recreate the whole panel and then try to
 replace it with the new one.
 This is where the AbstractAjaxTimerBehavior comes in.

 Greets Chris


 -Ursprüngliche Nachricht-
 Von: Ernesto Reinaldo Barreiro [mailto:reier...@gmail.com]
 Gesendet: Mittwoch, 11. November 2009 09:35
 An: users@wicket.apache.org
 Betreff: Re: AbstractAjaxTimerBehavior causes exception

 Hi Chris,

 Maybe it is because you are adding  the timer to the label and later on
 replacing it is another component. Then the second AJAX round trip to the
 page will look for the AbstractAjaxTimerBehavior associated to the
 message
 component, but the new one does not have associated such a behavior. And
 you
 do not need to replace the label component (just udpate it via AJAX): just
 write a model that displays If you see this message wicket is properly
 configured and running if count =0 and Test  + testCounter if 0.

 Best,

 Ernesto

 On Wed, Nov 11, 2009 at 9:21 AM, Giambalvo, Christian 
 christian.giamba...@excelsisnet.com wrote:

  Hi all,
 
 
 
  maybe i found a bug.
 
  Don't know if I'm doing something wrong.
 
  But it's a simple usecase.
 
 
 
  Following code produces an exception:
 
 
 
  public class HomePage extends WebPage {
 
 
 
 private static final long serialVersionUID = 1L;
 
 
 
 private static int testCounter = 0;
 
 
 
 public HomePage(final PageParameters parameters) {
 
 
 
 // Add the simplest type of label
 
 final Label test = new Label(message, If you see this message
  wicket is properly configured and running);
 
 test.add(new AbstractAjaxTimerBehavior(Duration.seconds(1))
 
 {
 
 @Override
 
 protected void onTimer(AjaxRequestTarget target)
 
 {
 
 Label t2 = new Label(message, Test  + testCounter);
 
 test.replaceWith(t2);
 
 testCounter++;
 
 target.addComponent(test);
 
 }
 
 });
 
 
 
 add(test);
 
 }
 
  }
 
 
 
  Exception:
 
  Root cause:
 
  java.lang.IllegalStateException: No Page found for component [Component
  id = message]
  at org.apache.wicket.Component.getPage(Component.java:1754)
  at org.apache.wicket.RequestCycle.urlFor(RequestCycle.java:872)
  at org.apache.wicket.Component.urlFor(Component.java:3286)
  at
  org.apache.wicket.behavior.AbstractAjaxBehavior.getCallbackUrl(AbstractA
  jaxBehavior.java:124)
  at
  org.apache.wicket.ajax.AbstractAjaxTimerBehavior.getCallbackScript(Abstr
  actAjaxTimerBehavior.java:127)
  at
  org.apache.wicket.ajax.AbstractAjaxTimerBehavior.getJsTimeoutCall(Abstra
  ctAjaxTimerBehavior.java:120)
  at
  org.apache.wicket.ajax.AbstractAjaxTimerBehavior.respond(AbstractAjaxTim
  erBehavior.java:163)
  at
  org.apache.wicket.ajax.AbstractDefaultAjaxBehavior.onRequest(AbstractDef
  aultAjaxBehavior.java:299)
  at
  org.apache.wicket.request.target.component.listener.BehaviorRequestTarge
  t.processEvents(BehaviorRequestTarget.java:119)
  at
  org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(Ab
  stractRequestCycleProcessor.java:92

Re: AbstractAjaxTimerBehavior causes exception

2009-11-11 Thread Martin Grigorov
On Wed, 2009-11-11 at 09:21 +0100, Giambalvo, Christian wrote:
 Hi all,
 
  
 
 maybe i found a bug.
 
 Don't know if I'm doing something wrong.
 
 But it's a simple usecase.
 
  
 
 Following code produces an exception:
 
  
 
 public class HomePage extends WebPage {
 
  
 
 private static final long serialVersionUID = 1L;
 
  
 
 private static int testCounter = 0;
 
  
 
 public HomePage(final PageParameters parameters) {
 
  
 
 // Add the simplest type of label
 
 final Label test = new Label(message, If you see this message
 wicket is properly configured and running);
 
 test.add(new AbstractAjaxTimerBehavior(Duration.seconds(1))
 
 {
 
 @Override
 
 protected void onTimer(AjaxRequestTarget target) 
 
 {
 
 Label t2 = new Label(message, Test  + testCounter);
 
 test.replaceWith(t2);
here you need to make : test = t2;
 
 testCounter++;
 
 target.addComponent(test);
 
 }
 
 });
 
  
 
 add(test);
 
 }
 
 }
 
  
 
 Exception:
 
 Root cause:
 
 java.lang.IllegalStateException: No Page found for component [Component
 id = message]
  at org.apache.wicket.Component.getPage(Component.java:1754)
  at org.apache.wicket.RequestCycle.urlFor(RequestCycle.java:872)
  at org.apache.wicket.Component.urlFor(Component.java:3286)
  at
 org.apache.wicket.behavior.AbstractAjaxBehavior.getCallbackUrl(AbstractA
 jaxBehavior.java:124)
  at
 org.apache.wicket.ajax.AbstractAjaxTimerBehavior.getCallbackScript(Abstr
 actAjaxTimerBehavior.java:127)
  at
 org.apache.wicket.ajax.AbstractAjaxTimerBehavior.getJsTimeoutCall(Abstra
 ctAjaxTimerBehavior.java:120)
  at
 org.apache.wicket.ajax.AbstractAjaxTimerBehavior.respond(AbstractAjaxTim
 erBehavior.java:163)
  at
 org.apache.wicket.ajax.AbstractDefaultAjaxBehavior.onRequest(AbstractDef
 aultAjaxBehavior.java:299)
  at
 org.apache.wicket.request.target.component.listener.BehaviorRequestTarge
 t.processEvents(BehaviorRequestTarget.java:119)
  at
 org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(Ab
 stractRequestCycleProcessor.java:92)
  at
 org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java
 :1250)
  at org.apache.wicket.RequestCycle.step(RequestCycle.java:1329)
  at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1428)
  at org.apache.wicket.RequestCycle.request(RequestCycle.java:545)
  at
 org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:468
 )
  at
 org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:
 301)
  at
 org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHan
 dler.java:1157)
  at
 org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
  at
 org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:2
 16)
  at
 org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
  at
 org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
  at
 org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
  at
 org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandler
 Collection.java:230)
  at
 org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.jav
 a:114)
  at
 org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
  at org.mortbay.jetty.Server.handle(Server.java:326)
  at
 org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:536)
  at
 org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConne
 ction.java:915)
  at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:539)
  at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
  at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:405)
  at
 org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:
 409)
  at
 org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java
 :582)
 
  
 
 Greets
 
 Chris
 



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



Re: AbstractAjaxTimerBehavior causes exception

2009-11-11 Thread Ernesto Reinaldo Barreiro
Well I think it all boils down to the explanation a gave on my first e-mail:
if you replace the component with a new one that does not have the behavior
then you will get an exception (the same will happend if you remove the
behavior during a round trip).  I guess Martin was just trying to say that
you should use the same label...? Did you try the code I posted? It does
work ;-)

Cheers,

Ernesto

On Wed, Nov 11, 2009 at 10:06 AM, Giambalvo, Christian 
christian.giamba...@excelsisnet.com wrote:

 Hi Martin,

 this doesn't work.

@Override
protected void onTimer(AjaxRequestTarget target)
{
Label t2 = new Label(message, Test  + testCounter);
 t2.setOutputMarkupId(true);
 test = t2;
testCounter++;
target.addComponent(test);
}
 It doesn't throw an exception, but the t2 didn't show up.
 I think this is because t2 isn't added to the page.
 That’s why there is Component#replaceWith(Component).

 Greets

 -Ursprüngliche Nachricht-
 Von: Martin Grigorov [mailto:mcgreg...@e-card.bg]
 Gesendet: Mittwoch, 11. November 2009 09:59
 An: users@wicket.apache.org
 Betreff: Re: AbstractAjaxTimerBehavior causes exception

 On Wed, 2009-11-11 at 09:21 +0100, Giambalvo, Christian wrote:
  Hi all,
 
 
 
  maybe i found a bug.
 
  Don't know if I'm doing something wrong.
 
  But it's a simple usecase.
 
 
 
  Following code produces an exception:
 
 
 
  public class HomePage extends WebPage {
 
 
 
  private static final long serialVersionUID = 1L;
 
 
 
  private static int testCounter = 0;
 
 
 
  public HomePage(final PageParameters parameters) {
 
 
 
  // Add the simplest type of label
 
  final Label test = new Label(message, If you see this message
  wicket is properly configured and running);
 
  test.add(new AbstractAjaxTimerBehavior(Duration.seconds(1))
 
  {
 
  @Override
 
  protected void onTimer(AjaxRequestTarget target)
 
  {
 
  Label t2 = new Label(message, Test  + testCounter);
 
  test.replaceWith(t2);
 here you need to make : test = t2;
 
  testCounter++;
 
  target.addComponent(test);
 
  }
 
  });
 
 
 
  add(test);
 
  }
 
  }
 
 
 
  Exception:
 
  Root cause:
 
  java.lang.IllegalStateException: No Page found for component [Component
  id = message]
   at org.apache.wicket.Component.getPage(Component.java:1754)
   at org.apache.wicket.RequestCycle.urlFor(RequestCycle.java:872)
   at org.apache.wicket.Component.urlFor(Component.java:3286)
   at
  org.apache.wicket.behavior.AbstractAjaxBehavior.getCallbackUrl(AbstractA
  jaxBehavior.java:124)
   at
  org.apache.wicket.ajax.AbstractAjaxTimerBehavior.getCallbackScript(Abstr
  actAjaxTimerBehavior.java:127)
   at
  org.apache.wicket.ajax.AbstractAjaxTimerBehavior.getJsTimeoutCall(Abstra
  ctAjaxTimerBehavior.java:120)
   at
  org.apache.wicket.ajax.AbstractAjaxTimerBehavior.respond(AbstractAjaxTim
  erBehavior.java:163)
   at
  org.apache.wicket.ajax.AbstractDefaultAjaxBehavior.onRequest(AbstractDef
  aultAjaxBehavior.java:299)
   at
  org.apache.wicket.request.target.component.listener.BehaviorRequestTarge
  t.processEvents(BehaviorRequestTarget.java:119)
   at
  org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(Ab
  stractRequestCycleProcessor.java:92)
   at
  org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java
  :1250)
   at org.apache.wicket.RequestCycle.step(RequestCycle.java:1329)
   at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1428)
   at org.apache.wicket.RequestCycle.request(RequestCycle.java:545)
   at
  org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:468
  )
   at
  org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:
  301)
   at
  org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHan
  dler.java:1157)
   at
  org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
   at
  org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:2
  16)
   at
  org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
   at
  org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
   at
  org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
   at
  org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandler
  Collection.java:230)
   at
  org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.jav
  a:114)
   at
  org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
   at org.mortbay.jetty.Server.handle(Server.java:326)
   at
  org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:536

Re: AbstractAjaxTimerBehavior causes exception

2009-11-11 Thread Ernesto Reinaldo Barreiro
Put a container (WebMarkupContainer?) around components you want to update,
atatch the behavior to that container and make sure the comapoent you want
to update are dynamic: meaning that theirs state should change every
time they are rendered.

Best,

Ernesto

On Wed, Nov 11, 2009 at 10:24 AM, Giambalvo, Christian 
christian.giamba...@excelsisnet.com wrote:

 You're right Ernesto, your example works, but what if I want to replace a
 whole panel and not just the model of a label?


 -Ursprüngliche Nachricht-
 Von: Ernesto Reinaldo Barreiro [mailto:reier...@gmail.com]
 Gesendet: Mittwoch, 11. November 2009 10:15
 An: users@wicket.apache.org
 Betreff: Re: AbstractAjaxTimerBehavior causes exception

 Well I think it all boils down to the explanation a gave on my first
 e-mail:
 if you replace the component with a new one that does not have the behavior
 then you will get an exception (the same will happend if you remove the
 behavior during a round trip).  I guess Martin was just trying to say that
 you should use the same label...? Did you try the code I posted? It does
 work ;-)

 Cheers,

 Ernesto

 On Wed, Nov 11, 2009 at 10:06 AM, Giambalvo, Christian 
 christian.giamba...@excelsisnet.com wrote:

  Hi Martin,
 
  this doesn't work.
 
 @Override
 protected void onTimer(AjaxRequestTarget target)
 {
 Label t2 = new Label(message, Test  + testCounter);
  t2.setOutputMarkupId(true);
  test = t2;
 testCounter++;
 target.addComponent(test);
 }
  It doesn't throw an exception, but the t2 didn't show up.
  I think this is because t2 isn't added to the page.
  That's why there is Component#replaceWith(Component).
 
  Greets
 
  -Ursprüngliche Nachricht-
  Von: Martin Grigorov [mailto:mcgreg...@e-card.bg]
  Gesendet: Mittwoch, 11. November 2009 09:59
  An: users@wicket.apache.org
  Betreff: Re: AbstractAjaxTimerBehavior causes exception
 
  On Wed, 2009-11-11 at 09:21 +0100, Giambalvo, Christian wrote:
   Hi all,
  
  
  
   maybe i found a bug.
  
   Don't know if I'm doing something wrong.
  
   But it's a simple usecase.
  
  
  
   Following code produces an exception:
  
  
  
   public class HomePage extends WebPage {
  
  
  
   private static final long serialVersionUID = 1L;
  
  
  
   private static int testCounter = 0;
  
  
  
   public HomePage(final PageParameters parameters) {
  
  
  
   // Add the simplest type of label
  
   final Label test = new Label(message, If you see this
 message
   wicket is properly configured and running);
  
   test.add(new AbstractAjaxTimerBehavior(Duration.seconds(1))
  
   {
  
   @Override
  
   protected void onTimer(AjaxRequestTarget target)
  
   {
  
   Label t2 = new Label(message, Test  + testCounter);
  
   test.replaceWith(t2);
  here you need to make : test = t2;
  
   testCounter++;
  
   target.addComponent(test);
  
   }
  
   });
  
  
  
   add(test);
  
   }
  
   }
  
  
  
   Exception:
  
   Root cause:
  
   java.lang.IllegalStateException: No Page found for component [Component
   id = message]
at org.apache.wicket.Component.getPage(Component.java:1754)
at org.apache.wicket.RequestCycle.urlFor(RequestCycle.java:872)
at org.apache.wicket.Component.urlFor(Component.java:3286)
at
  
 org.apache.wicket.behavior.AbstractAjaxBehavior.getCallbackUrl(AbstractA
   jaxBehavior.java:124)
at
  
 org.apache.wicket.ajax.AbstractAjaxTimerBehavior.getCallbackScript(Abstr
   actAjaxTimerBehavior.java:127)
at
  
 org.apache.wicket.ajax.AbstractAjaxTimerBehavior.getJsTimeoutCall(Abstra
   ctAjaxTimerBehavior.java:120)
at
  
 org.apache.wicket.ajax.AbstractAjaxTimerBehavior.respond(AbstractAjaxTim
   erBehavior.java:163)
at
  
 org.apache.wicket.ajax.AbstractDefaultAjaxBehavior.onRequest(AbstractDef
   aultAjaxBehavior.java:299)
at
  
 org.apache.wicket.request.target.component.listener.BehaviorRequestTarge
   t.processEvents(BehaviorRequestTarget.java:119)
at
  
 org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(Ab
   stractRequestCycleProcessor.java:92)
at
  
 org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java
   :1250)
at org.apache.wicket.RequestCycle.step(RequestCycle.java:1329)
at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1428)
at org.apache.wicket.RequestCycle.request(RequestCycle.java:545)
at
  
 org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:468
   )
at
  
 org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:
   301)
at
  
 org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHan
   dler.java:1157

Re: AbstractAjaxTimerBehavior causes exception

2009-11-11 Thread Ernesto Reinaldo Barreiro
public class HomePage extends WebPage {

private static final long serialVersionUID = 1L;

private static int testCounter = 0;


WebMarkupContainer container;

/**
 * Constructor that is invoked when page is invoked without a session.
 *
 * @param parameters
 *Page parameters
 */
public HomePage(final PageParameters parameters) {

container = new WebMarkupContainer(container);

// Add the simplest type of label
container.add(new PanelC(panel));
container.setOutputMarkupId(true);
container.add(new AbstractAjaxTimerBehavior(Duration.seconds(4))
{
private static final long serialVersionUID = 1L;

@Override
protected void onTimer(AjaxRequestTarget target)
{
Panel replacement = null;
testCounter++;

switch((testCounter%3))
{
case 0:
replacement = new PanelA(panel);
break;

case 1:
replacement = new PanelB(panel);
break;

case 2:
replacement = new PanelC(panel);
break;
}

container.addOrReplace(replacement);
target.addComponent(container);
}
});
add(container);
}
}

and

html xmlns:wicket=
http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd; 
head
titleWicket Quickstart Archetype Homepage/title
/head
body
strongWicket Quickstart Archetype Homepage/strong
br/br/
div wicket:id=container
span wicket:id=panelmessage will be here/span
/div
/body
/html

will do it

Best,

Ernesto

On Wed, Nov 11, 2009 at 10:25 AM, Giambalvo, Christian 
christian.giamba...@excelsisnet.com wrote:

 Look at the sample project.


 -Ursprüngliche Nachricht-
 Von: Giambalvo, Christian [mailto:christian.giamba...@excelsisnet.com]
 Gesendet: Mittwoch, 11. November 2009 10:24
 An: users@wicket.apache.org
 Betreff: AW: AbstractAjaxTimerBehavior causes exception

 You're right Ernesto, your example works, but what if I want to replace a
 whole panel and not just the model of a label?


 -Ursprüngliche Nachricht-
 Von: Ernesto Reinaldo Barreiro [mailto:reier...@gmail.com]
 Gesendet: Mittwoch, 11. November 2009 10:15
 An: users@wicket.apache.org
 Betreff: Re: AbstractAjaxTimerBehavior causes exception

 Well I think it all boils down to the explanation a gave on my first
 e-mail:
 if you replace the component with a new one that does not have the behavior
 then you will get an exception (the same will happend if you remove the
 behavior during a round trip).  I guess Martin was just trying to say that
 you should use the same label...? Did you try the code I posted? It does
 work ;-)

 Cheers,

 Ernesto

 On Wed, Nov 11, 2009 at 10:06 AM, Giambalvo, Christian 
 christian.giamba...@excelsisnet.com wrote:

  Hi Martin,
 
  this doesn't work.
 
 @Override
 protected void onTimer(AjaxRequestTarget target)
 {
 Label t2 = new Label(message, Test  + testCounter);
  t2.setOutputMarkupId(true);
  test = t2;
 testCounter++;
 target.addComponent(test);
 }
  It doesn't throw an exception, but the t2 didn't show up.
  I think this is because t2 isn't added to the page.
  That's why there is Component#replaceWith(Component).
 
  Greets
 
  -Ursprüngliche Nachricht-
  Von: Martin Grigorov [mailto:mcgreg...@e-card.bg]
  Gesendet: Mittwoch, 11. November 2009 09:59
  An: users@wicket.apache.org
  Betreff: Re: AbstractAjaxTimerBehavior causes exception
 
  On Wed, 2009-11-11 at 09:21 +0100, Giambalvo, Christian wrote:
   Hi all,
  
  
  
   maybe i found a bug.
  
   Don't know if I'm doing something wrong.
  
   But it's a simple usecase.
  
  
  
   Following code produces an exception:
  
  
  
   public class HomePage extends WebPage {
  
  
  
   private static final long serialVersionUID = 1L;
  
  
  
   private static int testCounter = 0;
  
  
  
   public HomePage(final PageParameters parameters) {
  
  
  
   // Add the simplest type of label
  
   final Label test = new Label(message, If you see this
 message
   wicket is properly configured and running);
  
   test.add(new AbstractAjaxTimerBehavior(Duration.seconds(1))
  
   {
  
   @Override
  
   protected void onTimer(AjaxRequestTarget target)
  
   {
  
   Label t2 = new Label(message, Test  + testCounter);
  
   test.replaceWith(t2);
  here you need to make : test = t2;
  
   testCounter++;
  
   target.addComponent(test