You are putting view objects inside the model of other view object. Models
are meant to keep your application domain data, and over that you create
your view. So:
For what MyPanel was designed?
1 - For present MyData
container.add(new ListView<MyData>("panels", panels) {
protected void populateItem(ListItem<MyData> item) {
item.add( new MyPanel("panel", item.getModelObject()));
}
});
then you write:
panels.getModelObject().add(new MyData());
more some code to update panels like
target.addComponent(container);
2 - For present some static markup on template
so consider to use an less sophisticated repeater, like RepeatingView
On Fri, Jan 22, 2010 at 1:04 PM, zkn <[email protected]> wrote:
>
> On 22.01.2010, at 03:18, [email protected] wrote:
>
> >
> http://old.nabble.com/dynamically-adding-components-to-a-ListView-td26626657.html
> >
> > In this post you said "You found it". Could you please post how did you
> do it?
> >
> > Zinovii
>
> in addPanel()
>
> replaced
>
> panels.add(panel);
>
> with
>
> panels.getModelObject().add(panel);
>
>
>
>
>
> On 04.12.2009, at 00:17, zkn wrote:
>
> > found it.
> >
> > On 03.12.2009, at 16:19, zkn wrote:
> >
> >> Hi,
> >>
> >> I'm trying to dynamically add components to an existing ListView but I
> can't figure out how to do that. Here is my case:
> >>
> >> MyPanelContainer class with markup
> >>
> >> <wicket:panel>
> >> <wicket:container wicket:id="panels">
> >> <wicket:container wicket:id="panel" />
> >> </wicket:container>
> >> <a href="#" wicket:id="addPanel">add panel</a>
> >> </wicket:panel>
> >>
> >> and here is how I create the container in the constructor of my page
> >>
> >> ..
> >> MyPanelContainer container = new MyPanelContainer("panels_list_1");
> >> List<MyPanel> panels = new ArrayList<MyPanel>();
> >>
> >> for (int j = 0; j < 5; j++) {
> >> MyPanel panel = new MyPanel("panel");
> >>
> >> .....
> >>
> >> panels.add(panel);
> >> .
> >>
> >>
> >> container.add(new ListView<MyPanel>("panels", panels) {
> >> protected void populateItem(ListItem<MyPanel> item) {
> >> item.add( item.getModelObject());
> >> }
> >> });
> >> add(Container);
> >> ..
> >>
> >> This works fine and I can see all MyPanel inside the container.
> >>
> >> Now I'm trying to add another MyPanel inside the container on user
> click. Here is the constructor of MyPanelContainer
> >>
> >> public MyPanelContainer(String id) {
> >> super(id);
> >> ....
> >> add(new Link("addPanel") {
> >> @Override
> >> public void onClick() {
> >> addPanel();
> >> }
> >>
> >> });
> >> .
> >>
> >> ..
> >> public void addPanel() {
> >>
> >> ListView< MyPanel > panels = (ListView< MyPanel >)
> get("panels");
> >>
> >> MyPanel panel = new MyPanel("panel");
> >> ...
> >> panels.add(panel);
> >> }
> >>
> >> Basically addPanel() does the same thing as in page constructor to add
> panels to the list but nothing shows up.
> >>
> >> Thanks in advance for your help
> >>
> >> Ozkan
> >>
> >
>
>
--
Pedro Henrique Oliveira dos Santos