You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Mark Fischer <fa...@gmail.com> on 2010/12/02 20:39:07 UTC

Wicket and Cayenne

I am stuck again.  I can get my wicket page to load but the first thing I
see is:

WicketMessage: Can't instantiate page using constructor public .......


Stacktrace

Root cause:

java.lang.IllegalStateException: Current thread has no bound ObjectContext.
     at org.apache.cayenne.BaseContext.getThreadObjectContext(BaseContext.java:73)

.......


My web.xml looks like this:

<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
 <display-name>lockbox</display-name>
	 <filter-mapping>
  <filter-name>wicket.lockbox</filter-name>
  <url-pattern>/*</url-pattern>
 </filter-mapping>

 <filter-mapping>
        <filter-name>CayenneFilter</filter-name>
        <servlet-name>ClickServlet</servlet-name>
    </filter-mapping>

 <filter>
  <filter-name>wicket.lockbox</filter-name>
  <filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class>
  <init-param>
   <param-name>applicationClassName</param-name>
   <param-value>***.*****.****.WicketApplication</param-value>
  </init-param>
 </filter>

 <filter>
        <filter-name>CayenneFilter</filter-name>
        <filter-class>org.apache.cayenne.conf.WebApplicationContextFilter</filter-class>
    </filter>
</web-app>

my java code looks like:

import org.apache.cayenne.ObjectContext;
import org.apache.cayenne.access.DataContext;
import org.apache.cayenne.query.SelectQuery;
import java.util.*;
import org.apache.wicket.request.mapper.parameter.PageParameters;
import org.apache.wicket.markup.html.WebPage;
import ***.******.lockbox.persistent.*;



/**
 * Home page
 * @param <ObjectContext>
 */
public class HomePage<BaseContext> extends WebPage {

	private static final long serialVersionUID = 1L;

	// TODO Add any page properties or variables here

    /**
	 * Constructor that is invoked when page is invoked without a session.
	 *
	 * @param parameters
	 *            Page parameters
	 */
    public HomePage(final PageParameters parameters) {
    	
    	//DataContext context = DataContext.createDataContext();
    	//DataContext context = (DataContext)BaseContext.getThreadObjectContext();
    	//ObjectContext context = DataContext.getThreadObjectContext();    	
    	//ObjectContext oc = BaseContext.getThreadObjectContext();

ObjectContext context = DataContext.getThreadObjectContext();


SelectQuery select1 = new SelectQuery(Credentials.class);
List CredentialsList = context.performQuery(select1);

// Add the simplest type of label
//add(new Label("message", "If you see this message wicket is properly
configured and running"));

add(new Label("message", CredentialsList.toString()));

// TODO Add your page's components here
}
}

Re: Wicket and Cayenne

Posted by Mark Fischer <fa...@gmail.com>.
Kicking myself.  I swear I tried putting the cayenne filter first earlier
this morning but I must have done something wrong.

THANKS SO MUCH!!!

Mark

On Thu, Dec 2, 2010 at 1:51 PM, Mark Fischer <fa...@gmail.com> wrote:

