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 <[email protected]> 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.
> [email protected]                |  http://webperformance.com
> 919-433-1762                            |  919-845-7601
>
> Web Performance: Website Load Testing Software & Services
> ------------------------------------------------------------------------ -
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to