RE: getter called multiple times on PropertyModel with ListView
Thanks. It does work, and the load() method only gets called once when the view renders. However, I am still confused as to why it works. In other words, why LoadableDetachableModel only gets called once, whereas PropertyModel gets called multiple times on rendering the ListView. For instance, the JavaDocs for this class say: LoadableDetachableModel holds a temporary, transient model object. If anything, it seems like that would get called MORE than PropertyModel, not less, in case the temporary, transient model object gets changed. Just struggling to really understand how models work, because they seem so key to understanding Wicket. Thanks -Original Message- From: Hoover, William [mailto:[EMAIL PROTECTED] Sent: Tuesday, April 29, 2008 3:09 PM To: users@wicket.apache.org Subject: RE: getter called multiple times on PropertyModel with ListView // It solves your problem because the call to load will be made each time your view renders final LoadableDetachableModel articlesLoadableModel = new LoadableDetachableModel() { private static final long serialVersionUID = 1L; /** * [EMAIL PROTECTED] */ @Override protected final Object load() { return new PropertyModel(YourPage.this, articles); } }; final ListView newsDetails = new ListView(newsDetails, articlesLoadableModel){ private static final long serialVersionUID = 1L; /** * [EMAIL PROTECTED] */ @Override protected final void populateItem(final ListItem item) { ... } }; add(newsDetails); -Original Message- From: Andrew Broderick [mailto:[EMAIL PROTECTED] Sent: Tuesday, April 29, 2008 2:19 PM To: 'users@wicket.apache.org' Subject: RE: getter called multiple times on PropertyModel with ListView Cannot instantiate LoadableDetachableModel directly .. it is abstract. Besides, how does it help solve the problem? Thanks -Original Message- From: Igor Vaynberg [mailto:[EMAIL PROTECTED] Sent: Tuesday, April 29, 2008 12:49 PM To: users@wicket.apache.org Subject: Re: getter called multiple times on PropertyModel with ListView ListView newsDetails = new ListView(newsDetails, new LoadableDetachableModel(new PropertyModel(this, articles))) -igor On Tue, Apr 29, 2008 at 10:46 AM, Andrew Broderick [EMAIL PROTECTED] wrote: Hi, I have a page where I am using a PropertyModel to populate a ListView, so it will change when the underlying contents change: ListView newsDetails = new ListView(newsDetails, new PropertyModel(this, articles)) { protected void populateItem(ListItem item) { final NewsDetails nd = (NewsDetails) item.getModelObject(); item.add(new Label(articleDate, nd.getArticleDate())); item.add(new Label(articleTime, nd.getArticleTime())); item.add(new Label(newsShortDesc, nd.getNewsShortDesc())); newsUrlLink.add(new Label(newsTitle, nd.getNewsTitle())); item.add(newsUrlLink); } }; add(newsDetails); The page class, obviously, has a getter named getArticles(): public ListNewsDetails getArticles() { } However, this seems to get called multiple times when the listview is being populated, not just once at the beginning of each time the page is displayer. Why is this happening? It results in many more hits to the database than are necessary. Thanks, Andrew B ___ The information in this email or in any file attached hereto is intended only for the personal and confiden- tial use of the individual or entity to which it is addressed and may contain information that is propri- etary and confidential. If you are not the intended recipient of this message you are hereby notified that any review, dissemination, distribution or copying of this message is strictly prohibited. This communica- tion is for information purposes only and should not be regarded as an offer to sell or as a solicitation of an offer to buy any financial product. Email trans- mission cannot be guaranteed to be secure or error- free. P6070214 - 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] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail
Re: getter called multiple times on PropertyModel with ListView
Read the models document on the wiki. It has helped many others. /shameless plug: chapter 4 of WIA also explains detachable models in detail. Martijn On 4/30/08, Andrew Broderick [EMAIL PROTECTED] wrote: Thanks. It does work, and the load() method only gets called once when the view renders. However, I am still confused as to why it works. In other words, why LoadableDetachableModel only gets called once, whereas PropertyModel gets called multiple times on rendering the ListView. For instance, the JavaDocs for this class say: LoadableDetachableModel holds a temporary, transient model object. If anything, it seems like that would get called MORE than PropertyModel, not less, in case the temporary, transient model object gets changed. Just struggling to really understand how models work, because they seem so key to understanding Wicket. Thanks -Original Message- From: Hoover, William [mailto:[EMAIL PROTECTED] Sent: Tuesday, April 29, 2008 3:09 PM To: users@wicket.apache.org Subject: RE: getter called multiple times on PropertyModel with ListView // It solves your problem because the call to load will be made each time your view renders final LoadableDetachableModel articlesLoadableModel = new LoadableDetachableModel() { private static final long serialVersionUID = 1L; /** * [EMAIL PROTECTED] */ @Override protected final Object load() { return new PropertyModel(YourPage.this, articles); } }; final ListView newsDetails = new ListView(newsDetails, articlesLoadableModel){ private static final long serialVersionUID = 1L; /** * [EMAIL PROTECTED] */ @Override protected final void populateItem(final ListItem item) { ... } }; add(newsDetails); -Original Message- From: Andrew Broderick [mailto:[EMAIL PROTECTED] Sent: Tuesday, April 29, 2008 2:19 PM To: 'users@wicket.apache.org' Subject: RE: getter called multiple times on PropertyModel with ListView Cannot instantiate LoadableDetachableModel directly .. it is abstract. Besides, how does it help solve the problem? Thanks -Original Message- From: Igor Vaynberg [mailto:[EMAIL PROTECTED] Sent: Tuesday, April 29, 2008 12:49 PM To: users@wicket.apache.org Subject: Re: getter called multiple times on PropertyModel with ListView ListView newsDetails = new ListView(newsDetails, new LoadableDetachableModel(new PropertyModel(this, articles))) -igor On Tue, Apr 29, 2008 at 10:46 AM, Andrew Broderick [EMAIL PROTECTED] wrote: Hi, I have a page where I am using a PropertyModel to populate a ListView, so it will change when the underlying contents change: ListView newsDetails = new ListView(newsDetails, new PropertyModel(this, articles)) { protected void populateItem(ListItem item) { final NewsDetails nd = (NewsDetails) item.getModelObject(); item.add(new Label(articleDate, nd.getArticleDate())); item.add(new Label(articleTime, nd.getArticleTime())); item.add(new Label(newsShortDesc, nd.getNewsShortDesc())); newsUrlLink.add(new Label(newsTitle, nd.getNewsTitle())); item.add(newsUrlLink); } }; add(newsDetails); The page class, obviously, has a getter named getArticles(): public ListNewsDetails getArticles() { } However, this seems to get called multiple times when the listview is being populated, not just once at the beginning of each time the page is displayer. Why is this happening? It results in many more hits to the database than are necessary. Thanks, Andrew B ___ The information in this email or in any file attached hereto is intended only for the personal and confiden- tial use of the individual or entity to which it is addressed and may contain information that is propri- etary and confidential. If you are not the intended recipient of this message you are hereby notified that any review, dissemination, distribution or copying of this message is strictly prohibited. This communica- tion is for information purposes only and should not be regarded as an offer to sell or as a solicitation of an offer to buy any financial product. Email trans- mission cannot be guaranteed to be secure or error- free. P6070214 - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED
Re: getter called multiple times on PropertyModel with ListView
ListView newsDetails = new ListView(newsDetails, new LoadableDetachableModel(new PropertyModel(this, articles))) -igor On Tue, Apr 29, 2008 at 10:46 AM, Andrew Broderick [EMAIL PROTECTED] wrote: Hi, I have a page where I am using a PropertyModel to populate a ListView, so it will change when the underlying contents change: ListView newsDetails = new ListView(newsDetails, new PropertyModel(this, articles)) { protected void populateItem(ListItem item) { final NewsDetails nd = (NewsDetails) item.getModelObject(); item.add(new Label(articleDate, nd.getArticleDate())); item.add(new Label(articleTime, nd.getArticleTime())); item.add(new Label(newsShortDesc, nd.getNewsShortDesc())); newsUrlLink.add(new Label(newsTitle, nd.getNewsTitle())); item.add(newsUrlLink); } }; add(newsDetails); The page class, obviously, has a getter named getArticles(): public ListNewsDetails getArticles() { } However, this seems to get called multiple times when the listview is being populated, not just once at the beginning of each time the page is displayer. Why is this happening? It results in many more hits to the database than are necessary. Thanks, Andrew B ___ The information in this email or in any file attached hereto is intended only for the personal and confiden- tial use of the individual or entity to which it is addressed and may contain information that is propri- etary and confidential. If you are not the intended recipient of this message you are hereby notified that any review, dissemination, distribution or copying of this message is strictly prohibited. This communica- tion is for information purposes only and should not be regarded as an offer to sell or as a solicitation of an offer to buy any financial product. Email trans- mission cannot be guaranteed to be secure or error- free. P6070214 - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: getter called multiple times on PropertyModel with ListView
Cannot instantiate LoadableDetachableModel directly .. it is abstract. Besides, how does it help solve the problem? Thanks -Original Message- From: Igor Vaynberg [mailto:[EMAIL PROTECTED] Sent: Tuesday, April 29, 2008 12:49 PM To: users@wicket.apache.org Subject: Re: getter called multiple times on PropertyModel with ListView ListView newsDetails = new ListView(newsDetails, new LoadableDetachableModel(new PropertyModel(this, articles))) -igor On Tue, Apr 29, 2008 at 10:46 AM, Andrew Broderick [EMAIL PROTECTED] wrote: Hi, I have a page where I am using a PropertyModel to populate a ListView, so it will change when the underlying contents change: ListView newsDetails = new ListView(newsDetails, new PropertyModel(this, articles)) { protected void populateItem(ListItem item) { final NewsDetails nd = (NewsDetails) item.getModelObject(); item.add(new Label(articleDate, nd.getArticleDate())); item.add(new Label(articleTime, nd.getArticleTime())); item.add(new Label(newsShortDesc, nd.getNewsShortDesc())); newsUrlLink.add(new Label(newsTitle, nd.getNewsTitle())); item.add(newsUrlLink); } }; add(newsDetails); The page class, obviously, has a getter named getArticles(): public ListNewsDetails getArticles() { } However, this seems to get called multiple times when the listview is being populated, not just once at the beginning of each time the page is displayer. Why is this happening? It results in many more hits to the database than are necessary. Thanks, Andrew B ___ The information in this email or in any file attached hereto is intended only for the personal and confiden- tial use of the individual or entity to which it is addressed and may contain information that is propri- etary and confidential. If you are not the intended recipient of this message you are hereby notified that any review, dissemination, distribution or copying of this message is strictly prohibited. This communica- tion is for information purposes only and should not be regarded as an offer to sell or as a solicitation of an offer to buy any financial product. Email trans- mission cannot be guaranteed to be secure or error- free. P6070214 - 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]
RE: getter called multiple times on PropertyModel with ListView
// It solves your problem because the call to load will be made each time your view renders final LoadableDetachableModel articlesLoadableModel = new LoadableDetachableModel() { private static final long serialVersionUID = 1L; /** * [EMAIL PROTECTED] */ @Override protected final Object load() { return new PropertyModel(YourPage.this, articles); } }; final ListView newsDetails = new ListView(newsDetails, articlesLoadableModel){ private static final long serialVersionUID = 1L; /** * [EMAIL PROTECTED] */ @Override protected final void populateItem(final ListItem item) { ... } }; add(newsDetails); -Original Message- From: Andrew Broderick [mailto:[EMAIL PROTECTED] Sent: Tuesday, April 29, 2008 2:19 PM To: 'users@wicket.apache.org' Subject: RE: getter called multiple times on PropertyModel with ListView Cannot instantiate LoadableDetachableModel directly .. it is abstract. Besides, how does it help solve the problem? Thanks -Original Message- From: Igor Vaynberg [mailto:[EMAIL PROTECTED] Sent: Tuesday, April 29, 2008 12:49 PM To: users@wicket.apache.org Subject: Re: getter called multiple times on PropertyModel with ListView ListView newsDetails = new ListView(newsDetails, new LoadableDetachableModel(new PropertyModel(this, articles))) -igor On Tue, Apr 29, 2008 at 10:46 AM, Andrew Broderick [EMAIL PROTECTED] wrote: Hi, I have a page where I am using a PropertyModel to populate a ListView, so it will change when the underlying contents change: ListView newsDetails = new ListView(newsDetails, new PropertyModel(this, articles)) { protected void populateItem(ListItem item) { final NewsDetails nd = (NewsDetails) item.getModelObject(); item.add(new Label(articleDate, nd.getArticleDate())); item.add(new Label(articleTime, nd.getArticleTime())); item.add(new Label(newsShortDesc, nd.getNewsShortDesc())); newsUrlLink.add(new Label(newsTitle, nd.getNewsTitle())); item.add(newsUrlLink); } }; add(newsDetails); The page class, obviously, has a getter named getArticles(): public ListNewsDetails getArticles() { } However, this seems to get called multiple times when the listview is being populated, not just once at the beginning of each time the page is displayer. Why is this happening? It results in many more hits to the database than are necessary. Thanks, Andrew B ___ The information in this email or in any file attached hereto is intended only for the personal and confiden- tial use of the individual or entity to which it is addressed and may contain information that is propri- etary and confidential. If you are not the intended recipient of this message you are hereby notified that any review, dissemination, distribution or copying of this message is strictly prohibited. This communica- tion is for information purposes only and should not be regarded as an offer to sell or as a solicitation of an offer to buy any financial product. Email trans- mission cannot be guaranteed to be secure or error- free. P6070214 - 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] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]