> That originally started out as (like the getting started tutorial):
>
> <filter-mapping>
>         <filter-name>CayenneFilter</filter-name>
>         <url-pattern>/*</url-pattern>
>     </filter-mapping>
> Which didn't work either but in searching the internet I was just copying
> and pasting stuff and I for got to change it back
> Mark
>
>
> On Thu, Dec 2, 2010 at 1:44 PM, Andrus Adamchik <an...@objectstyle.org>wrote:
>
>> Just a guess. Know nothing about Wicket...
>>
>> Looks like CayenneFilter wraps something called "ClickServlet" (which is
>> not shown elsewhere in web.xml), and Wicket call is made from the
>> "wicket.lockbox" filter, which is out of scope of CayenneFilter.
>>
>> Andrus
>>
>> On Dec 2, 2010, at 9:39 PM, Mark Fischer wrote:
>>
>> > I am stuck again.  I can get my wicket page to load but the first thing
>> I
>> > see is:
>> >
>> > WicketMessage: Can't instantiate page using constructor public .......
>> >
>> >
>> > Stacktrace
>> >
>> > Root cause:
>> >
>> > java.lang.IllegalStateException: Current thread has no bound
>> ObjectContext.
>> >     at
>> org.apache.cayenne.BaseContext.getThreadObjectContext(BaseContext.java:73)
>> >
>> > .......
>> >
>> >
>> > My web.xml looks like this:
>> >
>> > <?xml version="1.0" encoding="ISO-8859-1"?>
>> > <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
>> > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>> > xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
>> > http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
>> > <display-name>lockbox</display-name>
>> >        <filter-mapping>
>> >  <filter-name>wicket.lockbox</filter-name>
>> >  <url-pattern>/*</url-pattern>
>> > </filter-mapping>
>> >
>> > <filter-mapping>
>> >        <filter-name>CayenneFilter</filter-name>
>> >        <servlet-name>ClickServlet</servlet-name>
>> >    </filter-mapping>
>> >
>> > <filter>
>> >  <filter-name>wicket.lockbox</filter-name>
>> >
>>  <filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class>
>> >  <init-param>
>> >   <param-name>applicationClassName</param-name>
>> >   <param-value>***.*****.****.WicketApplication</param-value>
>> >  </init-param>
>> > </filter>
>> >
>> > <filter>
>> >        <filter-name>CayenneFilter</filter-name>
>> >
>>  <filter-class>org.apache.cayenne.conf.WebApplicationContextFilter</filter-class>
>> >    </filter>
>> > </web-app>
>> >
>> > my java code looks like:
>> >
>> > import org.apache.cayenne.ObjectContext;
>> > import org.apache.cayenne.access.DataContext;
>> > import org.apache.cayenne.query.SelectQuery;
>> > import java.util.*;
>> > import org.apache.wicket.request.mapper.parameter.PageParameters;
>> > import org.apache.wicket.markup.html.WebPage;
>> > import ***.******.lockbox.persistent.*;
>> >
>> >
>> >
>> > /**
>> > * Home page
>> > * @param <ObjectContext>
>> > */
>> > public class HomePage<BaseContext> extends WebPage {
>> >
>> >       private static final long serialVersionUID = 1L;
>> >
>> >       // TODO Add any page properties or variables here
>> >
>> >    /**
>> >        * Constructor that is invoked when page is invoked without a
>> session.
>> >        *
>> >        * @param parameters
>> >        *            Page parameters
>> >        */
>> >    public HomePage(final PageParameters parameters) {
>> >
>> >       //DataContext context = DataContext.createDataContext();
>> >       //DataContext context =
>> (DataContext)BaseContext.getThreadObjectContext();
>> >       //ObjectContext context = DataContext.getThreadObjectContext();
>> >       //ObjectContext oc = BaseContext.getThreadObjectContext();
>> >
>> > ObjectContext context = DataContext.getThreadObjectContext();
>> >
>> >
>> > SelectQuery select1 = new SelectQuery(Credentials.class);
>> > List CredentialsList = context.performQuery(select1);
>> >
>> > // Add the simplest type of label
>> > //add(new Label("message", "If you see this message wicket is properly
>> > configured and running"));
>> >
>> > add(new Label("message", CredentialsList.toString()));
>> >
>> > // TODO Add your page's components here
>> > }
>> > }
>>
>>
>

Re: Wicket and Cayenne

Posted by Mark Fischer <fa...@gmail.com>.
That originally started out as (like the getting started tutorial):
<filter-mapping>
        <filter-name>CayenneFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
Which didn't work either but in searching the internet I was just copying
and pasting stuff and I for got to change it back
Mark

On Thu, Dec 2, 2010 at 1:44 PM, Andrus Adamchik <an...@objectstyle.org>wrote:

