Re: best way to obtain component reference?
On Thu, 22 Jan 2009, Phillip Rhodes wrote: > I used the page.get("componentid") method, but it returns null. While > I could just store the reference to the label as a variable in my page > class, I would like to understand how to obtain a reference to it > using the wicket API. If it's very simple, a straight get("path") may be OK, but generally it's better to use visitors and/or findParent to not depend so much on the exact component hierarchy. > public AdminPage() { > add(new Label("message", "If you see this message wicket is properly > configured and running")); class StatusMessage extends Label { public StatusMessage() { super("message", "If you see this message wicket is properly configured and running"); } } > @Override > public void onSubmit() > { > Label lbl = new Label("message", "Deleted"); > this.get("message").replaceWith(lbl); getPage().visitChildren(StatusMessage.class, new IVisitor() { public Object component(Component component) { component.setDefaultModelObject("Deleted"); } }); Best wishes, Timo -- Timo Rantalaiho Reaktor Innovations Oyhttp://www.ri.fi/ > - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: best way to obtain component reference?
Phillip Rhodes wrote: I am trying to update the label text on a page from a inner class (onSubmit) of my page. I used the page.get("componentid") method, but it returns null. While I could just store the reference to the label as a variable in my page class, I would like to understand how to obtain a reference to it using the wicket API. When I use the following snippet, my "get" method always return null. Thanks, appreciate the help. public class AdminPage extends WebPage { public AdminPage() { add(new Label("message", "If you see this message wicket is properly configured and running")); DMIRequest dmiRequest = new DMIRequest(); Form myform = new Form("myform", new CompoundPropertyModel(dmiRequest)); add(myform); myform.add(new DeleteButton()); } } private class DeleteButton extends Button { private static final long serialVersionUID = 1L; private DeleteButton() { super("delete", new ResourceModel("delete")); setDefaultFormProcessing(true); } @Override public void onSubmit() { Label lbl = new Label("message", "Deleted"); this.get("message").replaceWith(lbl); Use AdminPage.this.get("message"). Adriano - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: best way to obtain component reference?
using AdminPage.this.get("message").replaceWith(lbl); instead of just this.get("message").replaceWith(lbl); might work, since message is added to the page, not to the delete button.. Phillip Rhodes wrote: I am trying to update the label text on a page from a inner class (onSubmit) of my page. I used the page.get("componentid") method, but it returns null. While I could just store the reference to the label as a variable in my page class, I would like to understand how to obtain a reference to it using the wicket API. When I use the following snippet, my "get" method always return null. Thanks, appreciate the help. public class AdminPage extends WebPage { public AdminPage() { add(new Label("message", "If you see this message wicket is properly configured and running")); DMIRequest dmiRequest = new DMIRequest(); Form myform = new Form("myform", new CompoundPropertyModel(dmiRequest)); add(myform); myform.add(new DeleteButton()); } } private class DeleteButton extends Button { private static final long serialVersionUID = 1L; private DeleteButton() { super("delete", new ResourceModel("delete")); setDefaultFormProcessing(true); } @Override public void onSubmit() { Label lbl = new Label("message", "Deleted"); this.get("message").replaceWith(lbl); } } - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
best way to obtain component reference?
I am trying to update the label text on a page from a inner class (onSubmit) of my page. I used the page.get("componentid") method, but it returns null. While I could just store the reference to the label as a variable in my page class, I would like to understand how to obtain a reference to it using the wicket API. When I use the following snippet, my "get" method always return null. Thanks, appreciate the help. public class AdminPage extends WebPage { public AdminPage() { add(new Label("message", "If you see this message wicket is properly configured and running")); DMIRequest dmiRequest = new DMIRequest(); Form myform = new Form("myform", new CompoundPropertyModel(dmiRequest)); add(myform); myform.add(new DeleteButton()); } } private class DeleteButton extends Button { private static final long serialVersionUID = 1L; private DeleteButton() { super("delete", new ResourceModel("delete")); setDefaultFormProcessing(true); } @Override public void onSubmit() { Label lbl = new Label("message", "Deleted"); this.get("message").replaceWith(lbl); } } - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org