You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by "Artur W." <a_...@gazeta.pl> on 2007/08/23 18:19:32 UTC

Can Panel replace itself ?

hi,

I have a panel with AjaxLink. I want to replace this panel with another one
when user clicks this link.

TestPage.java:
public class TestPage extends Page {

	public TestPage() {
		this(null);
	}

	public TestPage(PageParameters parameters) {
		super(parameters);
		add(new TestPanel("panel", "some param"));
	}
}

TestPanel.java:
public class TestPanel extends Panel {

	public TestPanel(String id, String param) {
		super(id);
		setOutputMarkupId(true);
		AjaxLink link = new AjaxLink("link") {
			public void onClick(AjaxRequestTarget target) {
				TestPanel newOne = new TestPanel(TestPanel.this.getId(), "another
param");
				target.addComponent(newOne);
			}
		};
		link.add(new Label("label0", "click"));
		add(link);
		add(new Label("label1", param.toUpperCase()));
		add(new Label("label2", param.toLowerCase()));
	}
}

TestPanel.html:
&lt;wicket:panel&gt;
    &lt;td&gt;&lt;a href="#" wicket:id="link"&gt;&lt;span
wicket:id="label0"&gt;["label0"]&lt;/span&gt;&lt;/a&gt;&lt;/td&gt;
    &lt;td&gt;&lt;span
wicket:id="label1"&gt;[label1]&lt;/span&gt;&lt;/td&gt;    
    &lt;td&gt;&lt;span
wicket:id="label2"&gt;[label2]&lt;/span&gt;&lt;/td&gt;
&lt;/wicket:panel&gt;


But it doesn't work. When I click on ajax link I get an error:

WicketMessage: This component is not (yet) coupled to a page. It has to be
able to find the page it is supposed to operate in before you can call this
method (Component#getMarkupId)

Root cause:

org.apache.wicket.WicketRuntimeException: This component is not (yet)
coupled to a page. It has to be able to find the page it is supposed to
operate in before you can call this method (Component#getMarkupId)
at org.apache.wicket.Component.getMarkupId(Component.java:1220)
at
org.apache.wicket.ajax.AjaxRequestTarget.addComponent(AjaxRequestTarget.java:342)
[...]


How can I fix it?
Artur

-- 
View this message in context: http://www.nabble.com/Can-Panel-replace-itself---tf4318533.html#a12296907
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: Can Panel replace itself ?

Posted by Igor Vaynberg <ig...@gmail.com>.
its happening because you are creating invalid html

you cannot have a span between a tr and td, so you just need to adjust how
you are outputting the markup. change testpage.html to use the following and
it will work:

<body>
    <table style="border-collapse: collapse; empty-cells: show;">
        <wicket:container wicket:id="list">
            <tr style="border: 1px solid #000;" wicket:id="panel">
            </tr>
        </wicket:container>
    </table>
</body>

-igor


On 8/24/07, Artur W. <a_...@gazeta.pl> wrote:
>
>
>
> igor.vaynberg wrote:
> >
> > i dont get it, where do you expect it to go? it looks like you are
> > replacing
> > an item inside panel7, not inside the panel that is inside the table?
> >
> > maybe you should build a quickstart so we have something to play with.
> >
> >
>
> Thanks for you replay Igor.
>
> The panel is put inside the table. But when I replace it with ajax it
> appear
> outside the table.
> Here is the working example with full source code:
> http://sunet.pl/files/test.war
>
> Artur
>
>
> --
> View this message in context:
> http://www.nabble.com/Can-Panel-replace-itself---tf4318533.html#a12307905
> 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: Can Panel replace itself ?

Posted by "Artur W." <a_...@gazeta.pl>.

igor.vaynberg wrote:
> 
> i dont get it, where do you expect it to go? it looks like you are
> replacing
> an item inside panel7, not inside the panel that is inside the table?
> 
> maybe you should build a quickstart so we have something to play with.
> 
> 

Thanks for you replay Igor.

The panel is put inside the table. But when I replace it with ajax it appear
outside the table.
Here is the working example with full source code:
http://sunet.pl/files/test.war

Artur


-- 
View this message in context: http://www.nabble.com/Can-Panel-replace-itself---tf4318533.html#a12307905
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: Can Panel replace itself ?

Posted by Igor Vaynberg <ig...@gmail.com>.
i dont get it, where do you expect it to go? it looks like you are replacing
an item inside panel7, not inside the panel that is inside the table?

maybe you should build a quickstart so we have something to play with.

-igor


On 8/23/07, Artur W. <a_...@gazeta.pl> wrote:
>
>
>
> igor.vaynberg wrote:
> >
> > does it do that in all browsers?
> >
> > also call view.setreuseitems(true);
> >
>
> I've checked it with ff2 and ie7. Also with Wicket1.3beta2 and beta3. I've
> set view.setreuseitems(true);
>
> The problem is that the wicket generate span tags for panels after body
> tag
> and before the table tag.
> So replacing is proper, but the tags location is incorrect:
>
> &lt;body&gt;
>
>     &lt;span id="panel5"&gt;
>     &lt;/span&gt;&lt;span id="panel7"&gt;
>     &lt;/span&gt;&lt;span id="panel9"&gt;
>     &lt;/span&gt;&lt;span id="panel11"&gt;
>     &lt;/span&gt;&lt;table&gt;
>         &lt;tbody&gt;&lt;tr&gt;
>             &lt;td&gt;&lt;a id="link6" onclick="var
>
> wcall=wicketAjaxGet('?wicket:interface=:4:list:0:panel:link::IBehaviorListener:0:',
> function() { }.bind(this), function() { }.bind(this));return !wcall;"
> href="#"&gt;&lt;span&gt;click&lt;/span&gt;&lt;/a&gt;&lt;/td&gt;
>
>     &lt;td&gt;&lt;span&gt;ONE&lt;/span&gt;&lt;/td&gt;
>     &lt;td&gt;&lt;span&gt;one&lt;/span&gt;&lt;/td&gt;
>
>         &lt;/tr&gt;...
>
>
>
> Full generated html file:
> http://sunet.pl/testpage.html
>
> Full generated html file after one click:
> http://sunet.pl/testpage-after-one-click.html
>
> Is it a but or am I doing something wrong?
>
> Artur
>
> --
> View this message in context:
> http://www.nabble.com/Can-Panel-replace-itself---tf4318533.html#a12307236
> 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: Can Panel replace itself ?

Posted by "Artur W." <a_...@gazeta.pl>.

igor.vaynberg wrote:
> 
> does it do that in all browsers?
> 
> also call view.setreuseitems(true);
> 

I've checked it with ff2 and ie7. Also with Wicket1.3beta2 and beta3. I've
set view.setreuseitems(true);

The problem is that the wicket generate span tags for panels after body tag
and before the table tag.
So replacing is proper, but the tags location is incorrect:

&lt;body&gt;
    
    &lt;span id="panel5"&gt;
    &lt;/span&gt;&lt;span id="panel7"&gt;
    &lt;/span&gt;&lt;span id="panel9"&gt;
    &lt;/span&gt;&lt;span id="panel11"&gt;
    &lt;/span&gt;&lt;table&gt;
        &lt;tbody&gt;&lt;tr&gt;
            &lt;td&gt;&lt;a id="link6" onclick="var
wcall=wicketAjaxGet('?wicket:interface=:4:list:0:panel:link::IBehaviorListener:0:',
function() { }.bind(this), function() { }.bind(this));return !wcall;"
href="#"&gt;&lt;span&gt;click&lt;/span&gt;&lt;/a&gt;&lt;/td&gt;

    &lt;td&gt;&lt;span&gt;ONE&lt;/span&gt;&lt;/td&gt;    
    &lt;td&gt;&lt;span&gt;one&lt;/span&gt;&lt;/td&gt;

        &lt;/tr&gt;...



Full generated html file:
http://sunet.pl/testpage.html

Full generated html file after one click:
http://sunet.pl/testpage-after-one-click.html

Is it a but or am I doing something wrong?

Artur

-- 
View this message in context: http://www.nabble.com/Can-Panel-replace-itself---tf4318533.html#a12307236
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: Can Panel replace itself ?

Posted by Igor Vaynberg <ig...@gmail.com>.
does it do that in all browsers?

also call view.setreuseitems(true);

-igor



On 8/23/07, Artur W. <a_...@gazeta.pl> wrote:
>
>
>
> igor.vaynberg wrote:
> >
> > c.replacewith(a) is the same as c.getparent().replace(a)
> >
>
> I want to extend this example and replace the panel but inside the
> ListView.
> But I've found another problem.
>
> I did like you wrote but the panel isn't replaced. The new panel is being
> added at the top of the table.
> Why?
>
> The Page:
> public class TestPage extends MyPage {
>
>         private static final List&lt;String&gt; params = Arrays.asList(
> new
> String[] { "one", "two", "three", "four"} );
>
>         public TestPage(PageParameters parameters) {
>                 super(parameters);
>
>                 ListView view = new ListView("list", params) {
>                         protected void populateItem(ListItem item) {
>                                 String s = (String) item.getModelObject();
>                                 item.add(new TestPanel("panel", s));
>                         }
>                 };
>                 add(view);
>         }
> }
>
> &lt;wicket:extend&gt;
>     &lt;table&gt;
>         &lt;tr wicket:id="list"&gt;
>             &lt;span wicket:id="panel"&gt;[panel]&lt;/span&gt;
>         &lt;/tr&gt;
>     &lt;/table&gt;
> &lt;/wicket:extend&gt;
>
> The Panel:
>         public TestPanel(String id, String param) {
>                 super(id);
>                 setOutputMarkupId(true);
>                 AjaxLink link = new AjaxLink("link") {
>                         public void onClick(AjaxRequestTarget target) {
>                                 TestPanel newOne = new TestPanel(
> TestPanel.this.getId(), "another
> param");
>                                 TestPanel.this.replaceWith(newOne);
>                                 target.addComponent(newOne);
>                         }
>                 };
>                 link.add(new Label("label0", "click"));
>                 add(link);
>                 add(new Label("label1", param.toUpperCase()));
>                 add(new Label("label2", param.toLowerCase()));
>         }
>
> &lt;wicket:panel&gt;
>     &lt;td&gt;&lt;a href="#" wicket:id="link"&gt;&lt;span
> wicket:id="label0"&gt;["label0"]&lt;/span&gt;&lt;/a&gt;&lt;/td&gt;
>     &lt;td&gt;&lt;span
> wicket:id="label1"&gt;[label1]&lt;/span&gt;&lt;/td&gt;
>     &lt;td&gt;&lt;span
> wicket:id="label2"&gt;[label2]&lt;/span&gt;&lt;/td&gt;
> &lt;/wicket:panel&gt;
>
>
> Artur
> --
> View this message in context:
> http://www.nabble.com/Can-Panel-replace-itself---tf4318533.html#a12300076
> 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: Can Panel replace itself ?

Posted by "Artur W." <a_...@gazeta.pl>.

igor.vaynberg wrote:
> 
> c.replacewith(a) is the same as c.getparent().replace(a)
> 

I want to extend this example and replace the panel but inside the ListView.
But I've found another problem.

I did like you wrote but the panel isn't replaced. The new panel is being
added at the top of the table.
Why?

The Page:
public class TestPage extends MyPage {

	private static final List&lt;String&gt; params = Arrays.asList( new
String[] { "one", "two", "three", "four"} );

	public TestPage(PageParameters parameters) {
		super(parameters);

		ListView view = new ListView("list", params) {
			protected void populateItem(ListItem item) {
				String s = (String) item.getModelObject();
				item.add(new TestPanel("panel", s));
			}
		};
		add(view);
	}
}

&lt;wicket:extend&gt;
    &lt;table&gt;
        &lt;tr wicket:id="list"&gt;
            &lt;span wicket:id="panel"&gt;[panel]&lt;/span&gt;
        &lt;/tr&gt;
    &lt;/table&gt;
&lt;/wicket:extend&gt;

The Panel:
	public TestPanel(String id, String param) {
		super(id);
		setOutputMarkupId(true);
		AjaxLink link = new AjaxLink("link") {
			public void onClick(AjaxRequestTarget target) {
				TestPanel newOne = new TestPanel(TestPanel.this.getId(), "another
param");
				TestPanel.this.replaceWith(newOne);
				target.addComponent(newOne);
			}
		};
		link.add(new Label("label0", "click"));
		add(link);
		add(new Label("label1", param.toUpperCase()));
		add(new Label("label2", param.toLowerCase()));
	}

&lt;wicket:panel&gt;
    &lt;td&gt;&lt;a href="#" wicket:id="link"&gt;&lt;span
wicket:id="label0"&gt;["label0"]&lt;/span&gt;&lt;/a&gt;&lt;/td&gt;
    &lt;td&gt;&lt;span
wicket:id="label1"&gt;[label1]&lt;/span&gt;&lt;/td&gt;    
    &lt;td&gt;&lt;span
wicket:id="label2"&gt;[label2]&lt;/span&gt;&lt;/td&gt;
&lt;/wicket:panel&gt;


Artur
-- 
View this message in context: http://www.nabble.com/Can-Panel-replace-itself---tf4318533.html#a12300076
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: Can Panel replace itself ?

Posted by Igor Vaynberg <ig...@gmail.com>.
c.replacewith(a) is the same as c.getparent().replace(a)

-igor


On 8/23/07, Artur W. <a_...@gazeta.pl> wrote:
>
>
>
>
> Eelco Hillenius wrote:
> >
> > do:
> >
> >    TestPanel newOne = new TestPanel(TestPanel.this.getId(), "another
> > param");
> >    TestPanel.this.replaceWith(newOne);    <------------
> >    target.addComponent(newOne);
> >
> >
>
> I didn't know about replaceWith method. It works great! Thanks a lot!!!
> Artur
>
> --
> View this message in context:
> http://www.nabble.com/Can-Panel-replace-itself---tf4318533.html#a12297058
> 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: Can Panel replace itself ?

Posted by "Artur W." <a_...@gazeta.pl>.


Eelco Hillenius wrote:
> 
> do:
> 
>    TestPanel newOne = new TestPanel(TestPanel.this.getId(), "another
> param");
>    TestPanel.this.replaceWith(newOne);    <------------
>    target.addComponent(newOne);
> 
> 

I didn't know about replaceWith method. It works great! Thanks a lot!!! 
Artur

-- 
View this message in context: http://www.nabble.com/Can-Panel-replace-itself---tf4318533.html#a12297058
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: Can Panel replace itself ?

Posted by Eelco Hillenius <ee...@gmail.com>.
On 8/23/07, Artur W. <a_...@gazeta.pl> wrote:
>
> hi,
>
> I have a panel with AjaxLink. I want to replace this panel with another one
> when user clicks this link.
>
> TestPage.java:
> public class TestPage extends Page {
>
>         public TestPage() {
>                 this(null);
>         }
>
>         public TestPage(PageParameters parameters) {
>                 super(parameters);
>                 add(new TestPanel("panel", "some param"));
>         }
> }
>
> TestPanel.java:
> public class TestPanel extends Panel {
>
>         public TestPanel(String id, String param) {
>                 super(id);
>                 setOutputMarkupId(true);
>                 AjaxLink link = new AjaxLink("link") {
>                         public void onClick(AjaxRequestTarget target) {
>                                 TestPanel newOne = new TestPanel(TestPanel.this.getId(), "another
> param");
>                                 target.addComponent(newOne);
>                         }


do:

   TestPanel newOne = new TestPanel(TestPanel.this.getId(), "another param");
   TestPanel.this.replaceWith(newOne);    <------------
   target.addComponent(newOne);

so that the hierarchy on the server side reflects the replacement.

Eelco

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