> Just a guess. Know nothing about Wicket...
>
> Looks like CayenneFilter wraps something called "ClickServlet" (which is
> not shown elsewhere in web.xml), and Wicket call is made from the
> "wicket.lockbox" filter, which is out of scope of CayenneFilter.
>
> Andrus
>
> On Dec 2, 2010, at 9:39 PM, Mark Fischer wrote:
>
> > I am stuck again.  I can get my wicket page to load but the first thing I
> > see is:
> >
> > WicketMessage: Can't instantiate page using constructor public .......
> >
> >
> > Stacktrace
> >
> > Root cause:
> >
> > java.lang.IllegalStateException: Current thread has no bound
> ObjectContext.
> >     at
> org.apache.cayenne.BaseContext.getThreadObjectContext(BaseContext.java:73)
> >
> > .......
> >
> >
> > My web.xml looks like this:
> >
> > <?xml version="1.0" encoding="ISO-8859-1"?>
> > <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
> > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> > xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
> > http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
> > <display-name>lockbox</display-name>
> >        <filter-mapping>
> >  <filter-name>wicket.lockbox</filter-name>
> >  <url-pattern>/*</url-pattern>
> > </filter-mapping>
> >
> > <filter-mapping>
> >        <filter-name>CayenneFilter</filter-name>
> >        <servlet-name>ClickServlet</servlet-name>
> >    </filter-mapping>
> >
> > <filter>
> >  <filter-name>wicket.lockbox</filter-name>
> >
>  <filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class>
> >  <init-param>
> >   <param-name>applicationClassName</param-name>
> >   <param-value>***.*****.****.WicketApplication</param-value>
> >  </init-param>
> > </filter>
> >
> > <filter>
> >        <filter-name>CayenneFilter</filter-name>
> >
>  <filter-class>org.apache.cayenne.conf.WebApplicationContextFilter</filter-class>
> >    </filter>
> > </web-app>
> >
> > my java code looks like:
> >
> > import org.apache.cayenne.ObjectContext;
> > import org.apache.cayenne.access.DataContext;
> > import org.apache.cayenne.query.SelectQuery;
> > import java.util.*;
> > import org.apache.wicket.request.mapper.parameter.PageParameters;
> > import org.apache.wicket.markup.html.WebPage;
> > import ***.******.lockbox.persistent.*;
> >
> >
> >
> > /**
> > * Home page
> > * @param <ObjectContext>
> > */
> > public class HomePage<BaseContext> extends WebPage {
> >
> >       private static final long serialVersionUID = 1L;
> >
> >       // TODO Add any page properties or variables here
> >
> >    /**
> >        * Constructor that is invoked when page is invoked without a
> session.
> >        *
> >        * @param parameters
> >        *            Page parameters
> >        */
> >    public HomePage(final PageParameters parameters) {
> >
> >       //DataContext context = DataContext.createDataContext();
> >       //DataContext context =
> (DataContext)BaseContext.getThreadObjectContext();
> >       //ObjectContext context = DataContext.getThreadObjectContext();
> >       //ObjectContext oc = BaseContext.getThreadObjectContext();
> >
> > ObjectContext context = DataContext.getThreadObjectContext();
> >
> >
> > SelectQuery select1 = new SelectQuery(Credentials.class);
> > List CredentialsList = context.performQuery(select1);
> >
> > // Add the simplest type of label
> > //add(new Label("message", "If you see this message wicket is properly
> > configured and running"));
> >
> > add(new Label("message", CredentialsList.toString()));
> >
> > // TODO Add your page's components here
> > }
> > }
>
>

Re: Wicket and Cayenne

Posted by Andrus Adamchik <an...@objectstyle.org>.
Just a guess. Know nothing about Wicket...

Looks like CayenneFilter wraps something called "ClickServlet" (which is not shown elsewhere in web.xml), and Wicket call is made from the "wicket.lockbox" filter, which is out of scope of CayenneFilter. 

Andrus

On Dec 2, 2010, at 9:39 PM, Mark Fischer wrote:

> I am stuck again.  I can get my wicket page to load but the first thing I
> see is:
> 
> WicketMessage: Can't instantiate page using constructor public .......
> 
> 
> Stacktrace
> 
> Root cause:
> 
> java.lang.IllegalStateException: Current thread has no bound ObjectContext.
>     at org.apache.cayenne.BaseContext.getThreadObjectContext(BaseContext.java:73)
> 
> .......
> 
> 
> My web.xml looks like this:
> 
> <?xml version="1.0" encoding="ISO-8859-1"?>
> <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
> http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
> <display-name>lockbox</display-name>
> 	 <filter-mapping>
>  <filter-name>wicket.lockbox</filter-name>
>  <url-pattern>/*</url-pattern>
> </filter-mapping>
> 
> <filter-mapping>
>        <filter-name>CayenneFilter</filter-name>
>        <servlet-name>ClickServlet</servlet-name>
>    </filter-mapping>
> 
> <filter>
>  <filter-name>wicket.lockbox</filter-name>
>  <filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class>
>  <init-param>
>   <param-name>applicationClassName</param-name>
>   <param-value>***.*****.****.WicketApplication</param-value>
>  </init-param>
> </filter>
> 
> <filter>
>        <filter-name>CayenneFilter</filter-name>
>        <filter-class>org.apache.cayenne.conf.WebApplicationContextFilter</filter-class>
>    </filter>
> </web-app>
> 
> my java code looks like:
> 
> import org.apache.cayenne.ObjectContext;
> import org.apache.cayenne.access.DataContext;
> import org.apache.cayenne.query.SelectQuery;
> import java.util.*;
> import org.apache.wicket.request.mapper.parameter.PageParameters;
> import org.apache.wicket.markup.html.WebPage;
> import ***.******.lockbox.persistent.*;
> 
> 
> 
> /**
> * Home page
> * @param <ObjectContext>
> */
> public class HomePage<BaseContext> extends WebPage {
> 
> 	private static final long serialVersionUID = 1L;
> 
> 	// TODO Add any page properties or variables here
> 
>    /**
> 	 * Constructor that is invoked when page is invoked without a session.
> 	 *
> 	 * @param parameters
> 	 *            Page parameters
> 	 */
>    public HomePage(final PageParameters parameters) {
>    	
>    	//DataContext context = DataContext.createDataContext();
>    	//DataContext context = (DataContext)BaseContext.getThreadObjectContext();
>    	//ObjectContext context = DataContext.getThreadObjectContext();    	
>    	//ObjectContext oc = BaseContext.getThreadObjectContext();
> 
> ObjectContext context = DataContext.getThreadObjectContext();
> 
> 
> SelectQuery select1 = new SelectQuery(Credentials.class);
> List CredentialsList = context.performQuery(select1);
> 
> // Add the simplest type of label
> //add(new Label("message", "If you see this message wicket is properly
> configured and running"));
> 
> add(new Label("message", CredentialsList.toString()));
> 
> // TODO Add your page's components here
> }
> }


