Example usage for org.apache.wicket.markup.html.form Form isSubmitted

List of usage examples for org.apache.wicket.markup.html.form Form isSubmitted

Introduction

In this page you can find the example usage for org.apache.wicket.markup.html.form Form isSubmitted.

Prototype

public final boolean isSubmitted() 

Source Link

Document

Checks if this form has been submitted during the current request

Usage

From source file:com.axway.ats.testexplorer.pages.machines.MachinesPage.java

License:Apache License

private Form<Object> getMachinesForm(final Label noMachinesLabel) {

    final Form<Object> machinesForm = new Form<Object>("machinesForm");
    machinesForm.setOutputMarkupId(true);

    machineModels = new HashMap<Integer, IModel<String>>();

    ListView<Machine> machinesTable = new ListView<Machine>("machine", machines) {

        private static final long serialVersionUID = 1L;

        @Override/*from w ww.j a v  a2 s. c  o m*/
        protected void populateItem(final ListItem<Machine> item) {

            if (item.getIndex() % 2 != 0) {
                item.add(AttributeModifier.replace("class", "oddRow"));
            }
            IModel<String> aliasModel = new Model<String>(item.getModelObject().alias);
            machineModels.put(item.getModelObject().machineId, aliasModel);
            item.add(new TextField<String>("machineAlias", aliasModel));

            item.add(new Label("machineName", item.getModelObject().name).setEscapeModelStrings(false));

            final Machine machine = item.getModelObject();
            item.add(new AjaxButton("machineInfo") {

                private static final long serialVersionUID = 1L;

                @Override
                protected void onSubmit(AjaxRequestTarget target, Form<?> form) {

                    if (machine.alias == null || machine.alias.trim().length() == 0) {
                        machineInfoDialogTitle.setDefaultModelObject(machine.name);
                    } else {
                        machineInfoDialogTitle.setDefaultModelObject(machine.alias + " (" + machine.name + ")");
                    }

                    machineInfoDialog.setVisible(true);
                    machineForEdit = machine;
                    machineInfoText.setModelObject(getMachineInformation(machine));

                    target.add(machineInfoDialogForm);
                }
            });
        }
    };
    machinesForm.add(machinesTable);

    AjaxButton saveMachineAliasesButton = new AjaxButton("saveMachineAliasesButton") {

        private static final long serialVersionUID = 1L;

        @Override
        public void onSubmit(AjaxRequestTarget target, Form<?> form) {

            if (!form.isSubmitted()) {
                return;
            }

            for (Machine machine : machines) {

                String newMachineAlias = machineModels.get(machine.machineId).getObject();
                if (newMachineAlias != null) {
                    newMachineAlias = newMachineAlias.trim();
                }
                if ((newMachineAlias == null && machine.alias != null)
                        || (newMachineAlias != null && !newMachineAlias.equals(machine.alias))) {

                    machine.alias = newMachineAlias;
                    try {
                        getTESession().getDbWriteConnection().updateMachineAlias(machine);
                    } catch (DatabaseAccessException e) {
                        LOG.error("Can't update alias of machine '" + machine.name + "'", e);
                        target.appendJavaScript(
                                "alert('There was an error while updating the machine aliases!');");
                        return;
                    }
                }
            }
            target.appendJavaScript("alert('The machine aliases were successfully updated.');");
        }
    };

    boolean hasMachines = machines.size() > 0;

    machinesTable.setVisible(hasMachines);
    saveMachineAliasesButton.setVisible(hasMachines);
    noMachinesLabel.setVisible(!hasMachines);

    machinesForm.add(saveMachineAliasesButton);
    machinesForm.add(noMachinesLabel);

    return machinesForm;
}

From source file:com.axway.ats.testexplorer.pages.reports.compare.ComparePage.java

License:Apache License

