Is this okay? (I think i will add some explantion to it but i think this exmaple explains it well):

class PersonList extends WebPage {
   private List peopleList;

   public PersonList(final List peopleList) {
       this.peopleList = peopleList;
       this.peopleList.add(new Person("Lila"));
       this.peopleList.add(new Person("Bender"));
       this.peopleList.add(new Person("Fry"));

       add(new ListView("peopleList", this.peopleList) {
           protected void populateItem(ListItem listItem) {
               final Person person = (Person) listItem.getModelObject();
               add(new Label("name", person.getName()));
               add(new Link("editPerson") {

                   public void onClick() {
                       setResponsePage(new PersonEdit(person, peopleList));
                   }
               });
           }
       });

       add(new Link("newPerson") {

           public void onClick() {
               setResponsePage(new PersonEdit(new Person(), peopleList));
           }
       });
   }
}

class PersonEdit extends WebPage {
   private FeedbackPanel feedbackPanel;
   private Person person;
   private List peopleList;

   public PersonEdit(Person person, List peopleList) {
       feedbackPanel = new FeedbackPanel("feedbackPanel");
       add(feedbackPanel);

       add(new PersonForm("personForm", person, feedbackPanel));
   }

   class PersonForm extends Form {
       public PersonForm(String s, Person person, IFeedback iFeedback) {
           super(s, new CompoundPropertyModel(person), iFeedback);
           add(new TextField("name"));
           add(new Button("save"));
       }

       public void onSubmit() {
           if (!peopleList.contains(person)) {
               peopleList.add(person);
           }
           setResponsePage(new PersonList(peopleList));
       }
   }
}

class Person {
   public Person() {
   }

   public Person(String name) {
       this.name = name;
   }

   public String getName() {
       return name;
   }

   public void setName(String name) {
       this.name = name;
   }

   private String name;
}



David Liebeherr wrote:

Hehe, what is this supposed to mean? :-)
"Add it to wiki" or "You damn fool there is already a Tutorial on wiki for it so: RTFM!"? :-)

Cu,
Dave

Jonathan Locke wrote:


wikiwiki!

David Liebeherr wrote:

I think you missuderstood me or i was not able to explain it clear enough. I wanted to use the same Form/Page for Editing yet existing Persons (which are in the People List) and edit new Persons (which has to be added to the People-List). Your solution does only work for editing new Persons but not for yet existing ones. (Or maybe i just do not understand your solution fully...)
But i found a solution for my Problem, and it goes like this:

On the Page where i show a list (Table) of Persons which are in the People-List i have two links:
1. Edit link which does the Following:
onClick() {
setRepsonsePage(new PersonEdit(person, personList)); //person is a reference to a existing Person Object
}
2. New Link which does the Following:
onClick() {
   setResponsePage(new PersonEdit(new Person(), personList));
}

And on the PersonEdit Page it goes like this:
onSubmit() {
   if (!this.personList.contains(this.person)) {
      this.personList.add(this.person);
   }
}

This works very well and i think it's clean and nice.
I think i will put it on the wicket wiki as a small tutorial, what do you think?

Anyway thank you for your reply!

Dave

Eelco Hillenius wrote:

In your form:

public MyForm(String id, IModel model)
{
 super(id, new CompoundPropertyModel(new Person()));
 ...
}

public void onSubmit()
{
Person newPerson = (Person)getModelObject(); // by now this object is 'filled' using your form components
  getPersonList().add(newPerson);
// now navigate to another page or set a new person to edit like setModel(new CompoundPropertyModel(new Person()))
}

Eelco

David Liebeherr wrote:

I have a Page with a Form to edit an Person object.
The Person object is always part of a People-List.

The Form uses a CompoundPropertyModel.
It works fine when i edit a given Person object.

So my question is now:
How can i implement it that the CompoudPropertyModel adds a new Person object to the People-List when i use it for editinig a new Person?

Thanks,
Dave


-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user








-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user







-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user



-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user





-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user




-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to