I tried this, but still got the WicketNotSerializableException on the same class - the JPA enhanced version of my Customer object (which is a very simple bean). However, I tried making Customer serializable and now the exception is gone. I was thinking that I could not make Customer serializable (or should not need to) because of the JPA connection and the use of DetachableLoadableModel. But then I had a vague memory that Models do need to be serializable? I read all about Models more than a year ago when I first started looking into Wicket and thought I understood them, but it's hazy now. I'm going to take a long slow read through https://cwiki.apache.org/WICKET/working-with-wicket-models.html because I now remember how important Models are to getting more advanced stuff in Wicket working the right way. I'll be back after I've done my homework.
Was there a chapter in Wicket In Action on models? I bought that a while back and seem to remember a good Models chapter, but lost my e-copy. Might have to buy it again! Thanks for the help! Chris On 8/8/2010 11:32 PM, Igor Vaynberg wrote: > final Customer customer = item.getModelObject(); > ... Link link = new Link("link") { > public void onClick() { > setResponsePage(new CustomerPage(customer)); > > the line above holds on to the customer object, so the Link subclass > has a reference to customer. instead > ... Link link = new Link("link", item.getmodel()) { > public void onClick() { > > setResponsePage(new > CustomerPage((Customer)getmodelobject())); > > -igor > > On Sun, Aug 8, 2010 at 8:16 PM, Chris Merrill <ch...@webperformance.com> > wrote: >> I have a DataView on a page to list items returned by a DB query (using >> JPA). My database object >> (Customer) has LoadableDetachableModel class (called >> DetachableCustomerModel) that the provider >> returns via the model() method. When populating the table, I want a link to >> a page for the details >> of that object. The following code actually works, but throws a >> WicketNotSerializableException >> on my Customer class when the page is rendered: >> >> >> final DataView<Customer> table_viewer = new >> DataView<Customer>("customer_list", provider) >> { >> @Override >> protected void populateItem(final Item<Customer> item) >> { >> final Customer customer = item.getModelObject(); >> item.add(new Label("id", String.valueOf(customer.getId()))); >> Link link = new Link("link") >> { >> @Override >> public void onClick() >> { >> Debug.log.out("CustomerListPage.onClick() - customer: >> " + customer.getName()); >> setResponsePage(new CustomerPage(customer)); >> } >> }; >> item.add(link); >> link.add(new Label("name", customer.getName())); >> String date_string = ""; >> Date date = customer.getLastActivity(); >> if (date != null) // TODO should this >> really ever be null? >> date_string = DateUtil.toSimpleDateString(date); >> item.add(new Label("date", date_string)); >> } >> }; >> >> From what I understand, it SHOULD throw that exception, since the Customer >> came from JPA and >> shouldn't be serialized. That is, I think, why the LoadableDetachableModel >> exists. So, thinking >> that I should be using the model instead, I tried this variation, but was >> surprised to find >> the same result. >> >> final DataView<Customer> table_viewer = new >> DataView<Customer>("customer_list", provider) >> { >> @Override >> protected void populateItem(final Item<Customer> item) >> { >> final IModel<Customer> customer_model = item.getModel(); >> Customer customer = customer_model.getObject(); >> item.add(new Label("id", String.valueOf(customer.getId()))); >> Link link = new Link("link") >> { >> @Override >> public void onClick() >> { >> Debug.log.out("CustomerListPage.onClick() - customer: >> " + >> customer_model.getObject().getName()); >> setResponsePage(new >> CustomerPage(customer_model.getObject())); >> } >> }; >> item.add(link); >> link.add(new Label("name", customer.getName())); >> String date_string = ""; >> Date date = customer.getLastActivity(); >> if (date != null) // TODO should this >> really ever be null? >> date_string = DateUtil.toSimpleDateString(date); >> item.add(new Label("date", date_string)); >> } >> }; >> >> So I'm obviously missing something important about the right way to do this. >> >> Can someone point me in the right direction? >> >> TIA! >> Chris >> >> >> >> -- >> ------------------------------------------------------------------------ - >> Chris Merrill | Web Performance, Inc. >> ch...@webperformance.com | http://webperformance.com >> 919-433-1762 | 919-845-7601 >> >> Web Performance: Website Load Testing Software & Services >> ------------------------------------------------------------------------ - >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org >> For additional commands, e-mail: users-h...@wicket.apache.org >> >> > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org > For additional commands, e-mail: users-h...@wicket.apache.org > > -- ------------------------------------------------------------------------ - Chris Merrill | Web Performance, Inc. ch...@webperformance.com | http://webperformance.com 919-433-1762 | 919-845-7601 Web Performance: Website Load Testing Software & Services ------------------------------------------------------------------------ - --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org