private AjaxButton getStandardRunsCompareButtons() {

    return new AjaxButton("regular_runs_compare_button") {

        private static final long serialVersionUID = 1L;

        @Override/*from  ww w.j a  va2 s .  com*/
        public void onSubmit(AjaxRequestTarget target, Form<?> form) {

            if (!form.isSubmitted()) {
                return;
            }
            StringBuilder sb = new StringBuilder();
            Map<Run, Model<Boolean>> runs = getTESession().getCompareContainer().getRuns();
            for (Run r : runs.keySet()) {
                if (runs.get(r).getObject()) {
                    sb.append(String.valueOf(r.runId));
                    sb.append("_");
                }
            }
            if (sb.length() > 0) {

                PageParameters parameters = new PageParameters();
                parameters.add("runIds", sb.substring(0, sb.length() - 1));
                parameters.add("dbname", ((TestExplorerSession) Session.get()).getDbName());
                setResponsePage(CompareRunsPage.class, parameters);
            }
        }
    };
}

From source file:com.axway.ats.testexplorer.pages.reports.compare.ComparePage.java

License:Apache License

private AjaxButton getStandardTestcasesCompareButtons() {

    return new AjaxButton("regular_testcases_compare_button") {

        private static final long serialVersionUID = 1L;

        @Override/*from w  w  w  . j a  v  a2 s.  c  o  m*/
        public void onSubmit(AjaxRequestTarget target, Form<?> form) {

            if (!form.isSubmitted()) {
                return;
            }
            StringBuilder sb = new StringBuilder();
            Map<Testcase, Model<Boolean>> testcases = getTESession().getCompareContainer().getTestcases();
            for (Testcase t : testcases.keySet()) {
                if (testcases.get(t).getObject()) {
                    sb.append(String.valueOf(t.testcaseId));
                    if (!t.name.equals(t.getAlias())) {
                        sb.append("=" + t.getAlias().replace("_", "-"));
                    }
                    sb.append("_");
                }
            }

            if (sb.length() > 0) {

                PageParameters parameters = new PageParameters();
                parameters.add("testcaseIds", sb.substring(0, sb.length() - 1));
                parameters.add("dbname", ((TestExplorerSession) Session.get()).getDbName());
                setResponsePage(CompareTestcaseSystemStatisticsPage.class, parameters);
            }
        }
    };
}

From source file:com.doculibre.constellio.wicket.behaviors.SetFocusBehavior.java

License:Open Source License

/**
 * @see org.apache.wicket.behavior.AbstractBehavior#renderHead(org.apache.wicket.markup.html.IHeaderResponse)
 *///w w w  . j a v  a  2s .  c  om
public void renderHead(final IHeaderResponse response) {
    Component focusComponent = (Component) focusComponentModel.getObject();
    if (focusComponent != null) {
        // If the focusComponent is a form, we will set the focus on one of
        // its fields.
        if (focusComponent instanceof Form) {
            Form form = (Form) focusComponent;

            // If the form has been submitted, we want to set the focus on
            // its first invalid field.
            if (form.isSubmitted()) {
                form.visitFormComponentsPostOrder(new IVisitor() {
                    public Object formComponent(IFormVisitorParticipant formParticipant) {
                        Object result;
                        if (formParticipant instanceof FormComponent) {
                            FormComponent formComponent = (FormComponent) formParticipant;
                            // We cannot set focus on an hidden field or a button.
                            if (!(formComponent instanceof HiddenField) && !(formComponent instanceof Button)
                                    && !formComponent.isValid()) {
                                setFocus(formComponent, response);
                                // Will break the loop.
                                result = Component.IVisitor.STOP_TRAVERSAL;
                            } else {
                                // Will continue the loop.
                                result = Component.IVisitor.CONTINUE_TRAVERSAL;
                            }
                        } else {
                            // Will continue the loop.
                            result = Component.IVisitor.CONTINUE_TRAVERSAL;
                        }
                        return result;
                    }
                });
            } else {
                // Since the form has not been submitted, we will set the
                // focus on its first field.
                form.visitFormComponentsPostOrder(new IVisitor() {
                    public Object formComponent(IFormVisitorParticipant formParticipant) {
                        Object result;
                        if (formParticipant instanceof FormComponent) {
                            FormComponent formComponent = (FormComponent) formParticipant;
                            // We cannot set focus on an hidden field or a button.
                            if (!(formComponent instanceof HiddenField) && !(formComponent instanceof Button)
                                    && formComponent.isEnabled() && formComponent.isVisible()) {
                                setFocus(formComponent, response);
                                // Will break the loop.
                                result = Component.IVisitor.STOP_TRAVERSAL;
                            } else {
                                // Will continue the loop.
                                result = Component.IVisitor.CONTINUE_TRAVERSAL;
                            }
                        } else {
                            // Will continue the loop.
                            result = Component.IVisitor.CONTINUE_TRAVERSAL;
                        }
                        return result;
                    }
                });
            }
        } else {
            // The focusComponent is not a form, so we will set the focus on
            // it.
            setFocus(focusComponent, response);
        }
    }
}

