You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Java Programmer <jp...@gmail.com> on 2008/04/02 10:59:50 UTC

Problem with serializing objects

Hello,
We have problem with serializing webpages - the user session files
growing rapidly (each request about 100KB), we don't know what we have
did wrong - system is based on examples from wicket.apache.org, so it
should work but this large files (10-20MB for some time, after many
request) slows it down.
We have tried to put transient in all fields which we are use as
components on WebPages - it doesn't help.
Maybe I put some code and little explain and you can tell us whay is wrong.
The example will be consider LinkTree with 2000+ categories:
Categories we have as Hibernate Entity cached whole in ehcache in memory:
@Entity
@Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
public class Category implements Serializable {
	
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Integer id;
	
	private String name;
	
	private String description;
	
	@Enumerated(value = EnumType.STRING)
	private CategoryStatus categoryStatus;

	@ManyToOne(fetch=FetchType.EAGER)
	@JoinColumn(name="parent_id", insertable=false, updatable=false, nullable=true)
	@Cascade(org.hibernate.annotations.CascadeType.ALL)
	@Fetch(value=FetchMode.SELECT)
	@Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
	private Category parent;
	
	@OneToMany(fetch=FetchType.EAGER)
	@JoinColumn(name="parent_id")
	@Cascade(org.hibernate.annotations.CascadeType.ALL)
	@IndexColumn(name="list_id")
	@Fetch(value=FetchMode.SELECT)
	@Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
	private List<Category> children = new ArrayList<Category> ();
	
	@Index(name = "categoryPathIndex")
	private String categoryPath = "";
	
	public Category addChild(Category child) {
		child.parent = this;
		children.add(child);
		return this;
	}

//getters setters hashcode equals
}

Next we put the categories on panel as:
public class CategoryTreePanel extends Panel {

	private final transient Log LOG = LogFactory.getLog(CategoryTreePanel.class);
	
	private transient Category activeCategory;
	
	private transient TreeNode treeNode;

	private transient LinkTree tree;
	
    public CategoryTreePanel(String id, List<Category> rootCategory) {
    	this(id, rootCategory, null);
    }

    public CategoryTreePanel(String id, List<Category> rootCategory,
Category activeCategory) {
    	super(id);
    	LOG.info("activeCategory: " + activeCategory);
    	this.activeCategory = activeCategory;
    	tree = new CarPartsLinkTree("category_tree",
createTreeModel(rootCategory));
		tree.setRootLess(true);
		LOG.info("treeNode: " + treeNode);
		if(treeNode != null) {
			expandAllParentNodes(tree, treeNode);
			tree.getTreeState().selectNode(treeNode, true);
		} else {
			tree.getTreeState().collapseAll();
		}
		add(tree);
    }

    class CarPartsLinkTree extends LinkTree {

		public CarPartsLinkTree(String id, TreeModel model) {
			super(id, model);
		}
		
		@Override
		protected void onNodeLinkClicked(TreeNode node, BaseTree tree,
AjaxRequestTarget target) {
			super.onNodeLinkClicked(node, tree, target);
			int catId = ((CategoryTreeNode) ((DefaultMutableTreeNode)
node).getUserObject()).getCategory().getId();
			setRedirect(true);
			Page page = getPage();
			if(page instanceof AdvertismentsList || page instanceof AddAdvertisement) {
				setResponsePage(getPage().getClass(), new
PageParameters("category=" + catId));
			} else {
				setResponsePage(AdvertismentsList.class, new
PageParameters("category=" + catId));
			}
		}
		@Override
		protected ResourceReference getCSS() {
			return null;
		}
		
		protected Component newNodeComponent(String id, IModel model) {
			return new LinkIconPanel(id, model, CarPartsLinkTree.this) {
				private static final long serialVersionUID = 1L;
				
				protected void onNodeLinkClicked(TreeNode node, BaseTree tree,
AjaxRequestTarget target)
				{
					super.onNodeLinkClicked(node, tree, target);
					CarPartsLinkTree.this.onNodeLinkClicked(node, tree, target);
				}

				protected Component newContentComponent(String componentId,
BaseTree tree, IModel model)
				{
					return new Label(componentId, getNodeTextModel(model));
				}
				
				@Override
				protected ResourceReference getResourceFolderOpen(TreeNode node) {
					return new ResourceReference(CategoryTreePanel.class,
"res/folder-open.gif");
				}
				
				@Override
				protected ResourceReference getResourceFolderClosed(TreeNode node) {
					return new ResourceReference(CategoryTreePanel.class,
"res/folder-closed.gif");
				}
				
				@Override
				protected ResourceReference getResourceItemLeaf(TreeNode node) {
					return new ResourceReference(CategoryTreePanel.class, "res/item.gif");
				}
			};
		}
    }

    private void expandAllParentNodes(AbstractTree tree, TreeNode treeNode) {
    	tree.getTreeState().expandNode(treeNode);
    	if(treeNode.getParent() != null) {
    		expandAllParentNodes(tree, treeNode.getParent());
    	}
    }

    private TreeModel createTreeModel(List<Category> rootCategories) {
        TreeModel model = null;
        DefaultMutableTreeNode rootNode = new
DefaultMutableTreeNode("rootCategory");
        add(rootNode, rootCategories);
        model = new DefaultTreeModel(rootNode);
        return model;
    }

    private class CategoryTreeNode {
    	
    	private Category category;
    	
    	public CategoryTreeNode(Category category) {
			super();
			this.category = category;
		}

		public Category getCategory() {
			return category;
		}

		public void setCategory(Category category) {
			this.category = category;
		}

		public String toString() {
    		return category.getName();
    	}
    }

    private void add(DefaultMutableTreeNode parent, List<Category> sub) {
        for (Iterator<Category> i = sub.iterator(); i.hasNext();) {
        	Category category = i.next();
            DefaultMutableTreeNode child = new
DefaultMutableTreeNode(new CategoryTreeNode(category));
            parent.add(child);
        	if(category.equals(activeCategory)) {
        		treeNode = child;
        	}
            if(category.getChildren().size() > 0) {
            	add(child, category.getChildren());
            }
        }
    }

}

Next we put panel on the page:
public abstract class CommonWebPage extends WebPage {
	
	@SpringBean
	private transient SessionService sessionService;

