Re: Listview and Link sometimes fail to get objects from DB

2009-02-12 Thread Igor Vaynberg
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
 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 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 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 
>> 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: 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: Listview and Link sometimes fail to get objects from DB

2009-02-12 Thread pieter claassen
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 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 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 
> 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: users-unsubscr...@wicket.apache.org
> For additional commands, e-mail: users-h...@wicket.apache.org
>
>


Re: Listview and Link sometimes fail to get objects from DB

2009-02-12 Thread Igor Vaynberg
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  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: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: Listview and Link sometimes fail to get objects from DB

2009-02-12 Thread Martin Makundi
What happens if you run a debugger and debug line-by-line? Put a
breakpoint somewhere where the null value appears from. It looks like
something else than a wicket bug.

**
Martin

2009/2/12 pieter claassen :
> The value "first" is a field on a template, that is retrieved as one
> template from the list of all templates, from a db4o database using a DAO
> class.
>
> List templates = getTemplateFactory().getAll();
>
> So, this list is *always* retrieved correctly. Each of the templates are
> correctly backed by a database object and I can retrieve any field on any
> one of them.
> Each one of the template objects are wrapped in a thin wrapper where they
> are converted from a "heavy" object (Template) to a thin webmodel
> (TemplateWebModel)
>
> List templatewebmodels = ModelConverter.getModelList(templates,
> TemplateWebModel.class)
>
> In the listview block, I set the model for each list iteration:
>
> final TemplateWebModel templatewebmodel = (TemplateWebModel)
> item.getModelObject();
> item.setModel(new CompoundPropertyModel(templatewebmodel));
>
> and when I want to access the database object, I use:
>
> getModelObject().getEntity()
>
> This approach works both in the listview block of code, but not in any
> onClick() methods of Links that I include in the listview, just after I
> started my application. The second time around, things work fine.
>
> Is this possibly a wicket problem?
>
> Rgrds,
> Pieter
>
>
>
> On Thu, Feb 12, 2009 at 3:06 PM, Martin Makundi <
> martin.maku...@koodaripalvelut.com> wrote:
>
>> Where do you set the value "first"?
>>
>> **
>> Martin
>>
>> 2009/2/12 pieter claassen :
>> > 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: 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: Listview and Link sometimes fail to get objects from DB

2009-02-12 Thread pieter claassen
The value "first" is a field on a template, that is retrieved as one
template from the list of all templates, from a db4o database using a DAO
class.

List templates = getTemplateFactory().getAll();

So, this list is *always* retrieved correctly. Each of the templates are
correctly backed by a database object and I can retrieve any field on any
one of them.
Each one of the template objects are wrapped in a thin wrapper where they
are converted from a "heavy" object (Template) to a thin webmodel
(TemplateWebModel)

List templatewebmodels = ModelConverter.getModelList(templates,
TemplateWebModel.class)

In the listview block, I set the model for each list iteration:

final TemplateWebModel templatewebmodel = (TemplateWebModel)
item.getModelObject();
item.setModel(new CompoundPropertyModel(templatewebmodel));

and when I want to access the database object, I use:

getModelObject().getEntity()

This approach works both in the listview block of code, but not in any
onClick() methods of Links that I include in the listview, just after I
started my application. The second time around, things work fine.

Is this possibly a wicket problem?

Rgrds,
Pieter



On Thu, Feb 12, 2009 at 3:06 PM, Martin Makundi <
martin.maku...@koodaripalvelut.com> wrote:

> Where do you set the value "first"?
>
> **
> Martin
>
> 2009/2/12 pieter claassen :
> > 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: users-unsubscr...@wicket.apache.org
> For additional commands, e-mail: users-h...@wicket.apache.org
>
>


Re: Listview and Link sometimes fail to get objects from DB

2009-02-12 Thread Martin Makundi
Where do you set the value "first"?

**
Martin

2009/2/12 pieter claassen :
> 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: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Listview and Link sometimes fail to get objects from DB

2009-02-12 Thread pieter claassen
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));
}
});
...