I'm brand new to wicket and going through the book "Wicket in Action". I've
ran into a problem that I can't seem to get around, maybe I am over thinking
it. I have a class I wrote that extends
org.apache.protocol.http.WebSession, and I am getting a ClassCastException
when I try to return my session. This is the cheese store example from the
book if anyone is familiar with it. Here is the code in question:
*From my class that extends WebPage:
*
public CheeseStoreSession getCheeseStoreSession()
{
return (CheeseStoreSession) getSession(); *//exception occurs right
here*
}
I've confirmed that the getSession method is returning an object of type
WebSession.
*
My custom session class looks like this:*
package com.manning.example;
import org.apache.wicket.Request;
import org.apache.wicket.Response;
import org.apache.wicket.Session;
import org.apache.wicket.protocol.http.WebSession;
public class CheeseStoreSession extends WebSession
{
private Cart cart = new Cart();
protected CheeseStoreSession(Request request)
{
super(request);
}
public Cart getCart()
{
return cart;
}
public Session newSession(Request request, Response response)
{
return new CheeseStoreSession(request);
}
}
I am having difficulty understanding the purpose of the ClassCastException
that I am getting. Here is the exception:
WicketMessage: Error calling method: public com.manning.example.Cart
com.manning.example.CheeseStorePage.getCart() on object: [Page class =
com.manning.example.Index, id = 13, version = 0]
Root cause:
java.lang.ClassCastException: org.apache.wicket.protocol.http.WebSession
at
com.manning.example.CheeseStorePage.getCheesrSession(CheeseStorePage.java:27)
at com.manning.example.CheeseStorePage.getCart(CheeseStorePage.java:33)
at java.lang.reflect.Method.invoke(Method.java:585)
at
org.apache.wicket.util.lang.PropertyResolver$MethodGetAndSet.getValue(PropertyResolver.java:1046)
at
org.apache.wicket.util.lang.PropertyResolver.getObjectAndGetSetter(PropertyResolver.java:242)
at
org.apache.wicket.util.lang.PropertyResolver.getValue(PropertyResolver.java:87)
at
org.apache.wicket.model.AbstractPropertyModel.getObject(AbstractPropertyModel.java:113)
at org.apache.wicket.Component.getModelObject(Component.java:1559)
at
org.apache.wicket.markup.html.list.ListView.getViewSize(ListView.java:217)
at org.apache.wicket.markup.html.list.ListView.onPopulate(ListView.java:524)
at
org.apache.wicket.markup.repeater.AbstractRepeater.onBeforeRender(AbstractRepeater.java:127)
at org.apache.wicket.Component.internalBeforeRender(Component.java:1003)
...
...
Can someone point me in the right direction for diagnosing this?
--
Brad Gardner