You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by "Artur W." <a_...@gazeta.pl> on 2007/12/25 17:22:33 UTC

getPage() throws IllegalStateException: No Page found for component

Hi!

I want to create a Panel that its content depends to which page it was
added.

So I want to do something like this

if (getPage().getPageClass() == Page1.class) {
    [...]
} else if (getPage().getPageClass() == Page2.class) {
    [...]
} else {
    [...]
}

and so on.

But when I call getPage() I get 

org.apache.wicket.WicketRuntimeException: Can't instantiate page using
constructor public com.test.AdminPage(org.apache.wicket.PageParameters) and
argument 
	at
org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:175)
	at
org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:66)
	at
org.apache.wicket.request.target.component.BookmarkablePageRequestTarget.newPage(BookmarkablePageRequestTarget.java:262)
	at
org.apache.wicket.request.target.component.BookmarkablePageRequestTarget.getPage(BookmarkablePageRequestTarget.java:283)
	at
org.apache.wicket.request.target.component.BookmarkablePageRequestTarget.processEvents(BookmarkablePageRequestTarget.java:210)
	at
org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(AbstractRequestCycleProcessor.java:90)
	at
org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1094)

[...]

Caused by: java.lang.IllegalStateException: No Page found for component
[MarkupContainer [Component id = menuPanel, page = <No Page>, path =
menuPanel.AdminPage$3]]
	at org.apache.wicket.Component.getPage(Component.java:1600)



How can I do this? (I use Wicket 1.3rc2)



Thanks,
Artur

-- 
View this message in context: http://www.nabble.com/getPage%28%29-throws-IllegalStateException%3A-No-Page-found-for-component-tp14496019p14496019.html
Sent from the Wicket - User 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: getPage() throws IllegalStateException: No Page found for component

Posted by Maurice Marrink <ma...@gmail.com>.
Usually this happens when you try to use getPage in the constructor of
you panel, however in that case i find the stacktrace with the
bookmarkablepagerequesttarget a bit odd.
Is the panel at the time of invocation attached to a page at all?
Usually you should be able to use getPage in the event phase (unless
your component has just been removed from its parent)
An alternative solution would be to pass the parent page at
construction time as a parameter of your panels constructor.

Maurice

On Dec 25, 2007 5:22 PM, Artur W. <a_...@gazeta.pl> wrote:
>
> Hi!
>
> I want to create a Panel that its content depends to which page it was
> added.
>
> So I want to do something like this
>
> if (getPage().getPageClass() == Page1.class) {
>     [...]
> } else if (getPage().getPageClass() == Page2.class) {
>     [...]
> } else {
>     [...]
> }
>
> and so on.
>
> But when I call getPage() I get
>
> org.apache.wicket.WicketRuntimeException: Can't instantiate page using
> constructor public com.test.AdminPage(org.apache.wicket.PageParameters) and
> argument
>         at
> org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:175)
>         at
> org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:66)
>         at
> org.apache.wicket.request.target.component.BookmarkablePageRequestTarget.newPage(BookmarkablePageRequestTarget.java:262)
>         at
> org.apache.wicket.request.target.component.BookmarkablePageRequestTarget.getPage(BookmarkablePageRequestTarget.java:283)
>         at
> org.apache.wicket.request.target.component.BookmarkablePageRequestTarget.processEvents(BookmarkablePageRequestTarget.java:210)
>         at
> org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(AbstractRequestCycleProcessor.java:90)
>         at
> org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1094)
>
> [...]
>
> Caused by: java.lang.IllegalStateException: No Page found for component
> [MarkupContainer [Component id = menuPanel, page = <No Page>, path =
> menuPanel.AdminPage$3]]
>         at org.apache.wicket.Component.getPage(Component.java:1600)
>
>
>
> How can I do this? (I use Wicket 1.3rc2)
>
>
>
> Thanks,
> Artur
>
> --
> View this message in context: http://www.nabble.com/getPage%28%29-throws-IllegalStateException%3A-No-Page-found-for-component-tp14496019p14496019.html
> Sent from the Wicket - User 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


Re: getPage() throws IllegalStateException: No Page found for component

Posted by Matej Knopp <ma...@gmail.com>.
If you really are calling getPage() in your panel's constructor than
it can't work. Because at that point the panel is not added to page.

