You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Edvin Syse <ed...@sysedata.no> on 2008/01/25 10:44:17 UTC

Maintain page state on a panel added as a listItem

I have created a CMS in Wicket 1.3 and have run into a problem.

A CMS-page consits of multiple "articles". The articles are laid out on 
the page using a ListView. Normally, an article just displays title, 
text etc, so each article is represented by a simple Fragment that holds 
the fields etc. A simplified version of populateItem looks like:

item.add(new ArticleFragment("article", "articleFragment", 
item.getModel()));

Now I also need to support custom modules (Wicket Panels) as articles, 
so I created a field in my article object that can contain a fully 
qualified class name that should resolve to a Panel, and I do something 
like:

if(article.getArticleType().equals(Article.ARTICLE_TYPE_PANEL_CONTROLLER) 
&& !Strings.isEmpty(article.getControlsPanel())) {
     Class panelClass = Class.forName(a.getControlsPanel());
     Constructor panelConstructor = panelClass.getConstructor(String.class);
     item.add((Panel) panelConstructor.newInstance("article"));
} else
     item.add(new ArticleFragment("article", "articleFragment", 
item.getModel()));

This works great. The problem arise when I need to maintain state in a 
panel included this way. When the page rerenders because of a form 
submit, the panel is recreated because of the actions in the 
populateItem method of the page, and I'm screwed.

Any idea of how I could avoid this? I've started getting crazy ideas 
about getting the panel from the pagemap or something and adding it back 
via item.add(), but I don't know how to, or if that will blow up in my 
face :)

Anyone? :)

-- Edvin

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Maintain page state on a panel added as a listItem

Posted by Ned Collyer <ne...@gmail.com>.
ListView is appropriate, just make sure you set the setReuseItems to true.

Other repeaters may well work too, but ListView is the most obvious choice,
so might as well use it.  (I'm a wicket noobie, and had the same problem a
few days back)


Edvin Syse wrote:
> 
> Hi Ned,
> 
> Thanks a lot, that solved my problem. It just occured to me that I guess 
> I could use some other Repeater-component instead, so that the adding of 
> the articles takes place in the constructor :)
> 
> You made my day!
> 
> -- Edvin
> 

-- 
View this message in context: http://www.nabble.com/Maintain-page-state-on-a-panel-added-as-a-listItem-tp15084385p15085466.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Maintain page state on a panel added as a listItem

Posted by Edvin Syse <ed...@sysedata.no>.
Hi Ned,

Thanks a lot, that solved my problem. It just occured to me that I guess 
I could use some other Repeater-component instead, so that the adding of 
the articles takes place in the constructor :)

You made my day!

-- Edvin

Ned Collyer skrev:
> Let me know if reading the big warning disclaimer on the ListView javadoc
> helps.
> 
> http://people.apache.org/~tobrien/wicket/apidocs/org/apache/wicket/markup/html/list/ListView.html
> 
> Yes, the default behaviour is quirky (and I feel wrong) but it would be a
> nightmare to change it.  A shame really, as it will be like this for
> forever!

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Maintain page state on a panel added as a listItem

Posted by Ned Collyer <ne...@gmail.com>.
Let me know if reading the big warning disclaimer on the ListView javadoc
helps.

http://people.apache.org/~tobrien/wicket/apidocs/org/apache/wicket/markup/html/list/ListView.html

Yes, the default behaviour is quirky (and I feel wrong) but it would be a
nightmare to change it.  A shame really, as it will be like this for
forever!
-- 
View this message in context: http://www.nabble.com/Maintain-page-state-on-a-panel-added-as-a-listItem-tp15084385p15084766.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org