You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by David Brown <db...@sexingtechnologies.com> on 2009/07/30 00:46:57 UTC
WicketNotSerializableException
Hello, I have a small show-stopper with a WicketTester testcase and a Wicket Page. The Wicket Page is a concrete Class extending WebPage. I am calling a simple private method: init() that is nested within the Page constructor. Inside the init() method I have an anonymous inner class constructed from a composition: new SortableDataProvider{}; The target of the composition is assigned to an instance variable of ISortableDataProvider which requires that I must override the IModel model(final Object object) method. When I run Maven test on this Page I get the following error condition:
org.apache.wicket.util.io.SerializableChecker$WicketNotSerializableException: Unable to serialize class: java.lang.Object
I have tried using strategic placement of: transient and static but of no use.
Regards, David.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: WicketNotSerializableException
Posted by Jeremy Thomerson <je...@wickettraining.com>.
You shouldn't have a final connection or reference to the DAO - these
go into the anonymous inner class and will cause this error (I'm
assuming that your dao isn't serializable). You should either have a
lookup in the anonymous class or use SpringBean (which you commented
ou).
--
Jeremy Thomerson
http://www.wickettraining.com
On Wed, Jul 29, 2009 at 6:43 PM, David
Brown<db...@sexingtechnologies.com> wrote:
> Hello Jeremy, thanks for the reply. Please find the requested WebPage included below. At the cost of looking somewhat contrived I had to edit to keep the Lawyers happy. Yes, you're right (again), there are plenty of references outside the declaration but those also got: implements Serializable in a weak attempt to shut up the compiler. Please advise, David.
>
>
> *******************************************************************
> package com.technology.pages.myapp;
>
> import java.sql.Connection;
> import java.sql.SQLException;
> import java.util.ArrayList;
> import java.util.Iterator;
> import java.util.List;
>
> import org.apache.wicket.Component;
> import org.apache.wicket.IPageMap;
> import org.apache.wicket.MarkupContainer;
> import org.apache.wicket.PageParameters;
> import org.apache.wicket.behavior.HeaderContributor;
> import org.apache.wicket.extensions.markup.html.repeater.data.table.DefaultDataTable;
> import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn;
> import org.apache.wicket.extensions.markup.html.repeater.data.table.ISortableDataProvider;
> import org.apache.wicket.extensions.markup.html.repeater.data.table.PropertyColumn;
> import org.apache.wicket.extensions.markup.html.repeater.data.table.filter.FilterForm;
> import org.apache.wicket.extensions.markup.html.repeater.data.table.filter.FilteredAbstractColumn;
> import org.apache.wicket.extensions.markup.html.repeater.util.SortableDataProvider;
> import org.apache.wicket.markup.html.WebPage;
> import org.apache.wicket.markup.html.link.Link;
> import org.apache.wicket.markup.repeater.Item;
> import org.apache.wicket.model.CompoundPropertyModel;
> import org.apache.wicket.model.IModel;
> import org.apache.wicket.model.LoadableDetachableModel;
> import org.apache.wicket.model.Model;
> import org.apache.wicket.spring.injection.annot.SpringBean;
> import org.slf4j.Logger;
> import org.slf4j.LoggerFactory;
>
> import com.technology.dao.MyappDao;
> import com.technology.dao.jdbc.MyappDaoJdbcDBConnSQL;
> import com.technology.dao.jdbc.DBConnSQL;
> import com.technology.model.Myapp;
> import com.technology.pages.myapp.ActionsPanel;
> import com.technology.pages.myapp.MyappEditPage;
>
> public class MyappPage extends WebPage {
>
> private static transient Logger log = LoggerFactory.getLogger(MyappPage.class);
>
> //@SpringBean
> private MyappDao myappDao;
>
> public MyappPage() {
> init();
> }
>
> private void init(){
>
> //adding css
> //add(HeaderContributor.forCss(MyappPage.class, "base.css")); // in 1.4 causes markup error
> myappDao = new MyappDaoJdbcDBConnSQL();
> if(myappDao == null && log.isDebugEnabled()) log.error("MyappPage.init().myappDao: null");
> else log.info("MyappPage.init().myappDao: OK!");
> final DBConnSQL dbc = new DBConnSQL();
> final Connection conn = dbc.getConnection();
>
> ISortableDataProvider dp = new SortableDataProvider(){
>
>
> private static final long serialVersionUID = 1L;
>
> @SuppressWarnings("unchecked")
>
>
> public Iterator iterator(int first, int count) {
>
> //final SortParam sort = getSort();
> //do something with the sort param here to eg
> //return baseDao.selectAllInRangeSorted(first, count, sort).iterator();
>
> //sorting not currently implemented
> return myappDao.getItems().iterator();
> }
>
> /*
> * use LoadableDetachableModel so that objects aren't serialized, could use
> * just a normal model if wasn't bothered about that eg
> * return new Model(object);
> */
> public IModel model(final Object object) {
> return new LoadableDetachableModel(object){
> private static final long serialVersionUID = 1L;
> //private Long id = object.getClass().cast(Myapp);
> @Override
> protected List load() {
> //return myappDao.getItem(id);
> return myappDao.getItems();
> }
> };
> }
>
> public int size() {
> return myappDao.getCount();
> }
>
> };
> final List<IColumn> columns = new ArrayList<IColumn>();
>
> //add column for the edit and delete links
> columns.add(new FilteredAbstractColumn(new Model("actions")){
> private static final long serialVersionUID = 1L;
> public Component getFilter(String componentId, FilterForm form) {
> return null;
> }
> public void populateItem(Item cellItem, String componentId, IModel rowModel) {
> cellItem.add(new ActionsPanel(componentId, rowModel));
> }
> });
>
> //sorting is not used on this
> //all the columns dont fit
> columns.add(new PropertyColumn(new Model("animalId"), "animalId", "animalId"));
> columns.add(new PropertyColumn(new Model("itemCode"), "itemCode", "itemCode"));
> columns.add(new PropertyColumn(new Model("brdCode"), "brdCode"));
> columns.add(new PropertyColumn(new Model("itemName"), "itemName"));
> columns.add(new PropertyColumn(new Model("AKAName"), "AKAName"));
> columns.add(new PropertyColumn(new Model("brdIdNo"), "brdIdNo", "brdIdNo"));
> columns.add(new PropertyColumn(new Model("statusIdNo"), "statusIdNo"));
> columns.add(new PropertyColumn(new Model("regNo"), "regNo"));
> columns.add(new PropertyColumn(new Model("sign"), "sign"));
> /*
> columns.add(new PropertyColumn(new Model("Tag"), "Tag"));
> columns.add(new PropertyColumn(new Model("mastCatItem"), "mastCatItem"));
> columns.add(new PropertyColumn(new Model("Country"), "Country"));
> columns.add(new PropertyColumn(new Model("ID"), "itemId"));
> columns.add(new PropertyColumn(new Model("birthDate"), "birthDate"));
> columns.add(new PropertyColumn(new Model("sName"), "sName"));
> columns.add(new PropertyColumn(new Model("RegNo"), "RegNo"));
> columns.add(new PropertyColumn(new Model("dName"), "dName"));
> columns.add(new PropertyColumn(new Model("dRegNo"), "dRegNo"));
> columns.add(new PropertyColumn(new Model("bloodNo"), "bloodNo"));
> columns.add(new PropertyColumn(new Model("DNo"), "DNo"));
> columns.add(new PropertyColumn(new Model("notes"), "notes"));
> columns.add(new PropertyColumn(new Model("lastModUser"), "lastModUser"));
> columns.add(new PropertyColumn(new Model("lastModDate"), "lastModDate"));
> */
>
> DefaultDataTable dataTable = new DefaultDataTable("dataTable", columns, dp, 20);
>
> add(dataTable);
>
> add(new Link("create"){
>
> /**
> *
> */
> private static final long serialVersionUID = 1L;
>
> @Override
> public void onClick() {
> setResponsePage(new MyappEditPage(getPage(), new CompoundPropertyModel(new Myapp())));
> }
>
> });
>
> dbc.returnConnection(conn);
>
> } // END INIT()
>
> }
>
> *******************************************************************
>
>
>
> ----- Original Message -----
> From: "Jeremy Thomerson" <je...@wickettraining.com>
> To: users@wicket.apache.org
> Sent: Wednesday, July 29, 2009 5:57:35 PM GMT -06:00 US/Canada Central
> Subject: Re: WicketNotSerializableException
>
> Can you show the code? When you create an anonymous inner class, it
> gets references to variables that are outside of the declaration.
>
> --
> Jeremy Thomerson
> http://www.wickettraining.com
>
>
>
>
> On Wed, Jul 29, 2009 at 5:46 PM, David
> Brown<db...@sexingtechnologies.com> wrote:
>> Hello, I have a small show-stopper with a WicketTester testcase and a Wicket Page. The Wicket Page is a concrete Class extending WebPage. I am calling a simple private method: init() that is nested within the Page constructor. Inside the init() method I have an anonymous inner class constructed from a composition: new SortableDataProvider{}; The target of the composition is assigned to an instance variable of ISortableDataProvider which requires that I must override the IModel model(final Object object) method. When I run Maven test on this Page I get the following error condition:
>>
>> org.apache.wicket.util.io.SerializableChecker$WicketNotSerializableException: Unable to serialize class: java.lang.Object
>>
>>
>> I have tried using strategic placement of: transient and static but of no use.
>>
>> Regards, David.
>>
>> ---------------------------------------------------------------------
>> 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
>
>
> ---------------------------------------------------------------------
> 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: WicketNotSerializableException
Posted by David Brown <db...@sexingtechnologies.com>.
Hello Jeremy, thanks for the reply. Please find the requested WebPage included below. At the cost of looking somewhat contrived I had to edit to keep the Lawyers happy. Yes, you're right (again), there are plenty of references outside the declaration but those also got: implements Serializable in a weak attempt to shut up the compiler. Please advise, David.
*******************************************************************
package com.technology.pages.myapp;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.apache.wicket.Component;
import org.apache.wicket.IPageMap;
import org.apache.wicket.MarkupContainer;
import org.apache.wicket.PageParameters;
import org.apache.wicket.behavior.HeaderContributor;
import org.apache.wicket.extensions.markup.html.repeater.data.table.DefaultDataTable;
import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn;
import org.apache.wicket.extensions.markup.html.repeater.data.table.ISortableDataProvider;
import org.apache.wicket.extensions.markup.html.repeater.data.table.PropertyColumn;
import org.apache.wicket.extensions.markup.html.repeater.data.table.filter.FilterForm;
import org.apache.wicket.extensions.markup.html.repeater.data.table.filter.FilteredAbstractColumn;
import org.apache.wicket.extensions.markup.html.repeater.util.SortableDataProvider;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.repeater.Item;
import org.apache.wicket.model.CompoundPropertyModel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.LoadableDetachableModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.spring.injection.annot.SpringBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.technology.dao.MyappDao;
import com.technology.dao.jdbc.MyappDaoJdbcDBConnSQL;
import com.technology.dao.jdbc.DBConnSQL;
import com.technology.model.Myapp;
import com.technology.pages.myapp.ActionsPanel;
import com.technology.pages.myapp.MyappEditPage;
public class MyappPage extends WebPage {
private static transient Logger log = LoggerFactory.getLogger(MyappPage.class);
//@SpringBean
private MyappDao myappDao;
public MyappPage() {
init();
}
private void init(){
//adding css
//add(HeaderContributor.forCss(MyappPage.class, "base.css")); // in 1.4 causes markup error
myappDao = new MyappDaoJdbcDBConnSQL();
if(myappDao == null && log.isDebugEnabled()) log.error("MyappPage.init().myappDao: null");
else log.info("MyappPage.init().myappDao: OK!");
final DBConnSQL dbc = new DBConnSQL();
final Connection conn = dbc.getConnection();
ISortableDataProvider dp = new SortableDataProvider(){
private static final long serialVersionUID = 1L;
@SuppressWarnings("unchecked")
public Iterator iterator(int first, int count) {
//final SortParam sort = getSort();
//do something with the sort param here to eg
//return baseDao.selectAllInRangeSorted(first, count, sort).iterator();
//sorting not currently implemented
return myappDao.getItems().iterator();
}
/*
* use LoadableDetachableModel so that objects aren't serialized, could use
* just a normal model if wasn't bothered about that eg
* return new Model(object);
*/
public IModel model(final Object object) {
return new LoadableDetachableModel(object){
private static final long serialVersionUID = 1L;
//private Long id = object.getClass().cast(Myapp);
@Override
protected List load() {
//return myappDao.getItem(id);
return myappDao.getItems();
}
};
}
public int size() {
return myappDao.getCount();
}
};
final List<IColumn> columns = new ArrayList<IColumn>();
//add column for the edit and delete links
columns.add(new FilteredAbstractColumn(new Model("actions")){
private static final long serialVersionUID = 1L;
public Component getFilter(String componentId, FilterForm form) {
return null;
}
public void populateItem(Item cellItem, String componentId, IModel rowModel) {
cellItem.add(new ActionsPanel(componentId, rowModel));
}
});
//sorting is not used on this
//all the columns dont fit
columns.add(new PropertyColumn(new Model("animalId"), "animalId", "animalId"));
columns.add(new PropertyColumn(new Model("itemCode"), "itemCode", "itemCode"));
columns.add(new PropertyColumn(new Model("brdCode"), "brdCode"));
columns.add(new PropertyColumn(new Model("itemName"), "itemName"));
columns.add(new PropertyColumn(new Model("AKAName"), "AKAName"));
columns.add(new PropertyColumn(new Model("brdIdNo"), "brdIdNo", "brdIdNo"));
columns.add(new PropertyColumn(new Model("statusIdNo"), "statusIdNo"));
columns.add(new PropertyColumn(new Model("regNo"), "regNo"));
columns.add(new PropertyColumn(new Model("sign"), "sign"));
/*
columns.add(new PropertyColumn(new Model("Tag"), "Tag"));
columns.add(new PropertyColumn(new Model("mastCatItem"), "mastCatItem"));
columns.add(new PropertyColumn(new Model("Country"), "Country"));
columns.add(new PropertyColumn(new Model("ID"), "itemId"));
columns.add(new PropertyColumn(new Model("birthDate"), "birthDate"));
columns.add(new PropertyColumn(new Model("sName"), "sName"));
columns.add(new PropertyColumn(new Model("RegNo"), "RegNo"));
columns.add(new PropertyColumn(new Model("dName"), "dName"));
columns.add(new PropertyColumn(new Model("dRegNo"), "dRegNo"));
columns.add(new PropertyColumn(new Model("bloodNo"), "bloodNo"));
columns.add(new PropertyColumn(new Model("DNo"), "DNo"));
columns.add(new PropertyColumn(new Model("notes"), "notes"));
columns.add(new PropertyColumn(new Model("lastModUser"), "lastModUser"));
columns.add(new PropertyColumn(new Model("lastModDate"), "lastModDate"));
*/
DefaultDataTable dataTable = new DefaultDataTable("dataTable", columns, dp, 20);
add(dataTable);
add(new Link("create"){
/**
*
*/
private static final long serialVersionUID = 1L;
@Override
public void onClick() {
setResponsePage(new MyappEditPage(getPage(), new CompoundPropertyModel(new Myapp())));
}
});
dbc.returnConnection(conn);
} // END INIT()
}
*******************************************************************
----- Original Message -----
From: "Jeremy Thomerson" <je...@wickettraining.com>
To: users@wicket.apache.org
Sent: Wednesday, July 29, 2009 5:57:35 PM GMT -06:00 US/Canada Central
Subject: Re: WicketNotSerializableException
Can you show the code? When you create an anonymous inner class, it
gets references to variables that are outside of the declaration.
--
Jeremy Thomerson
http://www.wickettraining.com
On Wed, Jul 29, 2009 at 5:46 PM, David
Brown<db...@sexingtechnologies.com> wrote:
> Hello, I have a small show-stopper with a WicketTester testcase and a Wicket Page. The Wicket Page is a concrete Class extending WebPage. I am calling a simple private method: init() that is nested within the Page constructor. Inside the init() method I have an anonymous inner class constructed from a composition: new SortableDataProvider{}; The target of the composition is assigned to an instance variable of ISortableDataProvider which requires that I must override the IModel model(final Object object) method. When I run Maven test on this Page I get the following error condition:
>
> org.apache.wicket.util.io.SerializableChecker$WicketNotSerializableException: Unable to serialize class: java.lang.Object
>
>
> I have tried using strategic placement of: transient and static but of no use.
>
> Regards, David.
>
> ---------------------------------------------------------------------
> 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
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: WicketNotSerializableException
Posted by Jeremy Thomerson <je...@wickettraining.com>.
Can you show the code? When you create an anonymous inner class, it
gets references to variables that are outside of the declaration.
--
Jeremy Thomerson
http://www.wickettraining.com
On Wed, Jul 29, 2009 at 5:46 PM, David
Brown<db...@sexingtechnologies.com> wrote:
> Hello, I have a small show-stopper with a WicketTester testcase and a Wicket Page. The Wicket Page is a concrete Class extending WebPage. I am calling a simple private method: init() that is nested within the Page constructor. Inside the init() method I have an anonymous inner class constructed from a composition: new SortableDataProvider{}; The target of the composition is assigned to an instance variable of ISortableDataProvider which requires that I must override the IModel model(final Object object) method. When I run Maven test on this Page I get the following error condition:
>
> org.apache.wicket.util.io.SerializableChecker$WicketNotSerializableException: Unable to serialize class: java.lang.Object
>
>
> I have tried using strategic placement of: transient and static but of no use.
>
> Regards, David.
>
> ---------------------------------------------------------------------
> 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