	@SpringBean
	private transient CategoryDAO categoryDAO;
	
	//some reusabale elements
	public static final String ID_PARAMETER = "id";
	private static final String CATEGORY_PARAMETER = "category";
	public static final String EMPTY_STRING = "";
	
	public static final String EQUALS = "=";
	protected static final char DOT_SEPERATOR = '.';
	protected static final String[] ALLOWED_PICTURES_TYPES = new String[]
{"jpg", "gif", "jpeg", "png"};
	public static final String ONCHANGE_BEHAVIOR = "onchange";
	public static final String ONCLICK_BEHAVIOR = "onclick";

	//wicket:ids
	private static final String CATEGORIES = "categories";
	private static final String MAIN_MENU = "main_menu";
	protected static final String SEARCH_PANEL = "search_panel";
	
	static {
		Arrays.sort(ALLOWED_PICTURES_TYPES);
	}
	
	protected transient Category category;
	
	private transient Label categoryTreePanel;

	private transient Menu menu;
	
	public CommonWebPage(PageParameters pageParameters) {
		super();
		loginUserIfRemembered();
		if(pageParameters.get(CATEGORY_PARAMETER) != null) {
			category = categoryDAO.getCategoryById(Integer.parseInt((String)
pageParameters.get(CATEGORY_PARAMETER)));
		}
		menu = new Menu(MAIN_MENU, category, isUserLogin());
		add(menu);
		categoryTreePanel = new CategoryTreePanel(CATEGORIES,
categoryDAO.getRootCategories(), category);
		add(categoryTreePanel);
	}
....
}

This is first problem large data is kept in session which is same for
all users (TreeModel), what can be done? What is wrong?

Second problem is with serializing some objects which we don't want
and use LoadebaleDeatachableModel for them:
public class CarPartDataProvider implements IDataProvider{

	private transient CarPartService carPartService;
	
	private transient Category category;
		
	public CarPartDataProvider(CarPartService carPartService) {
		super();
		this.carPartService = carPartService;
	}

	public CarPartDataProvider(CarPartService carPartService, Category category) {
		super();
		this.carPartService = carPartService;
		this.category = category;
	}

	@SuppressWarnings("unchecked")
	@Override
	public Iterator iterator(int first, int count) {
		return carPartService.getCarParts(category, first, count).iterator();
	}

	@Override
	public IModel model(Object carPart) {
		return new CarPartDetachableModel((CarPart) carPart);
	}

	class CarPartDetachableModel extends LoadableDetachableModel {

		private Integer carPartId;

		public CarPartDetachableModel(CarPart carPart) {
			this.carPartId = carPart.getId();
		}
		
		@Override
		protected Object load() {
			return carPartService.getCarPartById(this.carPartId);
		}
	}
	
	@Override
	public int size() {
		return carPartService.getCarPartsSize(category);
	}

	@Override
	public void detach() {
	}

	public CarPartService getCarPartService() {
		return carPartService;
	}

	public void setCarPartService(CarPartService carPartService) {
		this.carPartService = carPartService;
	}

	public Category getCategory() {
		return category;
	}

	public void setCategory(Category category) {
		this.category = category;
	}

}
I have see CarPart objects in serialized form in sesion which is
really unwanted for us - we cache all the objects in Hibernate so we
can get them really fast, serialization is not we want. Also we have
problem witch web spiders - spiders do not use session so for each
request is generated new session :(
I think it's problem by our side, so we ask for little help with optimizing.

Best regards,
Adr

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


Re: Problem with serializing objects

Posted by Igor Vaynberg <ig...@gmail.com>.
omfg, you guys COULD just use PropertyListView

-igor


On Wed, Apr 2, 2008 at 5:55 AM, Maurice Marrink <ma...@gmail.com> wrote:
> You mean item.setModel(new CompoundPropertyModel(item.getModel()));, right? ;)
>
>  And no wicket does not keep string references, it uses models so it
>  won't have to. you are jut not using them correct.
>
>  Maurice
>
>
>
>  On Wed, Apr 2, 2008 at 1:58 PM, Java Programmer <jp...@gmail.com> wrote:
>  > After all the answers, I start to think that maybe my question was a bit wrong.
>  >  First I put all the hints you were provided into work eg:
>  >  item.setModel(new CompoundPropertyModel(item.getModelObject()));
>  >
>  > item.add(description = new MultiLineLabel(DESCRIPTION));
>  >  but still have in session files (pm-null) the text which is provided
>  >  to MultiLineLabel from model (detachable, and next compound) - I start
>  >  to think that Wicket always will be keep states of it's components, so
>  >  it's not kept the CarPart object but just a strings from
>  >  MultiLineLabel. Am I right with that or not?
>  >
>  >  The problem is that that files grows very fast (10MB is porobably a
>  >  limit becuse at that size it stops), and also what happens if another
>  >  user change the state of the object and write it into DB.
>  >
>  >  Best regards,
>  >  Adr
>  >
>  >
>  >
>  >  ---------------------------------------------------------------------
>  >  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: Problem with serializing objects

Posted by Maurice Marrink <ma...@gmail.com>.
You mean item.setModel(new CompoundPropertyModel(item.getModel()));, right? ;)

And no wicket does not keep string references, it uses models so it
won't have to. you are jut not using them correct.

Maurice

On Wed, Apr 2, 2008 at 1:58 PM, Java Programmer <jp...@gmail.com> wrote:
> After all the answers, I start to think that maybe my question was a bit wrong.
>  First I put all the hints you were provided into work eg:
>  item.setModel(new CompoundPropertyModel(item.getModelObject()));
>
> item.add(description = new MultiLineLabel(DESCRIPTION));
>  but still have in session files (pm-null) the text which is provided
>  to MultiLineLabel from model (detachable, and next compound) - I start
>  to think that Wicket always will be keep states of it's components, so
>  it's not kept the CarPart object but just a strings from
>  MultiLineLabel. Am I right with that or not?
>
>  The problem is that that files grows very fast (10MB is porobably a
>  limit becuse at that size it stops), and also what happens if another
>  user change the state of the object and write it into DB.
>
>  Best regards,
>  Adr
>
>
>
>  ---------------------------------------------------------------------
>  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: Problem with serializing objects