From source file:org.patientview.radar.web.components.RadarComponentFactory.java

License:Open Source License

public static Label getSuccessMessageLabel(String id, final Form form,
        final List<Component> componentsToUpdate) {
    return new Label(id, RadarModelFactory.getSuccessMessageModel(form)) {
        {// w  w  w. j  ava2 s .c o  m
            setOutputMarkupId(true);
            setOutputMarkupPlaceholderTag(true);
            form.add(this);
            componentsToUpdate.add(this);
        }

        @Override
        public boolean isVisible() {
            return form.isSubmitted() && !form.hasError();
        }
    };
}

From source file:org.patientview.radar.web.components.RadarComponentFactory.java

License:Open Source License

public static Label getErrorMessageLabel(String id, final Form form, String msg,
        final List<Component> componentsToUpdate) {
    return new Label(id, msg) {
        {// w  w w .j a v  a 2  s  .  c  o m
            setOutputMarkupId(true);
            setOutputMarkupPlaceholderTag(true);
            form.add(this);
            componentsToUpdate.add(this);
        }

        @Override
        public boolean isVisible() {
            return form.isSubmitted() && form.hasError();
        }
    };
}

From source file:org.patientview.radar.web.components.RadarComponentFactory.java

License:Open Source License

public static Label getMessageLabel(String id, final Form form, PropertyModel message,
        final List<Component> componentsToUpdate) {
    return new Label(id, message) {
        {/*www  . j  ava2s  . c  o  m*/
            setOutputMarkupId(true);
            setOutputMarkupPlaceholderTag(true);
            form.add(this);
            componentsToUpdate.add(this);
        }

        @Override
        public boolean isVisible() {
            return form.isSubmitted() && form.hasError();
        }
    };
}

From source file:org.patientview.radar.web.pages.login.ForgottenPasswordPage.java

License:Open Source License

public ForgottenPasswordPage() {

    Label userType = new Label("userType", getUserType());
    add(userType);//from   w  w w. j  a  v  a2s .co  m

    // components to update on ajax submit
    final List<Component> componentsToUpdate = new ArrayList<Component>();
    // Construct form
    final Form<String> form = new Form<String>("form", new Model<String>()) {
        @Override
        protected void onSubmit() {
            try {
                sendPassword(getModelObject());
            } catch (EmailAddressNotFoundException e) {
                error(EMAIL_ADDRESS_NOT_RECOGNISED_MESSAGE);
            } catch (DecryptionException e) {
                error(ERROR_MESSAGE);
            }
        }
    };
    add(form);

    // Feedback
    final FeedbackPanel feedbackPanel = new FeedbackPanel("feedback", new IFeedbackMessageFilter() {
        public boolean accept(FeedbackMessage feedbackMessage) {
            String message = feedbackMessage.getMessage().toString();
            return message.contains(ERROR_MESSAGE) || message.contains(EMAIL_ADDRESS_NOT_RECOGNISED_MESSAGE);
        }
    });

    // success message
    Label successMessage = new Label("successMessage", "Your password has been emailed to you") {
        {
            setOutputMarkupId(true);
            setOutputMarkupPlaceholderTag(true);
            form.add(this);
            componentsToUpdate.add(this);
        }

        @Override
        public boolean isVisible() {
            return form.isSubmitted() && !form.hasError();
        }
    };
    form.add(feedbackPanel);
    componentsToUpdate.add(feedbackPanel);
    feedbackPanel.setOutputMarkupId(true);
    feedbackPanel.setOutputMarkupPlaceholderTag(true);

    // Email - can use same model as the form
    RadarRequiredTextField email = new RadarRequiredTextField("email", form, componentsToUpdate);
    email.setModel(form.getModel());
    form.add(email);

    // Submit link
    form.add(new IndicatingAjaxButton("submit") {
        {
            componentsToUpdate.add(this);
        }

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            target.add(componentsToUpdate.toArray(new Component[componentsToUpdate.size()]));
        }

        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form) {
            target.add(componentsToUpdate.toArray(new Component[componentsToUpdate.size()]));
        }

        @Override
        public boolean isVisible() {
            if (form.isSubmitted() && !form.hasError()) {
                return false;
            }
            return super.isVisible();
        }
    });

}

