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 <[email protected]> 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:[email protected]] > Sent: Friday, April 24, 2009 10:12 AM > To: [email protected] > 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 <[email protected]> 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: [email protected] > For additional commands, e-mail: [email protected] > > --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
