so getmodelobject() returns another imodel? you should really look into a dataview instead of a listview - it will make things easier to understand.
a listview does not expect a list of imodels, it expects a list of objects. each item then wraps each object in a imodel that can retrieve it if needed in listview#getlistitemmodel(). the list should usually be retrieved via a loadabledetachablemodel. anyways, dataviews make all this much simpler. -igor On Thu, Feb 12, 2009 at 7:56 AM, pieter claassen <[email protected]> wrote: > Hi Igor, > > Am I screwing up because I thought I did convert all my code to use only > webmodels? Maybe I still fail to understand the database-wicket integration > part. > > First I get all objects from the database: > > List<Template> templates = getTemplateFactory().getAll(); > > But they are fat and need to be wrapped by models: > > ListView templateList = new ListView("listview", > ModelConverter.getModelList(templates, TemplateWebModel.class)) { > > ModelConverter.getModelList(templates, TemplateWebModel.class)) is a helper > method that converts all my objects into models. > > final TemplateWebModel templatewebmodel = (TemplateWebModel) > item > .getModelObject(); > item.setModel(new CompoundPropertyModel(templatewebmodel)); > > This is more verbose, but isn't this the same as what you just recommended? > TemplateWebModel is an implementation of IModel. > > getModelObject() returns an IModel object because I convert my database > objects to webmodels before I even render the list > > Debugging this problem with a debugger seems unproductive because it seems > to never be there when I debug. > > P > > > On Thu, Feb 12, 2009 at 4:15 PM, Igor Vaynberg <[email protected]>wrote: > >> this code is very bad, you should use models so that you do not end up >> serializing your entities... >> >> item.setModel(new CompoundPropertyModel( item.getmodel() )); >> ... >> item.add(new Link("edit" , item.getmodel() ) { >> @Override >> public void onClick() { >> System.out.println("TEMPLATE NAME IN onClick(): " >> + getmodelobject() >> .getEntity().getName()); >> setResponsePage(new >> TemplateEditPage( getmodel() )); >> } >> }); >> >> -igor >> >> On Thu, Feb 12, 2009 at 5:57 AM, pieter claassen <[email protected]> >> wrote: >> > Listviews with Links in them, sometimes fail to retrieve the object in >> the >> > onClick() method the first time around. When I reload the page, the code >> > works fine. >> > >> > Here is a test. In the listview below, I load the page and in the >> listview >> > loop code, I correctly retrieve the item. Note that in the onClick() the >> > modelobject is null. >> > >> > TEMPLATE NAME IN listview: first >> > TEMPLATE NAME IN onClick(): null >> > >> > Reloading the page, and the problem goes away. >> > >> > TEMPLATE NAME IN listview: first >> > TEMPLATE NAME IN onClick(): first >> > >> > >> > This is using wicket 1.3.5. and db4o 7.8. This problem is normally there >> > when I restart my application. >> > >> > Any ideas? >> > >> > Example code: >> > >> > ListView templateList = new ListView("listview", ModelConverter >> > .getModelList(templates, TemplateWebModel.class)) { >> > @Override >> > protected void populateItem(ListItem item) { >> > final TemplateWebModel templatewebmodel = >> (TemplateWebModel) >> > item >> > .getModelObject(); >> > System.out.println("TEMPLATE NAME IN listview: " >> > + templatewebmodel.getEntity().getName()); >> > >> > item.setModel(new >> CompoundPropertyModel(templatewebmodel)); >> > ... >> > item.add(new Link("edit") { >> > @Override >> > public void onClick() { >> > System.out.println("TEMPLATE NAME IN onClick(): " >> > + templatewebmodel.getEntity().getName()); >> > setResponsePage(new >> > TemplateEditPage(templatewebmodel)); >> > } >> > }); >> > ... >> > >> >> --------------------------------------------------------------------- >> 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]
