Re: LoadableDetachableModel/Serialization Problem
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 Mohamedes.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 IteratorIPublication 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 DomainObjectModelIPublication((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) {
Re: LoadableDetachableModel/Serialization Problem
I actually tried that, however my publication object looks like this. (I trimmed it to the relevant parts). as you can see there's no authorsInOrder Property only the authors property which can't be displayed to the user. I have to call getAuthorsInOrder() to retrieve the the list of author objects. Right now i can't change this pojo implementation but i can try to convince the domain model guy. What are my options if it can be changed and if it can't? package main.java.domain.publication; import java.util.*; import main.java.domain.user.IUser; /** * An abstract publication POJO implementation for the IPublication interface. * * @see main.java.domain.publication.IPublication * @author Karim El-Sayed */ public abstract class Publication implements IPublication { /** * The unique id of this publication. */ private Long id; /** * The names of the authors of this publication in the same ordered that * have been entered by the user as a codeString/code separated by * commas. The authors within the organization has their id entered while * external authors directly have their name. */ private String authors; private SetIUser internalAuthors = new HashSetIUser(); /** * Default constructor. */ public Publication() { } @Override public Long getId() { return id; } @Override public void setId(Long id) { this.id = id; } @Override public String getAuthors() { return authors; } @Override public void setAuthors(String authors) { this.authors = authors; } @Override public List getAuthorsInOrder() { List authorsInOrder = new ArrayList(); String[] order = authors.split(#); for (String author : order) { long authorId = isNumber(author); if (authorId == -1) { authorsInOrder.add(author); } else { IteratorIUser iterator = internalAuthors.iterator(); while (iterator.hasNext()) { IUser user = iterator.next(); if (user.getId() == authorId) { authorsInOrder.add(user); break; } } } } return authorsInOrder; } } igor.vaynberg wrote: instead of IModel authorsModel = new LoadableDetachableModel() { @Override protected Object load() { return publication.getAuthorsInOrder(); } }; do authorsModel=new PropertyModel(item.getModel(), authorsInOrder); -- View this message in context: http://www.nabble.com/LoadableDetachableModel-Serialization-Problem-tp24868498p24869176.html Sent from the Wicket - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: LoadableDetachableModel/Serialization Problem
the propertymodel will call the getter function. -igor On Fri, Aug 7, 2009 at 10:44 AM, sky.walkeres.most...@gmail.com wrote: I actually tried that, however my publication object looks like this. (I trimmed it to the relevant parts). as you can see there's no authorsInOrder Property only the authors property which can't be displayed to the user. I have to call getAuthorsInOrder() to retrieve the the list of author objects. Right now i can't change this pojo implementation but i can try to convince the domain model guy. What are my options if it can be changed and if it can't? package main.java.domain.publication; import java.util.*; import main.java.domain.user.IUser; /** * An abstract publication POJO implementation for the IPublication interface. * * @see main.java.domain.publication.IPublication * @author Karim El-Sayed */ public abstract class Publication implements IPublication { /** * The unique id of this publication. */ private Long id; /** * The names of the authors of this publication in the same ordered that * have been entered by the user as a codeString/code separated by * commas. The authors within the organization has their id entered while * external authors directly have their name. */ private String authors; private SetIUser internalAuthors = new HashSetIUser(); /** * Default constructor. */ public Publication() { } �...@override public Long getId() { return id; } �...@override public void setId(Long id) { this.id = id; } �...@override public String getAuthors() { return authors; } �...@override public void setAuthors(String authors) { this.authors = authors; } �...@override public List getAuthorsInOrder() { List authorsInOrder = new ArrayList(); String[] order = authors.split(#); for (String author : order) { long authorId = isNumber(author); if (authorId == -1) { authorsInOrder.add(author); } else { IteratorIUser iterator = internalAuthors.iterator(); while (iterator.hasNext()) { IUser user = iterator.next(); if (user.getId() == authorId) { authorsInOrder.add(user); break; } } } } return authorsInOrder; } } igor.vaynberg wrote: instead of IModel authorsModel = new LoadableDetachableModel() { �...@override protected Object load() { return publication.getAuthorsInOrder(); } }; do authorsModel=new PropertyModel(item.getModel(), authorsInOrder); -- View this message in context: http://www.nabble.com/LoadableDetachableModel-Serialization-Problem-tp24868498p24869176.html Sent from the Wicket - User mailing list archive at Nabble.com. - 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
Re: LoadableDetachableModel/Serialization Problem
Thanks igor. i just tried it and it worked. It's so cool property models work like that. igor.vaynberg wrote: the propertymodel will call the getter function. -igor On Fri, Aug 7, 2009 at 10:44 AM, sky.walkeres.most...@gmail.com wrote: I actually tried that, however my publication object looks like this. (I trimmed it to the relevant parts). as you can see there's no authorsInOrder Property only the authors property which can't be displayed to the user. I have to call getAuthorsInOrder() to retrieve the the list of author objects. Right now i can't change this pojo implementation but i can try to convince the domain model guy. What are my options if it can be changed and if it can't? package main.java.domain.publication; import java.util.*; import main.java.domain.user.IUser; /** * An abstract publication POJO implementation for the IPublication interface. * * @see main.java.domain.publication.IPublication * @author Karim El-Sayed */ public abstract class Publication implements IPublication { /** * The unique id of this publication. */ private Long id; /** * The names of the authors of this publication in the same ordered that * have been entered by the user as a codeString/code separated by * commas. The authors within the organization has their id entered while * external authors directly have their name. */ private String authors; private SetIUser internalAuthors = new HashSetIUser(); /** * Default constructor. */ public Publication() { } �...@override public Long getId() { return id; } �...@override public void setId(Long id) { this.id = id; } �...@override public String getAuthors() { return authors; } �...@override public void setAuthors(String authors) { this.authors = authors; } �...@override public List getAuthorsInOrder() { List authorsInOrder = new ArrayList(); String[] order = authors.split(#); for (String author : order) { long authorId = isNumber(author); if (authorId == -1) { authorsInOrder.add(author); } else { IteratorIUser iterator = internalAuthors.iterator(); while (iterator.hasNext()) { IUser user = iterator.next(); if (user.getId() == authorId) { authorsInOrder.add(user); break; } } } } return authorsInOrder; } } igor.vaynberg wrote: instead of IModel authorsModel = new LoadableDetachableModel() { �...@override protected Object load() { return publication.getAuthorsInOrder(); } }; do authorsModel=new PropertyModel(item.getModel(), authorsInOrder); -- View this message in context: http://www.nabble.com/LoadableDetachableModel-Serialization-Problem-tp24868498p24869176.html Sent from the Wicket - User mailing list archive at Nabble.com. - 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 -- View this message in context: http://www.nabble.com/LoadableDetachableModel-Serialization-Problem-tp24868498p24869434.html Sent from the Wicket - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org