Re: [Wicket-user] Best practice and use of detachable models

2007-02-22 Thread Igor Vaynberg

On 2/22/07, Gabor Szokoli <[EMAIL PROTECTED]> wrote:


Hi!

On 2/22/07, Peter Thomas <[EMAIL PROTECTED]> wrote:
> > > Will new Label("foo", fooModel.getFoo() + "bar")kind of hardcoding
conflict in some subtle way with the concept of detachable models?

[detachable model for concatenated string snipped]

> Can I assume that doing all this may not be worth it if you are only
trying
> to derive a simple String value to put into a label - so the
"hardcoding"
> may be okay for most scenarios?

Let's see if I understand wicket basics by now: My take is that each
such "hardcoded" string model remains in the session.



yep

so you think of the tradeoff. you can either serialize a string or a model
class. which one would be smaller? for short strings the string will
probably take up less space.

another thing to consider is whether or not you need this model to be
refreshable. if you put a string in the model never changes, it always
contains the string no matter how many times you repaint the page. this
might not matter when used inside repeaters that rebuild their component
hierarchy on every request.

-igor



Gabor Szokoli

new guy

-
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share
your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
___
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user

-
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV___
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user


Re: [Wicket-user] Best practice and use of detachable models

2007-02-22 Thread Gabor Szokoli
Hi!

On 2/22/07, Peter Thomas <[EMAIL PROTECTED]> wrote:
> > > Will new Label("foo", fooModel.getFoo() + "bar")kind of hardcoding 
> > > conflict in some subtle way with the concept of detachable models?

[detachable model for concatenated string snipped]

> Can I assume that doing all this may not be worth it if you are only trying
> to derive a simple String value to put into a label - so the "hardcoding"
> may be okay for most scenarios?

Let's see if I understand wicket basics by now: My take is that each
such "hardcoded" string model remains in the session.


Gabor Szokoli
new guy

-
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
___
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user


Re: [Wicket-user] Best practice and use of detachable models

2007-02-21 Thread Peter Thomas


no, not exactly. if you havent set a model on the component (or set it to
null) and call getmodel() wicket will search upwards for a model that
implements the compound model interface. look up compound property models on
that wiki page.



Thanks, will do.

One last question:

f) And suppose I have a Label that has to be derived by say some string

> concatenation or formula and OGNL notation will not work.  Will new
> Label("foo", fooModel.getFoo() + "bar")kind of hardcoding conflict in
> some subtle way with the concept of detachable models?


write a simple model

private static class foomodel extends abstractreadonlymodel {
  private final imodel wrapped;
  public foomodel(imodel wrapped) { this.wrapped=wrapped; }
  public object getobject() { return wrapped.getobject()+"bar"; }
  public void detach() { wrapped.detach(); // important }
}

you do this a lot, so it is very helpful to create a superclass of the
above that helps with setting and detaching. i leave that as an excercise to
you.



Can I assume that doing all this may not be worth it if you are only trying
to derive a simple String value to put into a label - so the "hardcoding"
may be okay for most scenarios?
-
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV___
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user


Re: [Wicket-user] Best practice and use of detachable models

2007-02-21 Thread Igor Vaynberg

On 2/21/07, Peter Thomas <[EMAIL PROTECTED]> wrote:


Thanks Igor.  This really helped, and along the way I realized I missed a
few fundamentals.  One more question below:

d) Now I am iterating using ListView.  How exactly do I initialize the
> > ListView so that it uses the "installed" detachable model?
>
>
> what do you mean? you just pass it into the constructor.
>

Ok I get it.  Also, when you do "getModel()" Wicket will search upwards
the component hierarchy right? So it does not matter even if you are on a
child panel within the page or something, yes?




no, not exactly. if you havent set a model on the component (or set it to
null) and call getmodel() wicket will search upwards for a model that
implements the compound model interface. look up compound property models on
that wiki page.

-igor
-
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV___
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user


Re: [Wicket-user] Best practice and use of detachable models

2007-02-21 Thread Peter Thomas

Thanks Igor.  This really helped, and along the way I realized I missed a
few fundamentals.  One more question below:

d) Now I am iterating using ListView.  How exactly do I initialize the

> ListView so that it uses the "installed" detachable model?


what do you mean? you just pass it into the constructor.



Ok I get it.  Also, when you do "getModel()" Wicket will search upwards the
component hierarchy right? So it does not matter even if you are on a child
panel within the page or something, yes?

e) While rendering each row of the ListView, how do I initialize Labels so

> that they in turn get the right chunk of the detachable model?


just what you did above  - new PropertyModel(item.,getModel(), "name");
or if you use PropertyListView just add(new Label("name")) :)



Yep.  Honestly was not aware of PropertyListView and will look into that as
well.

f) And suppose I have a Label that has to be derived by say some string

> concatenation or formula and OGNL notation will not work.  Will new
> Label("foo", fooModel.getFoo() + "bar")kind of hardcoding conflict in
> some subtle way with the concept of detachable models?


write a simple model