Posted by Johan Compagner <jc...@gmail.com>.
that 10MB what kind of file is that?
that is the pm-x file?
That always grows to 10MB but that is not the session size
That is a file that holds the last X pages that it can hold in 10MB

so yes by default it will always grow to 10MB as more and more pages will be
added and then it will truncate

johan


On Wed, Apr 2, 2008 at 1:58 PM, Java Programmer <jp...@gmail.com>
wrote:

> After all the answers, I start to think that maybe my question was a bit
> wrong.
> First I put all the hints you were provided into work eg:
> item.setModel(new CompoundPropertyModel(item.getModelObject()));
> item.add(description = new MultiLineLabel(DESCRIPTION));
> but still have in session files (pm-null) the text which is provided
> to MultiLineLabel from model (detachable, and next compound) - I start
> to think that Wicket always will be keep states of it's components, so
> it's not kept the CarPart object but just a strings from
> MultiLineLabel. Am I right with that or not?
>
> The problem is that that files grows very fast (10MB is porobably a
> limit becuse at that size it stops), and also what happens if another
> user change the state of the object and write it into DB.
>
> Best regards,
> Adr
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: Problem with serializing objects

Posted by Maurice Marrink <ma...@gmail.com>.
Actually i copied it from my next big commit for wicket, which i'll
send ........ now ;)
Oops i hope i did not forget to make that change.

Maurice

On Wed, Apr 2, 2008 at 1:45 PM, Martijn Dashorst
<ma...@gmail.com> wrote:
> On 4/2/08, Maurice Marrink <ma...@gmail.com> wrote:
>  >  Right Martijn :) quick copy paste error :)
>
>  I hope the copy didn't come from our code....
>
>  /me eyes his code base...
>
>  Martijn
>
>
>
>  ---------------------------------------------------------------------
>  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: Problem with serializing objects

Posted by Martijn Dashorst <ma...@gmail.com>.
item.setModel(....) I suppose?

On 4/2/08, Maurice Marrink <ma...@gmail.com> wrote:
> It should be:
>
> protected void populateItem(Item item)
>  {
>
> item.setModelObject(new CompoundPropertyModel(item.getModel()));
>  .....
>  }
>
>
>  Maurice
>
>
>  On Wed, Apr 2, 2008 at 1:23 PM, Java Programmer <jp...@gmail.com> wrote:
>  > I have narrowed my code to:
>  >
>  >         protected void populateItem(Item item) {
>  >
>  >                 final CarPart carPart = (CarPart) item.getModelObject();
>  >
>  >                 item.setModelObject(new CompoundPropertyModel(carPart));
>  >                 item.add(description = new MultiLineLabel(DESCRIPTION));
>  >         }
>  >  and get error about using read only model:
>  >  java.lang.UnsupportedOperationException: Model class
>  >  parts.car.wicket.models.CarPartDetachableModel does not support
>  >  setObject(Object)
>  >      at org.apache.wicket.model.AbstractReadOnlyModel.setObject(AbstractReadOnlyModel.java:52)
>  >  What model could I use instead of LoadableDetachedModel?
>  >
>  >
>  >
>  >  Regards,
>  >  Adr
>  >
>  >  ---------------------------------------------------------------------
>  >  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
>
>


-- 
Buy Wicket in Action: http://manning.com/dashorst
Apache Wicket 1.3.2 is released
Get it now: http://www.apache.org/dyn/closer.cgi/wicket/1.3.2

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


Re: Problem with serializing objects

Posted by Java Programmer <jp...@gmail.com>.
After all the answers, I start to think that maybe my question was a bit wrong.
First I put all the hints you were provided into work eg:
item.setModel(new CompoundPropertyModel(item.getModelObject()));
item.add(description = new MultiLineLabel(DESCRIPTION));
but still have in session files (pm-null) the text which is provided
to MultiLineLabel from model (detachable, and next compound) - I start
to think that Wicket always will be keep states of it's components, so
it's not kept the CarPart object but just a strings from
MultiLineLabel. Am I right with that or not?

The problem is that that files grows very fast (10MB is porobably a
limit becuse at that size it stops), and also what happens if another
user change the state of the object and write it into DB.

Best regards,
Adr

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


Re: Problem with serializing objects

Posted by Martijn Dashorst <ma...@gmail.com>.
On 4/2/08, Maurice Marrink <ma...@gmail.com> wrote:
>  Right Martijn :) quick copy paste error :)

I hope the copy didn't come from our code....

/me eyes his code base...

Martijn

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


Re: Problem with serializing objects

Posted by Maurice Marrink <ma...@gmail.com>.
Oh and just in case you were using your carpart object somewhere else
in onpopulate.
Never use final on your jpa objects, instead if you must you can use
final on the model (or the item if you are in a list view)

Right Martijn :) quick copy paste error :)

Maurice

On Wed, Apr 2, 2008 at 1:35 PM, Maurice Marrink <ma...@gmail.com> wrote:
> It should be:
>
> protected void populateItem(Item item)
>  {
>  item.setModelObject(new CompoundPropertyModel(item.getModel()));
>  .....
>  }
>
>  Maurice
>
>
>
>  On Wed, Apr 2, 2008 at 1:23 PM, Java Programmer <jp...@gmail.com> wrote:
>  > I have narrowed my code to:
>  >
>  >         protected void populateItem(Item item) {
>  >
>  >                 final CarPart carPart = (CarPart) item.getModelObject();
>  >
>  >                 item.setModelObject(new CompoundPropertyModel(carPart));
>  >                 item.add(description = new MultiLineLabel(DESCRIPTION));
>  >         }
>  >  and get error about using read only model:
>  >  java.lang.UnsupportedOperationException: Model class
>  >  parts.car.wicket.models.CarPartDetachableModel does not support
>  >  setObject(Object)
>  >      at org.apache.wicket.model.AbstractReadOnlyModel.setObject(AbstractReadOnlyModel.java:52)
>  >  What model could I use instead of LoadableDetachedModel?
>  >
>  >
>  >
>  >  Regards,
>  >  Adr
>  >
>  >  ---------------------------------------------------------------------
>  >  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: Problem with serializing objects

Posted by Maurice Marrink <ma...@gmail.com>.
It should be:
protected void populateItem(Item item)
{
item.setModelObject(new CompoundPropertyModel(item.getModel()));
.....
}

