you have to chain your models, so instead of

 item.add(new Label("title", publication.getTitle()));

do

item.add(new Label("title", new PropertyModel(item.getModel(), "title"));

instead of

 IModel authorsModel = new LoadableDetachableModel() {
                   @Override
                   protected Object load() {
                       return publication.getAuthorsInOrder();
                   }
               };

do

authorsModel=new PropertyModel(item.getModel(), "authorsInOrder");

that way you never have to hold a reference to the domain object
itself, only a model to it.

-igor


On Fri, Aug 7, 2009 at 10:03 AM, Mostafa Mohamed<es.most...@gmail.com> wrote:
> we're working on wicket/spring/hibernate application (a research
> repository).
>
> my SortableDataProvider looks like this.
>
> public class PublicationDataProvider extends SortableDataProvider {
>    private IBrowseService browseService;
>    private Class<?> type;
>
>    public PublicationDataProvider() {};
>
>    public PublicationDataProvider(IBrowseService browseService, Class<?>
> type) {
>        this.browseService = browseService;
>        this.type = type;
>        setSort("title", true);
>    }
>
>     public Iterator<IPublication> iterator(int first, int count)
>     {
>         SortParam sp = getSort();
>         return browseService.find(first, count, sp.getProperty(),
> sp.isAscending(), type).iterator();
>     }
>
>     public int size()
>     {
>         return browseService.countAll();
>     }
>
>     public IModel model(Object object)
>     {
>         return new DomainObjectModel<IPublication>((IPublication)object);
>     }
>
>     public void detach() {}
> }
>
> I use it with a dataview on the following panel
>
> package main.java.web.components.browser;
>
> import main.java.domain.publication.IPublication;
> import main.java.domain.user.IUser;
> import main.java.services.publication.IBrowseService;
> import main.java.web.components.content.BasicPanel;
>
> import org.apache.wicket.ajax.AjaxRequestTarget;
> import
> org.apache.wicket.ajax.markup.html.navigation.paging.AjaxPagingNavigator;
> import
> org.apache.wicket.extensions.ajax.markup.html.repeater.data.sort.AjaxFallbackOrderByLink;
> import org.apache.wicket.markup.html.WebMarkupContainer;
> import org.apache.wicket.markup.html.basic.Label;
> import org.apache.wicket.markup.html.link.Link;
> import org.apache.wicket.markup.html.list.ListItem;
> import org.apache.wicket.markup.html.list.ListView;
> import org.apache.wicket.markup.repeater.Item;
> import org.apache.wicket.markup.repeater.data.DataView;
> import org.apache.wicket.model.IModel;
> import org.apache.wicket.model.LoadableDetachableModel;
> import org.apache.wicket.spring.injection.annot.SpringBean;
>
> public class BrowsePanel extends BasicPanel {
>   �...@springbean
>    IBrowseService browseService;
>
>    transient IPublication publication;
>
>    public BrowsePanel(Class<?> type) {
>        super("block", "Browse Publications");
>        setOutputMarkupId(true);
>
>        final WebMarkupContainer dataContainer = new
> WebMarkupContainer("dataContainer");
>        dataContainer.setOutputMarkupId(true);
>        add(dataContainer);
>
>        PublicationDataProvider pdp = new
> PublicationDataProvider(browseService, type);
>        final DataView dataView = new DataView("publication", pdp, 10) {
>           �...@override
>            protected void populateItem(Item item) {
>                publication = (IPublication) item.getModelObject();
>                item.add(new Label("number", "" + (getCurrentPage() * 10 +
> item.getIndex() + 1)));
>                item.add(new Label("title", publication.getTitle()));
>
>                IModel authorsModel = new LoadableDetachableModel() {
>                   �...@override
>                    protected Object load() {
>                        return publication.getAuthorsInOrder();
>                    }
>                };
>
>                ListView authorsListView = new ListView("author",
> authorsModel) {
>                   �...@override
>                    protected void populateItem(ListItem item) {
>                        Object author = item.getModelObject();
>                        Link authorLink = new Link("authorLink") {
>                           �...@override
>                            public void onClick() {
>
>                            }
>                        };
>                        if (author instanceof IUser) {
>                            authorLink.add(new Label("authorName", ((IUser)
> author).getFullName()));
>                        }
>                        else {
>                            authorLink.add(new Label("authorName",
> author.toString()));
>                            authorLink.setEnabled(false);
>                        }
>                        item.add(authorLink);
>                    }
>                };
>                item.add(authorsListView);
>                item.add(new Label("abstract",
> publication.getAbstractText()));
>            }
>        };
>
>        dataContainer.add(new AjaxFallbackOrderByLink("orderByTitle",
> "title", pdp) {
>           �...@override
>            protected void onSortChanged() {
>                dataView.setCurrentPage(0);
>            }
>
>           �...@override
>            protected void onAjaxClick(AjaxRequestTarget target) {
>                target.addComponent(dataContainer);
>            }
>        });
>
>        dataContainer.add(dataView);
>
>        AjaxPagingNavigator pager = new AjaxPagingNavigator("pager",
> dataView) {
>           �...@override
>            protected void onAjaxEvent(AjaxRequestTarget target) {
>                target.addComponent(dataContainer);
>            }
>        };
>
>        dataContainer.add(pager);
>    }
> }
>
> when the publication instance variable wasn't transient i would get a wicket
> not serializable exception on this field. I've been reading in the forum and
> i now know that this is because the loadable detachable model that gets the
> list of user objects holds a reference to the publication, (return
> publication.getAuthorsInOrder()). transient does solve my problem, however i
> have a feeling that something is not right. Is there any elegant way to do
> this? Also i'd like to point out that all my domain objects don't implement
> the serializable interface and that they implement the IDomainObject
> interface that has only a getId() method. I've seen the IDomainObject
> interface in WIA and it implements the serializable interface. but isn't
> that against the idea of the loadable detachable model?
>

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

Reply via email to