private static class foomodel extends abstractreadonlymodel {
  private final imodel wrapped;
  public foomodel(imodel wrapped) { this.wrapped=wrapped; }
  public object getobject() { return wrapped.getobject()+"bar"; }
  public void detach() { wrapped.detach(); // important }
}

you do this a lot, so it is very helpful to create a superclass of the
above that helps with setting and detaching. i leave that as an excercise to
you.



Thanks,  will try that out!

- Peter.
-
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV___
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user


Re: [Wicket-user] Best practice and use of detachable models

2007-02-21 Thread Igor Vaynberg

On 2/21/07, Peter Thomas <[EMAIL PROTECTED]> wrote:


Hi,

I use Hibernate and have got a reasonably sized app working with Wicket.
I am aware of the concept of detachable models and want to use it
effectively and I have the following questions.  If the information is
already there on the wiki or something - feel free to point me there.
Apologies in advance for the dumb questions, but I'm sure there is a general
consensus that Wicket models are tricky to understand.



what can be tricky about interface IModel { T getObject(); void
setObject(T t); } ? :)

there is a great wiki page on models that explains all this stuff in detail.

a) If you don't use detachable models, it is ok but the downside is that

when your page is serialized, your models get serialized and this could take
up a lot of memory. Is my understanding correct?



yes. generally you want to keep your session as small as possible. generally
there are no reasons to stick things in there that can be loaded from the
db.

b) In some cases I use new Label("foo", new PropertyModel(fooModel,

"foo"))); and in some cases I use new Label("foo", fooModel.getFoo());
which should I stick to or when should I use which?



if you dont mind the object put in session then you can do foomodel.getfoo()
(like if its something simple like a string)

c) I have a list of objects I got from Hibernate.  Can you provide (or link

to) some simple code that will show me how to "install" this model on the
parent component, and I mean in detachable mode.  In my case it is just a
WebPage.



add(new listview("list", new loadabledetachablemodel() {
  public object load() { return
getsession().createcriteria(user.class).list();
}
}

thats all there is to it. consider this:

public class entitymodel extends loadabledetachablemodel {
 private final Class clazz;
 private final Serializable id;

 public entitymodel(Class clazz, Serializable id) {
this.clazz=clazz; this.id=id;
 }

 public object load() { return getsession().get(clazz, id); }
}

the above model is a generalized hibernate entity model. you can do thigs
like

setresponsepage(new ViewUserPage(new entitymodel(user.class, 15)));

this model will load the user when getobject() is called, and keep it in
memory during the request. once the request is done and before the page is
saved this model will null the variable that keeps the user so it is not put
in session. only the two key pieces of information necessary to retrieve
this user (and which are hopefully much smaller then the actual user object)
are kept in session.


d) Now I am iterating using ListView.  How exactly do I initialize the

ListView so that it uses the "installed" detachable model?



what do you mean? you just pass it into the constructor.

e) While rendering each row of the ListView, how do I initialize Labels so

that they in turn get the right chunk of the detachable model?



just what you did above  - new PropertyModel(item.,getModel(), "name");
or if you use PropertyListView just add(new Label("name")) :)

f) And suppose I have a Label that has to be derived by say some string

concatenation or formula and OGNL notation will not work.  Will new
Label("foo", fooModel.getFoo() + "bar")kind of hardcoding conflict in some
subtle way with the concept of detachable models?



write a simple model

private static class foomodel extends abstractreadonlymodel {
 private final imodel wrapped;
 public foomodel(imodel wrapped) { this.wrapped=wrapped; }
 public object getobject() { return wrapped.getobject()+"bar"; }
 public void detach() { wrapped.detach(); // important }
}

you do this a lot, so it is very helpful to create a superclass of the above
that helps with setting and detaching. i leave that as an excercise to you.

-igor


Thanks,


Peter.

-
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share
your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
___
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user


-
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV___
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user


[Wicket-user] Best practice and use of detachable models

2007-02-21 Thread Peter Thomas

Hi,

I use Hibernate and have got a reasonably sized app working with Wicket.  I
am aware of the concept of detachable models and want to use it effectively
and I have the following questions.  If the information is already there on
the wiki or something - feel free to point me there.  Apologies in advance
for the dumb questions, but I'm sure there is a general consensus that
Wicket models are tricky to understand.

a) If you don't use detachable models, it is ok but the downside is that
when your page is serialized, your models get serialized and this could take
up a lot of memory. Is my understanding correct?

b) In some cases I use new Label("foo", new PropertyModel(fooModel,
"foo"))); and in some cases I use new Label("foo", fooModel.getFoo()); which
should I stick to or when should I use which?

c) I have a list of objects I got from Hibernate.  Can you provide (or link
to) some simple code that will show me how to "install" this model on the
parent component, and I mean in detachable mode.  In my case it is just a
WebPage.

d) Now I am iterating using ListView.  How exactly do I initialize the
ListView so that it uses the "installed" detachable model?

e) While rendering each row of the ListView, how do I initialize Labels so
that they in turn get the right chunk of the detachable model?

f) And suppose I have a Label that has to be derived by say some string
concatenation or formula and OGNL notation will not work.  Will new
Label("foo", fooModel.getFoo() + "bar")kind of hardcoding conflict in some
subtle way with the concept of detachable models?

Thanks,

Peter.
-
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV___
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user