Maurice

On Wed, Apr 2, 2008 at 1:23 PM, Java Programmer <jp...@gmail.com> wrote:
> I have narrowed my code to:
>
>         protected void populateItem(Item item) {
>
>                 final CarPart carPart = (CarPart) item.getModelObject();
>
>                 item.setModelObject(new CompoundPropertyModel(carPart));
>                 item.add(description = new MultiLineLabel(DESCRIPTION));
>         }
>  and get error about using read only model:
>  java.lang.UnsupportedOperationException: Model class
>  parts.car.wicket.models.CarPartDetachableModel does not support
>  setObject(Object)
>      at org.apache.wicket.model.AbstractReadOnlyModel.setObject(AbstractReadOnlyModel.java:52)
>  What model could I use instead of LoadableDetachedModel?
>
>
>
>  Regards,
>  Adr
>
>  ---------------------------------------------------------------------
>  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: Problem with serializing objects

Posted by Java Programmer <jp...@gmail.com>.
I have narrowed my code to:
	protected void populateItem(Item item) {
		final CarPart carPart = (CarPart) item.getModelObject();
		item.setModelObject(new CompoundPropertyModel(carPart));
		item.add(description = new MultiLineLabel(DESCRIPTION));
	}
and get error about using read only model:
java.lang.UnsupportedOperationException: Model class
parts.car.wicket.models.CarPartDetachableModel does not support
setObject(Object)
     at org.apache.wicket.model.AbstractReadOnlyModel.setObject(AbstractReadOnlyModel.java:52)
What model could I use instead of LoadableDetachedModel?

Regards,
Adr

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


Re: Problem with serializing objects

Posted by Nino Saturnino Martinez Vazquez Wael <ni...@jayway.dk>.

Nino Saturnino Martinez Vazquez Wael wrote:
>
>
> Java Programmer wrote:
>> I'm little confused now about not using detachable model in places you
>> have marked - I have in first place to pull the object from item:
>>   
> Yup thats right. But after that you use that CarPart object raw. When 
> you provide it to the components...
>> final CarPart carPart = (CarPart) item.getModelObject();
>> which is load() object correctly - i tested it by quickly putting:
>>         @Override
>>         protected Object load() {
>>             System.out.println("\n\n\n LOAD object: " + 
>> this.carPartId + "\n\n\n");
>>             return carPartService.getCarPartById(this.carPartId);
>>         }
>> for 3 elements on the page I got in logs:
>>  LOAD object: 13
>>
>>  LOAD object: 12
>>
>>  LOAD object: 2
>> So I think deatachable model is used here? Am I wrong?
>>   
> I believe youre wrong.
>    item.add(price = new Label(PRICE, carPart.getPrice().toString()));
> Carpart is not a detachable model right?
and further more, toString isnt..
>
>> If I want to use item.setModelObject(new
>> CompoundPropertyModel(carPart)); how can I get netsted object in:
>> carPart.getCarModel().getModelName()
>>
>>   
> Something like this:  new 
> PropertyModel(myCompoundPropertyModel(mydetachableModel).bind("carModel"),"modelName"); 
>
>
> It's very important that you chain the models, otherwise you'll still 
> not use the detachablemodel... Like my previous example:
>
> item.setModel(new CompoundModel(item.getModel()));
>
>
>> Best regards,
>> Adr
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>>   
>

-- 
-Wicket for love

Nino Martinez Wael
Java Specialist @ Jayway DK
http://www.jayway.dk
+45 2936 7684


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


Re: Problem with serializing objects

Posted by Nino Saturnino Martinez Vazquez Wael <ni...@jayway.dk>.

Java Programmer wrote:
> I'm little confused now about not using detachable model in places you
> have marked - I have in first place to pull the object from item:
>   
Yup thats right. But after that you use that CarPart object raw. When 
you provide it to the components...
> final CarPart carPart = (CarPart) item.getModelObject();
> which is load() object correctly - i tested it by quickly putting:
> 		@Override
> 		protected Object load() {
> 			System.out.println("\n\n\n LOAD object: " + this.carPartId + "\n\n\n");
> 			return carPartService.getCarPartById(this.carPartId);
> 		}
> for 3 elements on the page I got in logs:
>  LOAD object: 13
>
>  LOAD object: 12
>
>  LOAD object: 2
> So I think deatachable model is used here? Am I wrong?
>   
I believe youre wrong.
    item.add(price = new Label(PRICE, carPart.getPrice().toString()));
Carpart is not a detachable model right?
> If I want to use item.setModelObject(new
> CompoundPropertyModel(carPart)); how can I get netsted object in:
> carPart.getCarModel().getModelName()
>
>   
Something like this:  new 
PropertyModel(myCompoundPropertyModel(mydetachableModel).bind("carModel"),"modelName");

It's very important that you chain the models, otherwise you'll still 
not use the detachablemodel... Like my previous example:

item.setModel(new CompoundModel(item.getModel()));


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

-- 
-Wicket for love

Nino Martinez Wael
Java Specialist @ Jayway DK
http://www.jayway.dk
+45 2936 7684


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


Re: Problem with serializing objects

Posted by Java Programmer <jp...@gmail.com>.
I'm little confused now about not using detachable model in places you
have marked - I have in first place to pull the object from item:
final CarPart carPart = (CarPart) item.getModelObject();
which is load() object correctly - i tested it by quickly putting:
		@Override
		protected Object load() {
			System.out.println("\n\n\n LOAD object: " + this.carPartId + "\n\n\n");
			return carPartService.getCarPartById(this.carPartId);
		}
for 3 elements on the page I got in logs:
 LOAD object: 13

 LOAD object: 12

 LOAD object: 2
So I think deatachable model is used here? Am I wrong?

If I want to use item.setModelObject(new
CompoundPropertyModel(carPart)); how can I get netsted object in:
carPart.getCarModel().getModelName()

Best regards,
Adr

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


Re: Problem with serializing objects

Posted by Nino Saturnino Martinez Vazquez Wael <ni...@jayway.dk>.
And this way to wrap the detachablemodel:


item.setModel(new CompoundModel(item.getModel()));

Im a little quick on the trigger today..