You can postpone your initialization by putting the code to
onBeforeRender and invoke it only when onBeforeRender is called for
the first time.

e.g

super.onBeforeRender();
if (!hasBeenRendered()) {
   // getPage() works here. Do the stuff you need with page instance
}

-Matej

On Dec 27, 2007 7:46 AM, Artur W. <a_...@gazeta.pl> wrote:
>
>
> Antoine Angénieux wrote:
> >
> > May be you should try making your panel abstract and override an
> > abstract method as an anonymous inner class of your page, instead of all
> > your "ifs" ?
> >
>
> Antoine, Thanks for you reply.
>
> Your idea is good but it will not work in my case.
>
> I have a abstract page to which I add my Panel (menu). All of the other
> pages extends this abstract page so I don't create/add this panel to them.
>
>
> Best regards,
> Artur
> --
> View this message in context: http://www.nabble.com/getPage%28%29-throws-IllegalStateException%3A-No-Page-found-for-component-tp14496019p14510157.html
> Sent from the Wicket - User 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


Re: getPage() throws IllegalStateException: No Page found for component

Posted by "Artur W." <a_...@gazeta.pl>.

Antoine Angénieux wrote:
> 
> May be you should try making your panel abstract and override an 
> abstract method as an anonymous inner class of your page, instead of all 
> your "ifs" ?
> 

Antoine, Thanks for you reply.

Your idea is good but it will not work in my case.

I have a abstract page to which I add my Panel (menu). All of the other
pages extends this abstract page so I don't create/add this panel to them.


Best regards,
Artur
-- 
View this message in context: http://www.nabble.com/getPage%28%29-throws-IllegalStateException%3A-No-Page-found-for-component-tp14496019p14510157.html
Sent from the Wicket - User 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: getPage() throws IllegalStateException: No Page found for component

Posted by Antoine Angénieux <aa...@clinigrid.com>.
May be you should try making your panel abstract and override an 
abstract method as an anonymous inner class of your page, instead of all 
your "ifs" ?

Like :

public abstract class MyPageRelatedPanel extends Panel {

   public MyPageRelatedPanel(String id, IModel model) {
     super(id, model);
     [..add your common components, etc..]
     createSpecificPart();
   }

   protected abstract void createSpecificPart();

}

and in your page :

   add(new MyPageRelatedPanel("id", panelModel) {

     protected abstract void createSpecificPart() {
      [..add your special page related components, behaviors, etc.. here]
     }
   };

This way you keep your panel generic enough and page independant and can 
reuse it in pages you haven't created yet !

Just my 2 cents,

Cheers,

Antoine.

Artur W. a écrit :
> Hi!
> 
> I want to create a Panel that its content depends to which page it was
> added.
> 
> So I want to do something like this
> 
> if (getPage().getPageClass() == Page1.class) {
>     [...]
> } else if (getPage().getPageClass() == Page2.class) {
>     [...]
> } else {
>     [...]
> }
> 
> and so on.
> 
> But when I call getPage() I get 
> 
> org.apache.wicket.WicketRuntimeException: Can't instantiate page using
> constructor public com.test.AdminPage(org.apache.wicket.PageParameters) and
> argument 
> 	at
> org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:175)
> 	at
> org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:66)
> 	at
> org.apache.wicket.request.target.component.BookmarkablePageRequestTarget.newPage(BookmarkablePageRequestTarget.java:262)
> 	at
> org.apache.wicket.request.target.component.BookmarkablePageRequestTarget.getPage(BookmarkablePageRequestTarget.java:283)
> 	at
> org.apache.wicket.request.target.component.BookmarkablePageRequestTarget.processEvents(BookmarkablePageRequestTarget.java:210)
> 	at
> org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(AbstractRequestCycleProcessor.java:90)
> 	at
> org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1094)
> 
> [...]
> 
> Caused by: java.lang.IllegalStateException: No Page found for component
> [MarkupContainer [Component id = menuPanel, page = <No Page>, path =
> menuPanel.AdminPage$3]]
> 	at org.apache.wicket.Component.getPage(Component.java:1600)
> 
> 
> 
> How can I do this? (I use Wicket 1.3rc2)
> 
> 
> 
> Thanks,
> Artur
> 

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