From source file:org.patientview.radar.web.pages.regisration.ChangeRegistrationDetails.java

License:Open Source License

public ChangeRegistrationDetails() {

    // ------------------------- authentication section -------------------------------- //

    // need a model for password as no setter method for password in User.class probably for security
    final IModel<String> passwordModel = new Model<String>();

    // components to update on ajax
    final List<Component> componentsToUpdate = new ArrayList<Component>();

    final WebMarkupContainer authenticationPanel = new WebMarkupContainer("authenticationPanel");
    authenticationPanel.setOutputMarkupId(true);
    authenticationPanel.setOutputMarkupPlaceholderTag(true);
    componentsToUpdate.add(authenticationPanel);
    add(authenticationPanel);/*from  w  w w . jav a2  s  . c o m*/

    // controls whether the second changed details panel is visible
    final IModel<Boolean> changeDetailsVisibilityModel = new Model<Boolean>(false);

    final CompoundPropertyModel<ProfessionalUser> userModel = new CompoundPropertyModel<ProfessionalUser>(
            new Model<ProfessionalUser>(new ProfessionalUser()));
    final Form<ProfessionalUser> authenticationForm = new Form<ProfessionalUser>("authenticationForm",
            userModel) {
        @Override
        protected void onSubmit() {
            ProfessionalUser user = getModelObject();
            try {
                boolean authenticated = userManager.authenticateProfessionalUser(user.getUsername(),
                        passwordModel.getObject());

                if (!authenticated) {
                    error(VERIFICATION_FAILED_MESSAGE);
                }
            } catch (AuthenticationException e) {
                error(VERIFICATION_FAILED_MESSAGE);
            }

            if (isSubmitted() && !hasError()) {
                authenticationPanel.setVisible(false);
                changeDetailsVisibilityModel.setObject(true);
            }
        }

    };

    authenticationForm.add(new RadarRequiredTextField("username", authenticationForm, componentsToUpdate));
    final PasswordTextField password = RadarComponentFactory.getRequiredPasswordTextField(PASSWORD_ID,
            authenticationForm, componentsToUpdate);
    password.setOutputMarkupId(true);
    password.setOutputMarkupPlaceholderTag(true);
    authenticationForm.add(password);
    password.setModel(passwordModel);
    componentsToUpdate.add(password);

    // components to update on ajax for the change details components
    final List<Component> changeDetailsComponentsToUpdate = new ArrayList<Component>();

    authenticationForm.add(new AjaxSubmitLink("authenticationSubmit") {
        {
            setOutputMarkupId(true);
            setOutputMarkupPlaceholderTag(true);
        }

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            target.add(componentsToUpdate.toArray(new Component[componentsToUpdate.size()]));
            target.add(changeDetailsComponentsToUpdate
                    .toArray(new Component[changeDetailsComponentsToUpdate.size()]));
        }

        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form) {
            target.add(componentsToUpdate.toArray(new Component[componentsToUpdate.size()]));
            password.clearInput();
        }

    });
    authenticationPanel.add(authenticationForm);

    // Construct feedback panel
    final FeedbackPanel feedbackPanel = new FeedbackPanel("feedback", new IFeedbackMessageFilter() {
        public boolean accept(FeedbackMessage feedbackMessage) {
            String message = feedbackMessage.getMessage().toString();
            return message.equals(VERIFICATION_FAILED_MESSAGE);
        }
    });

    componentsToUpdate.add(feedbackPanel);
    feedbackPanel.setOutputMarkupId(true);
    feedbackPanel.setOutputMarkupPlaceholderTag(true);
    authenticationForm.add(feedbackPanel);

    // --------------------------------------- change details section ------------------------------ //
    final WebMarkupContainer changeDetailsPanel = new WebMarkupContainer("changeDetailsPanel") {
        @Override
        public boolean isVisible() {
            return changeDetailsVisibilityModel.getObject();
        }
    };
    changeDetailsPanel.setOutputMarkupId(true);
    changeDetailsPanel.setOutputMarkupPlaceholderTag(true);
    changeDetailsComponentsToUpdate.add(changeDetailsPanel);
    add(changeDetailsPanel);

    final Form<PasswordModel> changeDetailsForm = new Form<PasswordModel>("changeDetailsForm",
            new CompoundPropertyModel<PasswordModel>(new Model<PasswordModel>(new PasswordModel()))) {
        @Override
        protected void onSubmit() {
            PasswordModel passwordModel = getModelObject();
            if (!passwordModel.password1.equals(passwordModel.password2)) {
                error(PASSWORD_MISMATCH_ERROR_MESSAGE);
            }
            if (!hasError()) {
                try {
                    userManager.changeUserPassword(userModel.getObject().getUsername(),
                            getModelObject().password1);
                } catch (DecryptionException e) {
                    error(UNEXPECTED_ERROR);
                } catch (DaoException e) {
                    error(UNEXPECTED_ERROR);
                }
            }
        }

    };

    final PasswordTextField password1 = RadarComponentFactory.getRadarPasswordTextFieldWithValidation(
            "password1", StringValidator.lengthBetween(6, 10), true, changeDetailsForm,
            changeDetailsComponentsToUpdate);
    changeDetailsForm.add(password1);

    final PasswordTextField password2 = RadarComponentFactory.getRequiredPasswordTextField("password2",
            changeDetailsForm, changeDetailsComponentsToUpdate);
    changeDetailsForm.add(password2);

    password1.setOutputMarkupId(true);
    password1.setOutputMarkupPlaceholderTag(true);

    password2.setOutputMarkupId(true);
    password2.setOutputMarkupPlaceholderTag(true);

    changeDetailsComponentsToUpdate.add(password1);
    changeDetailsComponentsToUpdate.add(password2);

    AjaxButton changeDetailsSubmit = new IndicatingAjaxButton("changeDetailsSubmit") {
        {
            setOutputMarkupId(true);
            setOutputMarkupPlaceholderTag(true);
        }

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            target.add(changeDetailsComponentsToUpdate
                    .toArray(new Component[changeDetailsComponentsToUpdate.size()]));
        }

        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form) {
            target.add(changeDetailsComponentsToUpdate
                    .toArray(new Component[changeDetailsComponentsToUpdate.size()]));
            password1.clearInput();
            password2.clearInput();
        }

        @Override
        public boolean isVisible() {
            return !(changeDetailsForm.isSubmitted() && !changeDetailsForm.hasError());
        }
    };
    changeDetailsForm.add(changeDetailsSubmit);
    componentsToUpdate.add(changeDetailsSubmit);
    changeDetailsPanel.add(changeDetailsForm);

    // Construct feedback panel
    final FeedbackPanel changeDetailsfeedbackPanel = new FeedbackPanel("feedback",
            new IFeedbackMessageFilter() {
                public boolean accept(FeedbackMessage feedbackMessage) {
                    String message = feedbackMessage.getMessage().toString();
                    return message.equals(PASSWORD_MISMATCH_ERROR_MESSAGE) || message.equals(UNEXPECTED_ERROR);
                }
            });

    changeDetailsForm.add(new Label("successMessage", "Your password has been changed") {
        {
            setOutputMarkupId(true);
            setOutputMarkupPlaceholderTag(true);
            componentsToUpdate.add(this);
        }

        @Override
        public boolean isVisible() {
            return changeDetailsForm.isSubmitted() && !changeDetailsForm.hasError();
        }
    });

    changeDetailsComponentsToUpdate.add(changeDetailsfeedbackPanel);
    changeDetailsfeedbackPanel.setOutputMarkupId(true);
    changeDetailsfeedbackPanel.setOutputMarkupPlaceholderTag(true);
    changeDetailsForm.add(changeDetailsfeedbackPanel);

}