Nino Saturnino Martinez Vazquez Wael wrote:
> And dada, I of course meant compoundpropertymodel.
>
> Nino Saturnino Martinez Vazquez Wael wrote:
>> How large are the size of your list? Generally you use raw string 
>> values instead of detachablemodels..'
>>
>> I'd suggest doing it another way, by using a compoundmodel:
>>
>>     protected void populateItem(Item item) {
>>         final CarPart carPart = (CarPart) item.getModelObject();
>> item.setModelObject(new CompoundModel(carPart));
>>
>> item.add(price = new Label(PRICE));
>> item.add(publishDate = new Label(PUBLISHDATE));
>>
>> etc...
>>
>>
>>
>>
>>
>> Java Programmer wrote:
>>> On Wed, Apr 2, 2008 at 11:38 AM, Nino Saturnino Martinez Vazquez Wael
>>> <ni...@jayway.dk> wrote:
>>>  
>>>> Are you really sure that your detachablemodels are being used all 
>>>> over?
>>>>     
>>>
>>> We create it in CarPartDataProvider from my first post, next we create
>>> DataView based on this provider we implement populate method as:
>>>     @Override
>>>     protected void populateItem(Item item) {
>>>         final CarPart carPart = (CarPart) item.getModelObject();
>>>         if (carPart.getCarModel() != null) {
>>>             item.add(carModel = new Label(CARMODEL,
>>> carPart.getCarModel().getModelName()));
>>>   
>> detachable model not used
>>>         } else {
>>>             item.add(carModel = new Label(CARMODEL,
>>> getString(ADVERT_LIST_NOMODEL_KEY)));
>>>   
>> detachable model not used
>>>         }
>>>         item.add(price = new Label(PRICE, 
>>> carPart.getPrice().toString()));
>>>   
>> detachable model not used
>>>         item.add(publishDate = new Label(PUBLISHDATE,
>>> carPart.getPublishDate().toString()));
>>>   
>> detachable model not used
>>>     ....
>>> }
>>> Is this the correct way to obtain object from provider ->
>>> item.getModelObject(); is it use LoadableDetachableModel from
>>> provider?
>>> We do not ask for CarParts objects in other places, only these 3
>>> classes (provider, model and webpage view as data view), but still see
>>> large CarPart objects in session.
>>> Any idea?
>>>
>>> Best regards,
>>> Adr
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>
>>>
>>>   
>>
>

-- 
-Wicket for love

Nino Martinez Wael
Java Specialist @ Jayway DK
http://www.jayway.dk
+45 2936 7684


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


Re: Problem with serializing objects

Posted by Nino Saturnino Martinez Vazquez Wael <ni...@jayway.dk>.
And dada, I of course meant compoundpropertymodel.

Nino Saturnino Martinez Vazquez Wael wrote:
> How large are the size of your list? Generally you use raw string 
> values instead of detachablemodels..'
>
> I'd suggest doing it another way, by using a compoundmodel:
>
>     protected void populateItem(Item item) {
>         final CarPart carPart = (CarPart) item.getModelObject();
> item.setModelObject(new CompoundModel(carPart));
>
> item.add(price = new Label(PRICE));
> item.add(publishDate = new Label(PUBLISHDATE));
>
> etc...
>
>
>
>
>
> Java Programmer wrote:
>> On Wed, Apr 2, 2008 at 11:38 AM, Nino Saturnino Martinez Vazquez Wael
>> <ni...@jayway.dk> wrote:
>>  
>>> Are you really sure that your detachablemodels are being used all over?
>>>     
>>
>> We create it in CarPartDataProvider from my first post, next we create
>> DataView based on this provider we implement populate method as:
>>     @Override
>>     protected void populateItem(Item item) {
>>         final CarPart carPart = (CarPart) item.getModelObject();
>>         if (carPart.getCarModel() != null) {
>>             item.add(carModel = new Label(CARMODEL,
>> carPart.getCarModel().getModelName()));
>>   
> detachable model not used
>>         } else {
>>             item.add(carModel = new Label(CARMODEL,
>> getString(ADVERT_LIST_NOMODEL_KEY)));
>>   
> detachable model not used
>>         }
>>         item.add(price = new Label(PRICE, 
>> carPart.getPrice().toString()));
>>   
> detachable model not used
>>         item.add(publishDate = new Label(PUBLISHDATE,
>> carPart.getPublishDate().toString()));
>>   
> detachable model not used
>>     ....
>> }
>> Is this the correct way to obtain object from provider ->
>> item.getModelObject(); is it use LoadableDetachableModel from
>> provider?
>> We do not ask for CarParts objects in other places, only these 3
>> classes (provider, model and webpage view as data view), but still see
>> large CarPart objects in session.
>> Any idea?
>>
>> Best regards,
>> Adr
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>>   
>

-- 
-Wicket for love

Nino Martinez Wael
Java Specialist @ Jayway DK
http://www.jayway.dk
+45 2936 7684


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


Re: Problem with serializing objects

Posted by Nino Saturnino Martinez Vazquez Wael <ni...@jayway.dk>.
How large are the size of your list? Generally you use raw string values 
instead of detachablemodels..'

I'd suggest doing it another way, by using a compoundmodel:

	protected void populateItem(Item item) {
		final CarPart carPart = (CarPart) item.getModelObject();
item.setModelObject(new CompoundModel(carPart));

item.add(price = new Label(PRICE));
item.add(publishDate = new Label(PUBLISHDATE));

etc...
 




Java Programmer wrote:
> On Wed, Apr 2, 2008 at 11:38 AM, Nino Saturnino Martinez Vazquez Wael
> <ni...@jayway.dk> wrote:
>   
>> Are you really sure that your detachablemodels are being used all over?
>>     
>
> We create it in CarPartDataProvider from my first post, next we create
> DataView based on this provider we implement populate method as:
> 	@Override
> 	protected void populateItem(Item item) {
> 		final CarPart carPart = (CarPart) item.getModelObject();
> 		if (carPart.getCarModel() != null) {
> 			item.add(carModel = new Label(CARMODEL,
> carPart.getCarModel().getModelName()));
>   
detachable model not used
> 		} else {
> 			item.add(carModel = new Label(CARMODEL,
> getString(ADVERT_LIST_NOMODEL_KEY)));
>   
detachable model not used
> 		}
> 		item.add(price = new Label(PRICE, carPart.getPrice().toString()));
>   
detachable model not used
> 		item.add(publishDate = new Label(PUBLISHDATE,
> carPart.getPublishDate().toString()));
>   
detachable model not used
>     ....
> }
> Is this the correct way to obtain object from provider ->
> item.getModelObject(); is it use LoadableDetachableModel from
> provider?
> We do not ask for CarParts objects in other places, only these 3
> classes (provider, model and webpage view as data view), but still see
> large CarPart objects in session.
> Any idea?
>
> Best regards,
> Adr
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
>   

-- 
-Wicket for love

Nino Martinez Wael
Java Specialist @ Jayway DK
http://www.jayway.dk
+45 2936 7684


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


Re: Problem with serializing objects

Posted by Java Programmer <jp...@gmail.com>.
On Wed, Apr 2, 2008 at 11:38 AM, Nino Saturnino Martinez Vazquez Wael
<ni...@jayway.dk> wrote:
> Are you really sure that your detachablemodels are being used all over?

We create it in CarPartDataProvider from my first post, next we create
DataView based on this provider we implement populate method as:
	@Override
	protected void populateItem(Item item) {
		final CarPart carPart = (CarPart) item.getModelObject();
		if (carPart.getCarModel() != null) {
			item.add(carModel = new Label(CARMODEL,
carPart.getCarModel().getModelName()));
		} else {
			item.add(carModel = new Label(CARMODEL,
getString(ADVERT_LIST_NOMODEL_KEY)));
		}
		item.add(price = new Label(PRICE, carPart.getPrice().toString()));
		item.add(publishDate = new Label(PUBLISHDATE,
carPart.getPublishDate().toString()));
    ....
}
Is this the correct way to obtain object from provider ->
item.getModelObject(); is it use LoadableDetachableModel from
provider?
We do not ask for CarParts objects in other places, only these 3
classes (provider, model and webpage view as data view), but still see
large CarPart objects in session.
Any idea?

Best regards,
Adr

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


Re: Problem with serializing objects

Posted by Nino Saturnino Martinez Vazquez Wael <ni...@jayway.dk>.
Are you really sure that your detachablemodels are being used all over?

Java Programmer wrote:
> On Wed, Apr 2, 2008 at 11:15 AM, Ayodeji Aladejebi <al...@gmail.com> wrote:
>   
>> from JPA experience, eager loading of List of Entities is part of what hogs
>>  memory. I have profiles an application before that the memory  usage just
>>  kept growing each time my page reference a particular entity that eager
>>  loads other collection of entities. As soon as I removed the eager load
>>  annotation, my memory usage became quite stable.
>>     
> Thanks but we tried also with LAZY
> @Entity
> @Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
> public class Category implements Serializable {
> 	
> 	@Id
> 	@GeneratedValue(strategy = GenerationType.AUTO)
> 	private Integer id;
> 	
> 	private String name;
> 	
> 	private String description;
> 	
> 	@Enumerated(value = EnumType.STRING)
> 	private CategoryStatus categoryStatus;
>
> 	@ManyToOne(fetch=FetchType.LAZY)
> 	@JoinColumn(name="parent_id", insertable=false, updatable=false, nullable=true)
> 	@Cascade(org.hibernate.annotations.CascadeType.ALL)
> 	@Fetch(value=FetchMode.SELECT)
> 	@Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
> 	private Category parent;
> 	
> 	@OneToMany(fetch=FetchType.LAZY)
> 	@JoinColumn(name="parent_id")
> 	@Cascade(org.hibernate.annotations.CascadeType.ALL)
> 	@IndexColumn(name="list_id")
> 	@Fetch(value=FetchMode.SELECT)
> 	@Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
> 	private List<Category> children = new ArrayList<Category> ();
> 	
> 	@Index(name = "categoryPathIndex")
> 	private String categoryPath = "";
>
>         ....
> }
>
> and OpenSessionInView in webxml:
>   <filter>
>     <filter-name>OpenSessionInViewFilter</filter-name>
>     <filter-class>com.test.CarPartsOpenSessionInViewFilter</filter-class>
>   </filter>
>
>   <filter-mapping>
>     <filter-name>OpenSessionInViewFilter</filter-name>
>     <url-pattern>/*</url-pattern>
>   </filter-mapping>
>
> but the results were quite same - large sesion file each request took
> about 100kB more in size, I tried also versioning compontent to false:
> categoryTreePanel = new CategoryTreePanel(CATEGORIES,
> categoryDAO.getRootCategories(), category);
> categoryTreePanel.setVersioned(false);
> nothing happens ... we are quite afraid of this behaviour ...
>
> Regards,
> Adr
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
>   

-- 
-Wicket for love

Nino Martinez Wael
Java Specialist @ Jayway DK
http://www.jayway.dk
+45 2936 7684


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


Re: Problem with serializing objects

Posted by Java Programmer <jp...@gmail.com>.
On Wed, Apr 2, 2008 at 11:15 AM, Ayodeji Aladejebi <al...@gmail.com> wrote:
> from JPA experience, eager loading of List of Entities is part of what hogs
>  memory. I have profiles an application before that the memory  usage just
>  kept growing each time my page reference a particular entity that eager
>  loads other collection of entities. As soon as I removed the eager load
>  annotation, my memory usage became quite stable.
Thanks but we tried also with LAZY
@Entity
@Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
public class Category implements Serializable {
	
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Integer id;
	
	private String name;
	
	private String description;
	
	@Enumerated(value = EnumType.STRING)
	private CategoryStatus categoryStatus;

	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="parent_id", insertable=false, updatable=false, nullable=true)
	@Cascade(org.hibernate.annotations.CascadeType.ALL)
	@Fetch(value=FetchMode.SELECT)
	@Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
	private Category parent;
	
	@OneToMany(fetch=FetchType.LAZY)
	@JoinColumn(name="parent_id")
	@Cascade(org.hibernate.annotations.CascadeType.ALL)
	@IndexColumn(name="list_id")
	@Fetch(value=FetchMode.SELECT)
	@Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
	private List<Category> children = new ArrayList<Category> ();
	
	@Index(name = "categoryPathIndex")
	private String categoryPath = "";

        ....
}

and OpenSessionInView in webxml:
  <filter>
    <filter-name>OpenSessionInViewFilter</filter-name>
    <filter-class>com.test.CarPartsOpenSessionInViewFilter</filter-class>
  </filter>

  <filter-mapping>
    <filter-name>OpenSessionInViewFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>

but the results were quite same - large sesion file each request took
about 100kB more in size, I tried also versioning compontent to false:
categoryTreePanel = new CategoryTreePanel(CATEGORIES,
categoryDAO.getRootCategories(), category);
categoryTreePanel.setVersioned(false);
nothing happens ... we are quite afraid of this behaviour ...

Regards,
Adr

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


Re: Problem with serializing objects

Posted by Ayodeji Aladejebi <al...@gmail.com>.
from JPA experience, eager loading of List of Entities is part of what hogs
memory. I have profiles an application before that the memory  usage just
kept growing each time my page reference a particular entity that eager
loads other collection of entities. As soon as I removed the eager load
annotation, my memory usage became quite stable.

if you need the reference your collections, just take another trip to the
database and fetch them.

Beware of some JPA providers, they also hog memory too.

I am not saying this is the problem in your case, yu may choose to look into
it and give that a try.


just dropped by

cheers

dabar

On 4/2/08, Java Programmer <jp...@gmail.com> wrote:
>
> Hello,
> We have problem with serializing webpages - the user session files
> growing rapidly (each request about 100KB), we don't know what we have
> did wrong - system is based on examples from wicket.apache.org, so it
> should work but this large files (10-20MB for some time, after many
> request) slows it down.
> We have tried to put transient in all fields which we are use as
> components on WebPages - it doesn't help.
> Maybe I put some code and little explain and you can tell us whay is
> wrong.
> The example will be consider LinkTree with 2000+ categories:
> Categories we have as Hibernate Entity cached whole in ehcache in memory:
> @Entity
> @Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
> public class Category implements Serializable {
>
>         @Id
>         @GeneratedValue(strategy = GenerationType.AUTO)
>         private Integer id;
>
>         private String name;
>
>         private String description;
>
>         @Enumerated(value = EnumType.STRING)
>         private CategoryStatus categoryStatus;
>
>         @ManyToOne(fetch=FetchType.EAGER)
>         @JoinColumn(name="parent_id", insertable=false, updatable=false,
> nullable=true)
>         @Cascade(org.hibernate.annotations.CascadeType.ALL)
>         @Fetch(value=FetchMode.SELECT)
>         @Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
>         private Category parent;
>
>         @OneToMany(fetch=FetchType.EAGER)
>         @JoinColumn(name="parent_id")
>         @Cascade(org.hibernate.annotations.CascadeType.ALL)
>         @IndexColumn(name="list_id")
>         @Fetch(value=FetchMode.SELECT)
>         @Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
>         private List<Category> children = new ArrayList<Category> ();
>
>         @Index(name = "categoryPathIndex")
>         private String categoryPath = "";
>
>         public Category addChild(Category child) {
>                 child.parent = this;
>                 children.add(child);
>                 return this;
>         }
>
> //getters setters hashcode equals
> }
>
> Next we put the categories on panel as:
> public class CategoryTreePanel extends Panel {
>
>         private final transient Log LOG =
> LogFactory.getLog(CategoryTreePanel.class);
>
>         private transient Category activeCategory;
>
>         private transient TreeNode treeNode;
>
>         private transient LinkTree tree;
>
>     public CategoryTreePanel(String id, List<Category> rootCategory) {
>         this(id, rootCategory, null);
>     }
>
>     public CategoryTreePanel(String id, List<Category> rootCategory,
> Category activeCategory) {
>         super(id);
>         LOG.info("activeCategory: " + activeCategory);
>         this.activeCategory = activeCategory;
>         tree = new CarPartsLinkTree("category_tree",
> createTreeModel(rootCategory));
>                 tree.setRootLess(true);
>                 LOG.info("treeNode: " + treeNode);
>                 if(treeNode != null) {
>                         expandAllParentNodes(tree, treeNode);
>                         tree.getTreeState().selectNode(treeNode, true);
>                 } else {
>                         tree.getTreeState().collapseAll();
>                 }
>                 add(tree);
>     }
>
>     class CarPartsLinkTree extends LinkTree {
>
>                 public CarPartsLinkTree(String id, TreeModel model) {
>                         super(id, model);
>                 }
>
>                 @Override
>                 protected void onNodeLinkClicked(TreeNode node, BaseTree
> tree,
> AjaxRequestTarget target) {
>                         super.onNodeLinkClicked(node, tree, target);
>                         int catId = ((CategoryTreeNode)
> ((DefaultMutableTreeNode)
> node).getUserObject()).getCategory().getId();
>                         setRedirect(true);
>                         Page page = getPage();
>                         if(page instanceof AdvertismentsList || page
> instanceof AddAdvertisement) {
>                                 setResponsePage(getPage().getClass(), new
> PageParameters("category=" + catId));
>                         } else {
>                                 setResponsePage(AdvertismentsList.class,
> new
> PageParameters("category=" + catId));
>                         }
>                 }
>                 @Override
>                 protected ResourceReference getCSS() {
>                         return null;
>                 }
>
>                 protected Component newNodeComponent(String id, IModel
> model) {
>                         return new LinkIconPanel(id, model,
> CarPartsLinkTree.this) {
>                                 private static final long serialVersionUID
> = 1L;
>
>                                 protected void onNodeLinkClicked(TreeNode
> node, BaseTree tree,
> AjaxRequestTarget target)
>                                 {
>                                         super.onNodeLinkClicked(node,
> tree, target);
>                                         CarPartsLinkTree.this.onNodeLinkClicked(node,
> tree, target);
>                                 }
>
>                                 protected Component
> newContentComponent(String componentId,
> BaseTree tree, IModel model)
>                                 {
>                                         return new Label(componentId,
> getNodeTextModel(model));
>                                 }
>
>                                 @Override
>                                 protected ResourceReference
> getResourceFolderOpen(TreeNode node) {
>                                         return new
> ResourceReference(CategoryTreePanel.class,
> "res/folder-open.gif");
>                                 }
>
>                                 @Override
>                                 protected ResourceReference
> getResourceFolderClosed(TreeNode node) {
>                                         return new
> ResourceReference(CategoryTreePanel.class,
> "res/folder-closed.gif");
>                                 }
>
>                                 @Override
>                                 protected ResourceReference
> getResourceItemLeaf(TreeNode node) {
>                                         return new
> ResourceReference(CategoryTreePanel.class, "res/item.gif");
>                                 }
>                         };
>                 }
>     }
>
>     private void expandAllParentNodes(AbstractTree tree, TreeNode
> treeNode) {
>         tree.getTreeState().expandNode(treeNode);
>         if(treeNode.getParent() != null) {
>                 expandAllParentNodes(tree, treeNode.getParent());
>         }
>     }
>
>     private TreeModel createTreeModel(List<Category> rootCategories) {
>         TreeModel model = null;
>         DefaultMutableTreeNode rootNode = new
> DefaultMutableTreeNode("rootCategory");
>         add(rootNode, rootCategories);
>         model = new DefaultTreeModel(rootNode);
>         return model;
>     }
>
>     private class CategoryTreeNode {
>
>         private Category category;
>
>         public CategoryTreeNode(Category category) {
>                         super();
>                         this.category = category;
>                 }
>
>                 public Category getCategory() {
>                         return category;
>                 }
>
>                 public void setCategory(Category category) {
>                         this.category = category;
>                 }
>
>                 public String toString() {
>                 return category.getName();
>         }
>     }
>
>     private void add(DefaultMutableTreeNode parent, List<Category> sub) {
>         for (Iterator<Category> i = sub.iterator(); i.hasNext();) {
>                 Category category = i.next();
>             DefaultMutableTreeNode child = new
> DefaultMutableTreeNode(new CategoryTreeNode(category));
>             parent.add(child);
>                 if(category.equals(activeCategory)) {
>                         treeNode = child;
>                 }
>             if(category.getChildren().size() > 0) {
>                 add(child, category.getChildren());
>             }
>         }
>     }
>
> }
>
> Next we put panel on the page:
> public abstract class CommonWebPage extends WebPage {
>
>         @SpringBean
>         private transient SessionService sessionService;
>
>         @SpringBean
>         private transient CategoryDAO categoryDAO;
>
>         //some reusabale elements
>         public static final String ID_PARAMETER = "id";
>         private static final String CATEGORY_PARAMETER = "category";
>         public static final String EMPTY_STRING = "";
>
>         public static final String EQUALS = "=";
>         protected static final char DOT_SEPERATOR = '.';
>         protected static final String[] ALLOWED_PICTURES_TYPES = new
> String[]
> {"jpg", "gif", "jpeg", "png"};
>         public static final String ONCHANGE_BEHAVIOR = "onchange";
>         public static final String ONCLICK_BEHAVIOR = "onclick";
>
>         //wicket:ids
>         private static final String CATEGORIES = "categories";
>         private static final String MAIN_MENU = "main_menu";
>         protected static final String SEARCH_PANEL = "search_panel";
>
>         static {
>                 Arrays.sort(ALLOWED_PICTURES_TYPES);
>         }
>
>         protected transient Category category;
>
>         private transient Label categoryTreePanel;
>
>         private transient Menu menu;
>
>         public CommonWebPage(PageParameters pageParameters) {
>                 super();
>                 loginUserIfRemembered();
>                 if(pageParameters.get(CATEGORY_PARAMETER) != null) {
>                         category =
> categoryDAO.getCategoryById(Integer.parseInt((String)
> pageParameters.get(CATEGORY_PARAMETER)));
>                 }
>                 menu = new Menu(MAIN_MENU, category, isUserLogin());
>                 add(menu);
>                 categoryTreePanel = new CategoryTreePanel(CATEGORIES,
> categoryDAO.getRootCategories(), category);
>                 add(categoryTreePanel);
>         }
> ....
> }
>
> This is first problem large data is kept in session which is same for
> all users (TreeModel), what can be done? What is wrong?
>
> Second problem is with serializing some objects which we don't want
> and use LoadebaleDeatachableModel for them:
> public class CarPartDataProvider implements IDataProvider{
>
>         private transient CarPartService carPartService;
>
>         private transient Category category;
>
>         public CarPartDataProvider(CarPartService carPartService) {
>                 super();
>                 this.carPartService = carPartService;
>         }
>
>         public CarPartDataProvider(CarPartService carPartService, Category
> category) {
>                 super();
>                 this.carPartService = carPartService;
>                 this.category = category;
>         }
>
>         @SuppressWarnings("unchecked")
>         @Override
>         public Iterator iterator(int first, int count) {
>                 return carPartService.getCarParts(category, first,
> count).iterator();
>         }
>
>         @Override
>         public IModel model(Object carPart) {
>                 return new CarPartDetachableModel((CarPart) carPart);
>         }
>
>         class CarPartDetachableModel extends LoadableDetachableModel {
>
>                 private Integer carPartId;
>
>                 public CarPartDetachableModel(CarPart carPart) {
>                         this.carPartId = carPart.getId();
>                 }
>
>                 @Override
>                 protected Object load() {
>                         return
> carPartService.getCarPartById(this.carPartId);
>                 }
>         }
>
>         @Override
>         public int size() {
>                 return carPartService.getCarPartsSize(category);
>         }
>
>         @Override
>         public void detach() {
>         }
>
>         public CarPartService getCarPartService() {
>                 return carPartService;
>         }
>
>         public void setCarPartService(CarPartService carPartService) {
>                 this.carPartService = carPartService;
>         }
>
>         public Category getCategory() {
>                 return category;
>         }
>
>         public void setCategory(Category category) {
>                 this.category = category;
>         }
>
> }
> I have see CarPart objects in serialized form in sesion which is
> really unwanted for us - we cache all the objects in Hibernate so we
> can get them really fast, serialization is not we want. Also we have
> problem witch web spiders - spiders do not use session so for each
> request is generated new session :(
> I think it's problem by our side, so we ask for little help with
> optimizing.
>
> Best regards,
> Adr
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>


-- 
Aladejebi Ayodeji A.,
DabarObjects Solutions
Phone: +234 9 481 7 156
Mobile: +234 803 589 1780
Email: deji@dabarobjects.com
Web: www.dabarobjects.com
Blog: blog.dabarobjects.com

Participate, Collaborate, Innovate
Join Community:
http://www.cowblock.net/

Get A Free Blog:
http://blogs.cowblock.net/