Re: Wicket and Cayenne

Posted by Robert Zeigler <ro...@roxanemy.com>.
filter ordering is important here. 
Wicket is implemented as a servlet filter, right?
So you need the cayenne filter applied before the wicket filter so it has a chance to bind the context before wicket does its thing.
Filters are applied in the order that their <filter-mappings> are listed.  So move the <filter-mapping> for the cayenne servlet above the <filter-mapping> for the wicket.lockbox filter.

Robert

On Dec 2, 2010, at 12/21:39 PM , Mark Fischer wrote:

> I am stuck again.  I can get my wicket page to load but the first thing I
> see is:
> 
> WicketMessage: Can't instantiate page using constructor public .......
> 
> 
> Stacktrace
> 
> Root cause:
> 
> java.lang.IllegalStateException: Current thread has no bound ObjectContext.
>     at org.apache.cayenne.BaseContext.getThreadObjectContext(BaseContext.java:73)
> 
> .......
> 
> 
> My web.xml looks like this:
> 
> <?xml version="1.0" encoding="ISO-8859-1"?>
> <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
> http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
> <display-name>lockbox</display-name>
> 	 <filter-mapping>
>  <filter-name>wicket.lockbox</filter-name>
>  <url-pattern>/*</url-pattern>
> </filter-mapping>
> 
> <filter-mapping>
>        <filter-name>CayenneFilter</filter-name>
>        <servlet-name>ClickServlet</servlet-name>
>    </filter-mapping>
> 
> <filter>
>  <filter-name>wicket.lockbox</filter-name>
>  <filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class>
>  <init-param>
>   <param-name>applicationClassName</param-name>
>   <param-value>***.*****.****.WicketApplication</param-value>
>  </init-param>
> </filter>
> 
> <filter>
>        <filter-name>CayenneFilter</filter-name>
>        <filter-class>org.apache.cayenne.conf.WebApplicationContextFilter</filter-class>
>    </filter>
> </web-app>
> 
> my java code looks like:
> 
> import org.apache.cayenne.ObjectContext;
> import org.apache.cayenne.access.DataContext;
> import org.apache.cayenne.query.SelectQuery;
> import java.util.*;
> import org.apache.wicket.request.mapper.parameter.PageParameters;
> import org.apache.wicket.markup.html.WebPage;
> import ***.******.lockbox.persistent.*;
> 
> 
> 
> /**
> * Home page
> * @param <ObjectContext>
> */
> public class HomePage<BaseContext> extends WebPage {
> 
> 	private static final long serialVersionUID = 1L;
> 
> 	// TODO Add any page properties or variables here
> 
>    /**
> 	 * Constructor that is invoked when page is invoked without a session.
> 	 *
> 	 * @param parameters
> 	 *            Page parameters
> 	 */
>    public HomePage(final PageParameters parameters) {
>    	
>    	//DataContext context = DataContext.createDataContext();
>    	//DataContext context = (DataContext)BaseContext.getThreadObjectContext();
>    	//ObjectContext context = DataContext.getThreadObjectContext();    	
>    	//ObjectContext oc = BaseContext.getThreadObjectContext();
> 
> ObjectContext context = DataContext.getThreadObjectContext();
> 
> 
> SelectQuery select1 = new SelectQuery(Credentials.class);
> List CredentialsList = context.performQuery(select1);
> 
> // Add the simplest type of label
> //add(new Label("message", "If you see this message wicket is properly
> configured and running"));
> 
> add(new Label("message", CredentialsList.toString()));
> 
> // TODO Add your page's components here
> }
> }