From source file:org.patientview.radar.web.pages.regisration.ProfessionalRegistrationPage.java

License:Open Source License

public ProfessionalRegistrationPage() {

    final List<Component> componentsToUpdate = new ArrayList<Component>();

    Random randomGenerator = new Random();
    int firstNumber = randomGenerator.nextInt(10);
    int secondNumber = randomGenerator.nextInt(10);

    final Form<ProfessionalUser> form = new Form<ProfessionalUser>("form",
            new CompoundPropertyModel<ProfessionalUser>(new ProfessionalUser())) {
        @Override//from  w ww .j av  a2s. co  m
        protected void onSubmit() {
            try {
                ProfessionalUser professionalUser = getModelObject();
                professionalUser.setSecurityQuestionAnsw(securityQuestionAnswModel.getObject());
                userManager.registerProfessional(professionalUser);
            } catch (UserEmailAlreadyExists professionalUserEmailAlreadyExists) {
                get("emailContainer").get("email").error("This email address has already been taken");
            } catch (InvalidSecurityQuestionAnswer invalidSecurityQuestionAnswer) {
                get("securityQuestionContainer").get("securityQuestion")
                        .error("Wrong answer to the anti-spam question, please try again.");
            } catch (RegistrationException e) {
                error(ERROR_MESSAGE);
            }
        }
    };

    final IModel<String> areaModel = new Model<String>();

    form.add(new RadarTextFieldWithValidation("surname", null, true, form, componentsToUpdate));
    form.add(new RadarTextFieldWithValidation("forename", null, true, form, componentsToUpdate));
    form.add(new RadarRequiredDropdownChoice("title", Arrays.asList("Dr", "Professor", "Mr", "Mrs", "Miss"),
            new ChoiceRenderer(), form, componentsToUpdate));

    DropDownChoice areaDropDown = new RadarRequiredDropdownChoice("areaDropDown", areaModel,
            Arrays.asList(AREA1, AREA2), new ChoiceRenderer(), form, componentsToUpdate);

    form.add(areaDropDown);
    areaDropDown.add(new AjaxFormComponentUpdatingBehavior("onchange") {
        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            target.add(componentsToUpdate.toArray(new Component[componentsToUpdate.size()]));
        }
    });

    WebMarkupContainer gmcContainer = new WebMarkupContainer("gmcContainer") {
        {
            setOutputMarkupId(true);
            setOutputMarkupPlaceholderTag(true);
        }

        @Override
        public boolean isVisible() {
            return (AREA1).equals(areaModel.getObject());
        }
    };

    RadarTextFieldWithValidation gmc = new RadarTextFieldWithValidation("gmc", null, true, gmcContainer,
            componentsToUpdate);
    gmcContainer.add(gmc);
    form.add(gmcContainer);
    componentsToUpdate.add(gmcContainer);

    WebMarkupContainer roleContainer = new WebMarkupContainer("roleContainer") {
        {
            setOutputMarkupId(true);
            setOutputMarkupPlaceholderTag(true);
        }

        @Override
        public boolean isVisible() {
            return areaModel.getObject() != null;
        }
    };

    RadarTextFieldWithValidation role = new RadarTextFieldWithValidation("role", null, true, roleContainer,
            componentsToUpdate);
    roleContainer.add(role);
    form.add(roleContainer);
    componentsToUpdate.add(roleContainer);

    WebMarkupContainer emailContainer = new WebMarkupContainer("emailContainer") {
        {
            setOutputMarkupId(true);
            setOutputMarkupPlaceholderTag(true);
        }

        @Override
        public boolean isVisible() {
            return areaModel.getObject() != null;
        }
    };

    RadarTextFieldWithValidation email = new RadarTextFieldWithValidation("email",
            EmailAddressValidator.getInstance(), true, emailContainer, componentsToUpdate);

    emailContainer.add(email);
    form.add(emailContainer);
    componentsToUpdate.add(emailContainer);

    WebMarkupContainer phoneContainer = new WebMarkupContainer("phoneContainer") {
        {
            setOutputMarkupId(true);
            setOutputMarkupPlaceholderTag(true);
        }

        @Override
        public boolean isVisible() {
            return areaModel.getObject() != null;
        }
    };

    RadarTextFieldWithValidation phone = new RadarTextFieldWithValidation("phone", null, true, phoneContainer,
            componentsToUpdate);
    phoneContainer.add(phone);
    form.add(phoneContainer);
    componentsToUpdate.add(phoneContainer);

    WebMarkupContainer centreContainer = new WebMarkupContainer("centreContainer") {
        {
            setOutputMarkupId(true);
            setOutputMarkupPlaceholderTag(true);
        }

        @Override
        public boolean isVisible() {
            return areaModel.getObject() != null;
        }
    };

    RadarRequiredDropdownChoice centre = new RadarRequiredDropdownChoice("centre", utilityManager.getCentres(),
            new ChoiceRenderer("name", "id"), centreContainer, componentsToUpdate);
    centreContainer.add(centre);
    form.add(centreContainer);
    componentsToUpdate.add(centreContainer);

    WebMarkupContainer securityQuestionContainer = new WebMarkupContainer("securityQuestionContainer") {
        {
            setOutputMarkupId(true);
            setOutputMarkupPlaceholderTag(true);
        }

        @Override
        public boolean isVisible() {
            return areaModel.getObject() != null;
        }
    };

    WebMarkupContainer securityQuestionMsgContainer = new WebMarkupContainer("securityQuestionMsgContainer") {
        {
            setOutputMarkupId(true);
            setOutputMarkupPlaceholderTag(true);
        }

        @Override
        public boolean isVisible() {
            return areaModel.getObject() != null;
        }
    };

    RadarTextFieldWithValidation securityQuestion = new RadarTextFieldWithValidation("securityQuestion", null,
            true, securityQuestionContainer, componentsToUpdate);
    securityQuestionContainer.add(securityQuestion);
    form.add(securityQuestionContainer);
    componentsToUpdate.add(securityQuestionContainer);

    securityQuestionAnswModel.setObject(String.valueOf(firstNumber + secondNumber));
    HiddenField securityQuestionAnsw = new HiddenField("securityQuestionAnsw", securityQuestionAnswModel);
    securityQuestionContainer.add(securityQuestionAnsw);
    form.add(securityQuestionContainer);
    componentsToUpdate.add(securityQuestionContainer);

    Label successMessage = new Label("successMessage",
            "Thank you. Your registration has been successful and will" + " be confirmed by email shortly") {
        {
            setOutputMarkupId(true);
            setOutputMarkupPlaceholderTag(true);
            form.add(this);
            componentsToUpdate.add(this);
        }

        @Override
        public boolean isVisible() {
            return form.isSubmitted() && !form.hasError();
        }
    };

    Label errorMessage = new Label("errorMessage", "Please fix all errors") {
        {
            setOutputMarkupId(true);
            setOutputMarkupPlaceholderTag(true);
            form.add(this);
            componentsToUpdate.add(this);
        }

        @Override
        public boolean isVisible() {
            return form.isSubmitted() && form.hasError();
        }
    };

    Label securityQuestionMessage = new Label("securityQuestionMessage",
            firstNumber + " + " + secondNumber + " = ? ") {
        {
            setOutputMarkupId(true);
            setOutputMarkupPlaceholderTag(true);
            form.add(this);
            componentsToUpdate.add(this);
        }

        @Override
        public boolean isVisible() {
            return areaModel.getObject() != null;
        }
    };
    securityQuestionMsgContainer.add(securityQuestionMessage);
    form.add(securityQuestionMsgContainer);
    componentsToUpdate.add(securityQuestionMsgContainer);

    // Construct feedback panel
    // for errors not specific to a particular component
    final FeedbackPanel feedbackPanel = new FeedbackPanel("errorFeedback", new IFeedbackMessageFilter() {
        public boolean accept(FeedbackMessage feedbackMessage) {
            String message = feedbackMessage.getMessage().toString();
            return message.contains(ERROR_MESSAGE);
        }
    });

    form.add(feedbackPanel);

    AjaxButton submit = new IndicatingAjaxButton("submit") {
        {
            componentsToUpdate.add(this);
        }

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            target.add(componentsToUpdate.toArray(new Component[componentsToUpdate.size()]));
        }

        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form) {
            target.add(componentsToUpdate.toArray(new Component[componentsToUpdate.size()]));
        }

        @Override
        public boolean isVisible() {
            if (form.isSubmitted() && !form.hasError()) {
                return false;
            }
            return super.isVisible();
        }
    };
    form.add(submit);
    submit.add(new Label("submitLabel", new AbstractReadOnlyModel<Object>() {
        @Override
        public Object getObject() {
            return areaModel.getObject() == null ? "Continue" : "Register";
        }
    }));

    submit.setOutputMarkupId(true);
    submit.setOutputMarkupPlaceholderTag(true);
    componentsToUpdate.add(submit);

    add(form);

}