You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Dane Laverty <da...@gmail.com> on 2009/04/24 16:57:38 UTC
Adding a model to a custom panel
I’m building a Panel called TaskPanel that will display the contents of my
Task class. This simple Panel has a single constructor and a method, that
looks like this:
public class TaskPanel extends Panel {
Task task;
public TaskPanel(String id, final Task task) {
super(id);
add(new Label("name", task.getName()));
add(new Label("description", task.getDescription()));
add(new Label("assignedTo", task.getAssignedTo()));
this.task = task;
}
@Override
protected void onComponentTag(ComponentTag tag) {
if (task.isSelected()) {
// Do something
}
}
}
It seems like I should make Task the model for the Panel, but I'm having
trouble finding information on how to connect them. I imagine it should look
something like this:
public class TaskPanel extends Panel {
public TaskPanel(String id, IModel task) {
super(id, task);
add(new Label("name", ???));
add(new Label("description", ???));
add(new Label("assignedTo", ???));
}
@Override
protected void onComponentTag(ComponentTag tag) {
if (getModel().???.isSelected()) {
// Do something
}
}
}
Am I even heading in the right direction? Is this the right place to be
using a Model, or should I just stick with keeping the Task as an instance
variable in the class?
Re: Adding a model to a custom panel
Posted by Igor Vaynberg <ig...@gmail.com>.
public TaskPanel(String id, IModel<Task> task) {
super(id, task);
add(new Label("name",new propertymodel(task, "name"));
protected void onComponentTag(ComponentTag tag) {
if (getModel().getObject().isSelected()) {
// Do something
}
}
-igor
On Fri, Apr 24, 2009 at 7:57 AM, Dane Laverty <da...@gmail.com> wrote:
> I’m building a Panel called TaskPanel that will display the contents of my
> Task class. This simple Panel has a single constructor and a method, that
> looks like this:
>
> public class TaskPanel extends Panel {
>
> Task task;
>
> public TaskPanel(String id, final Task task) {
> super(id);
> add(new Label("name", task.getName()));
> add(new Label("description", task.getDescription()));
> add(new Label("assignedTo", task.getAssignedTo()));
>
> this.task = task;
> }
>
> @Override
> protected void onComponentTag(ComponentTag tag) {
> if (task.isSelected()) {
> // Do something
> }
> }
> }
>
>
> It seems like I should make Task the model for the Panel, but I'm having
> trouble finding information on how to connect them. I imagine it should look
> something like this:
>
> public class TaskPanel extends Panel {
>
> public TaskPanel(String id, IModel task) {
> super(id, task);
> add(new Label("name", ???));
> add(new Label("description", ???));
> add(new Label("assignedTo", ???));
> }
>
> @Override
> protected void onComponentTag(ComponentTag tag) {
> if (getModel().???.isSelected()) {
> // Do something
> }
> }
> }
>
> Am I even heading in the right direction? Is this the right place to be
> using a Model, or should I just stick with keeping the Task as an instance
> variable in the class?
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Adding a model to a custom panel
Posted by Igor Vaynberg <ig...@gmail.com>.
consider a simple usecase where you present this panl and below you
have a textfield to edit the task name. after you submit the form you
want the task panel to be updated.
if you do this without a model you will have to recreate the panel,
giving it the updated task, if you use a model you can give the panel
a loadable detachable model and it will automatically pull the latest
task from the db.
-igor
On Fri, Apr 24, 2009 at 10:21 AM, Dane Laverty <da...@gmail.com> wrote:
> Thanks, that seems pretty straightforward. However, it makes me
> wonder, what is the advantage of using a model instead of just using
> the Task as a class variable? The model adds an extra layer of
> complexity, and I don't see the benefit.
>
>
> -----Original Message-----
> From: Igor Vaynberg [mailto:igor.vaynberg@gmail.com]
> Sent: Friday, April 24, 2009 10:12 AM
> To: users@wicket.apache.org
> Subject: Re: Adding a model to a custom panel
>
> public TaskPanel(String id, IModel<Task> task) {
> super(id, task);
> add(new Label("name",new propertymodel(task, "name"));
>
>
> protected void onComponentTag(ComponentTag tag) {
> if (getModel().getObject().isSelected()) {
> // Do something
> }
> }
>
> -igor
>
>
> On Fri, Apr 24, 2009 at 7:57 AM, Dane Laverty <da...@gmail.com> wrote:
>
>> I’m building a Panel called TaskPanel that will display the contents of my
>> Task class. This simple Panel has a single constructor and a method, that
>> looks like this:
>>
>> public class TaskPanel extends Panel {
>>
>> Task task;
>>
>> public TaskPanel(String id, final Task task) {
>> super(id);
>> add(new Label("name", task.getName()));
>> add(new Label("description", task.getDescription()));
>> add(new Label("assignedTo", task.getAssignedTo()));
>>
>> this.task = task;
>> }
>>
>> @Override
>> protected void onComponentTag(ComponentTag tag) {
>> if (task.isSelected()) {
>> // Do something
>> }
>> }
>> }
>>
>>
>> It seems like I should make Task the model for the Panel, but I'm having
>> trouble finding information on how to connect them. I imagine it should look
>> something like this:
>>
>> public class TaskPanel extends Panel {
>>
>> public TaskPanel(String id, IModel task) {
>> super(id, task);
>> add(new Label("name", ???));
>> add(new Label("description", ???));
>> add(new Label("assignedTo", ???));
>> }
>>
>> @Override
>> protected void onComponentTag(ComponentTag tag) {
>> if (getModel().???.isSelected()) {
>> // Do something
>> }
>> }
>> }
>>
>> Am I even heading in the right direction? Is this the right place to be
>> using a Model, or should I just stick with keeping the Task as an instance
>> variable in the class?
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Adding a model to a custom panel
Posted by Dane Laverty <da...@gmail.com>.
Thanks, that seems pretty straightforward. However, it makes me
wonder, what is the advantage of using a model instead of just using
the Task as a class variable? The model adds an extra layer of
complexity, and I don't see the benefit.
-----Original Message-----
From: Igor Vaynberg [mailto:igor.vaynberg@gmail.com]
Sent: Friday, April 24, 2009 10:12 AM
To: users@wicket.apache.org
Subject: Re: Adding a model to a custom panel
public TaskPanel(String id, IModel<Task> task) {
super(id, task);
add(new Label("name",new propertymodel(task, "name"));
protected void onComponentTag(ComponentTag tag) {
if (getModel().getObject().isSelected()) {
// Do something
}
}
-igor
On Fri, Apr 24, 2009 at 7:57 AM, Dane Laverty <da...@gmail.com> wrote:
> I’m building a Panel called TaskPanel that will display the contents of my
> Task class. This simple Panel has a single constructor and a method, that
> looks like this:
>
> public class TaskPanel extends Panel {
>
> Task task;
>
> public TaskPanel(String id, final Task task) {
> super(id);
> add(new Label("name", task.getName()));
> add(new Label("description", task.getDescription()));
> add(new Label("assignedTo", task.getAssignedTo()));
>
> this.task = task;
> }
>
> @Override
> protected void onComponentTag(ComponentTag tag) {
> if (task.isSelected()) {
> // Do something
> }
> }
> }
>
>
> It seems like I should make Task the model for the Panel, but I'm having
> trouble finding information on how to connect them. I imagine it should look
> something like this:
>
> public class TaskPanel extends Panel {
>
> public TaskPanel(String id, IModel task) {
> super(id, task);
> add(new Label("name", ???));
> add(new Label("description", ???));
> add(new Label("assignedTo", ???));
> }
>
> @Override
> protected void onComponentTag(ComponentTag tag) {
> if (getModel().???.isSelected()) {
> // Do something
> }
> }
> }
>
> Am I even heading in the right direction? Is this the right place to be
> using a Model, or should I just stick with keeping the Task as an instance
> variable in the class?
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org