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

Reply via email to