package ch.difty.sipamato;

import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.form.OnChangeAjaxBehavior;
import org.apache.wicket.authroles.authorization.strategies.role.annotations.AuthorizeInstantiation;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.PropertyModel;
import org.apache.wicket.model.StringResourceModel;
import org.apache.wicket.request.mapper.parameter.PageParameters;

@AuthorizeInstantiation("USER")
public class PaperEntryPage extends BasePage {

    public PaperEntryPage(PageParameters parameters) {
        super(parameters);
    }

    private static final long serialVersionUID = 1L;

    private Model<Paper> model = Model.of(new Paper());

    protected void onInitialize() {
        super.onInitialize();

        Form<Paper> form = new Form<Paper>("form") {
            private static final long serialVersionUID = 1L;

            @Override
            protected void onSubmit() {
                System.out.println("form submitted. Paper:");
                System.out.println(model.getObject());
            }
        };
        add(form);

        form.add(new Label("authorLabel", new StringResourceModel("author.label", this, null)));
        TextField<String> authorField = new TextField<String>(Paper.AUTHOR, PropertyModel.of(model, Paper.AUTHOR));
        form.add(authorField);

        form.add(new Label("firstAuthorLabel", new StringResourceModel("firstAuthor.label", this, null)));
        TextField<String> firstAuthorField = new TextField<String>(Paper.FIRST_AUTHOR, PropertyModel.of(model, Paper.FIRST_AUTHOR));
        firstAuthorField.setEnabled(false);
        firstAuthorField.setOutputMarkupId(true);
        form.add(firstAuthorField);

        authorField.add(new OnChangeAjaxBehavior() {
            private static final long serialVersionUID = 1L;

            @Override
            protected void onUpdate(AjaxRequestTarget target) {
                target.add(firstAuthorField);
            }
        });

        form.add(new Label("titleLabel", new StringResourceModel("title.label", this, null)));
        TextField<String> titleField = new TextField<String>(Paper.TITLE, PropertyModel.of(model, Paper.TITLE));
        form.add(titleField);

        form.add(new Label("locationLabel", new StringResourceModel("location.label", this, null)));
        TextField<String> locationField = new TextField<String>(Paper.LOCATION, PropertyModel.of(model, Paper.LOCATION));
        form.add(locationField);
    };
}

@@ -410,16 +410,32 @@
 t.model.
+CompoundProperty
 Model;%0Ai
@@ -464,24 +464,16 @@
 t.model.
-Property
 Model;%0Ai
@@ -670,16 +670,70 @@
 Page %7B%0A%0A
+    private static final long serialVersionUID = 1L;%0A%0A
     publ
@@ -817,119 +817,8 @@
  %7D%0A%0A
-    private static final long serialVersionUID = 1L;%0A%0A    private Model%3CPaper%3E model = Model.of(new Paper());%0A%0A
     
@@ -929,16 +929,73 @@
 %3E(%22form%22
+, new CompoundPropertyModel%3CPaper%3E(Model.of(new Paper()))
 ) %7B%0A    
@@ -1215,17 +1215,83 @@
 tln(
-model.get
+getModelObject());%0A                info(%22form submitted. Paper:%22 + getModel
 Obje
@@ -1517,47 +1517,8 @@
 THOR
-, PropertyModel.of(model, Paper.AUTHOR)
 );%0A 
@@ -1744,53 +1744,8 @@
 THOR
-, PropertyModel.of(model, Paper.FIRST_AUTHOR)
 );%0A 
@@ -2319,46 +2319,8 @@
 ITLE
-, PropertyModel.of(model, Paper.TITLE)
 );%0A 
@@ -2532,49 +2532,8 @@
 TION
-, PropertyModel.of(model, Paper.LOCATION)
 );%0A 

Use CompoundPropertyModel