You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by monzonj <mo...@gmail.com> on 2010/10/04 16:38:41 UTC

AbstractDefaultAjaxBehavior.getCallbackUrl() throws a Runtime Exception

Hi. 
I'm still trying to understand how Wicket works, and I still don't get many
things, specially related to the code we can / can't place in a page/panel
constructor.

I've got this case I don't understand, perhaps you guys have an idea what's
going on. 

Imagine this test application:

-------------------------------------------------

public class TestApp extends WebApplication {
    @Override
    public Class<? extends Page> getHomePage() {
        return HomePage.class;
    }
}

-------------------------------------------------

public class HomePage extends WebPage {
    public HomePage() {
        TestPanel p = new TestPanel("myPanel");
        add(p);
    }
}

-------------------------------------------------

((HomePage.html))
<body>
    <div wicket:id="myPanel"></div>
</body>


-------------------------------------------------


public class TestPanel extends Panel {
    public TestPanel(final String id) {
        super(id);

        AbstractDefaultAjaxBehavior behavior = new
AbstractDefaultAjaxBehavior(){
            protected void respond(final AjaxRequestTarget target) {
                //not important for the test
            }
        };

        add(behavior); 
        behavior.getCallbackUrl()); //Runtime exception. No Page found for
component :(
    }
}


If you run this example, you get:

java.lang.IllegalStateException: No Page found for component
[MarkupContainer [Component id = myPanel]]
     at org.apache.wicket.Component.getPage(Component.java:1819)

The method getPage returns null. Why? Where Am I supposed to make the call
getCallBackUrl() if not in the constructor?

Any help will be most appreciated,
Thanks.






-- 
View this message in context: http://apache-wicket.1842946.n4.nabble.com/AbstractDefaultAjaxBehavior-getCallbackUrl-throws-a-Runtime-Exception-tp2954440p2954440.html
Sent from the Users forum mailing list archive at Nabble.com.

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


Re: AbstractDefaultAjaxBehavior.getCallbackUrl() throws a Runtime Exception

Posted by Martin Grigorov <mg...@apache.org>.
You can make the call as soon as in #onInitialize() or in #onBeforeRender()

On Mon, Oct 4, 2010 at 4:38 PM, monzonj <mo...@gmail.com> wrote:

>
> Hi.
> I'm still trying to understand how Wicket works, and I still don't get many
> things, specially related to the code we can / can't place in a page/panel
> constructor.
>
> I've got this case I don't understand, perhaps you guys have an idea what's
> going on.
>
> Imagine this test application:
>
> -------------------------------------------------
>
> public class TestApp extends WebApplication {
>    @Override
>    public Class<? extends Page> getHomePage() {
>        return HomePage.class;
>    }
> }
>
> -------------------------------------------------
>
> public class HomePage extends WebPage {
>    public HomePage() {
>        TestPanel p = new TestPanel("myPanel");
>        add(p);
>    }
> }
>
> -------------------------------------------------
>
> ((HomePage.html))
> <body>
>    <div wicket:id="myPanel"></div>
> </body>
>
>
> -------------------------------------------------
>
>
> public class TestPanel extends Panel {
>    public TestPanel(final String id) {
>        super(id);
>
>        AbstractDefaultAjaxBehavior behavior = new
> AbstractDefaultAjaxBehavior(){
>            protected void respond(final AjaxRequestTarget target) {
>                //not important for the test
>            }
>        };
>
>        add(behavior);
>        behavior.getCallbackUrl()); //Runtime exception. No Page found for
> component :(
>    }
> }
>
>
> If you run this example, you get:
>
> java.lang.IllegalStateException: No Page found for component
> [MarkupContainer [Component id = myPanel]]
>     at org.apache.wicket.Component.getPage(Component.java:1819)
>
> The method getPage returns null. Why? Where Am I supposed to make the call
> getCallBackUrl() if not in the constructor?
>
> Any help will be most appreciated,
> Thanks.
>
>
>
>
>
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/AbstractDefaultAjaxBehavior-getCallbackUrl-throws-a-Runtime-Exception-tp2954440p2954440.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: AbstractDefaultAjaxBehavior.getCallbackUrl() throws a Runtime Exception

Posted by monzonj <mo...@gmail.com>.
Thank you guy, it worked!

I was using mostly the constructor to always set up my pages.
-- 
View this message in context: http://apache-wicket.1842946.n4.nabble.com/AbstractDefaultAjaxBehavior-getCallbackUrl-throws-a-Runtime-Exception-tp2954440p2956227.html
Sent from the Users forum mailing list archive at Nabble.com.

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


Re: AbstractDefaultAjaxBehavior.getCallbackUrl() throws a Runtime Exception

Posted by Ernesto Reinaldo Barreiro <re...@gmail.com>.
The panel containing the behavior hasn't been added to the page (yet)
on panel constructor so you can't compute the path (UTL) to the
behavior. That's why you have to to use the methods suggested by
Martin.

Ernesto

On Mon, Oct 4, 2010 at 4:38 PM, monzonj <mo...@gmail.com> wrote:
>
> Hi.
> I'm still trying to understand how Wicket works, and I still don't get many
> things, specially related to the code we can / can't place in a page/panel
> constructor.
>
> I've got this case I don't understand, perhaps you guys have an idea what's
> going on.
>
> Imagine this test application:
>
> -------------------------------------------------
>
> public class TestApp extends WebApplication {
>    @Override
>    public Class<? extends Page> getHomePage() {
>        return HomePage.class;
>    }
> }
>
> -------------------------------------------------
>
> public class HomePage extends WebPage {
>    public HomePage() {
>        TestPanel p = new TestPanel("myPanel");
>        add(p);
>    }
> }
>
> -------------------------------------------------
>
> ((HomePage.html))
> <body>
>    <div wicket:id="myPanel"></div>
> </body>
>
>
> -------------------------------------------------
>
>
> public class TestPanel extends Panel {
>    public TestPanel(final String id) {
>        super(id);
>
>        AbstractDefaultAjaxBehavior behavior = new
> AbstractDefaultAjaxBehavior(){
>            protected void respond(final AjaxRequestTarget target) {
>                //not important for the test
>            }
>        };
>
>        add(behavior);
>        behavior.getCallbackUrl()); //Runtime exception. No Page found for
> component :(
>    }
> }
>
>
> If you run this example, you get:
>
> java.lang.IllegalStateException: No Page found for component
> [MarkupContainer [Component id = myPanel]]
>     at org.apache.wicket.Component.getPage(Component.java:1819)
>
> The method getPage returns null. Why? Where Am I supposed to make the call
> getCallBackUrl() if not in the constructor?
>
> Any help will be most appreciated,
> Thanks.
>
>
>
>
>
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/AbstractDefaultAjaxBehavior-getCallbackUrl-throws-a-Runtime-Exception-tp2954440p2954440.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

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