Example usage for org.apache.wicket.markup.html.form FormComponent setDefaultModelObject

List of usage examples for org.apache.wicket.markup.html.form FormComponent setDefaultModelObject

Introduction

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

Prototype

Component setDefaultModelObject(Object object);

Source Link

Usage

From source file:gr.interamerican.wicket.bo2.utils.SelfDrawnUtils.java

License:Open Source License

/**
 * Code called on any self-drawn form component.
 * // w  w  w.  jav  a2s  . c o m
 * @param component
 *        FormComponent
 * @param descriptor
 *        BoPropertyDescriptor
 * 
 * @param <T>
 *        Type of component's model object.
 */
public static <T> void standardSelfDrawnFormComponentStuff(FormComponent<T> component,
        BoPropertyDescriptor<T> descriptor) {
    component.setOutputMarkupPlaceholderTag(true);
    component.add(ValidationStyleBehavior.INSTANCE);
    component.add(new BoPropertyDescriptorValidatorWrapper<T>(descriptor));
    if (descriptor.isHasDefault() && component.getDefaultModelObject() == null) {
        component.setDefaultModelObject(descriptor.getDefaultValue());
    }
    if (descriptor.isReadOnly()) {
        disableComponent(component);
    }
    /*
     * This check cannot be off-loaded to the NotNullValidator, since
     * in this case, wicket will not process any validators attached
     * on the component. Having to set this here means that state changes
     * of the nullAllowed property of the BoPropertyDescriptor are not
     * propagated to the self-drawn Component. This is not, however, a
     * major issue, since it is not expected that the BoPropertyDescriptor
     * of a self-drawn Component will have this property changed after
     * the Component is created.
     */
    component.setRequired(!descriptor.isNullAllowed());
}

From source file:org.artifactory.webapp.wicket.page.config.repos.remote.importer.RemoteRepoImportPanel.java

License:Open Source License

public RemoteRepoImportPanel(CachingDescriptorHelper cachingDescriptorHelper) {
    setWidth(740);/*from  w w  w  . j  av  a2s  .  c om*/
    add(new CssClass("import-remote-repos"));
    Form loadForm = new SecureForm("loadForm");
    add(loadForm);

    MarkupContainer loadBorder = new TitledBorder("loadBorder");
    loadForm.add(loadBorder);

    loadBorder.add(new HelpBubble("urlHelp",
            "Enter the base URL of another Artifactory server you want to import repository definitions from."));
    FormComponent<String> urlTextField = new TextField<>("url", new PropertyModel<String>(this, "url"));
    urlTextField.add(new UriValidator("http", "https"));
    setPersistent(urlTextField);
    urlTextField.setOutputMarkupId(true);
    urlTextField.setRequired(true);
    urlTextField.setDefaultModelObject("http://repo.jfrog.org/artifactory");
    loadBorder.add(urlTextField);
    loadBorder.add(getLoadButton(loadForm));

    Form listForm = new SecureForm("listForm");
    add(listForm);

    MarkupContainer listBorder = new TitledBorder("listBorder");
    listForm.add(listBorder);
    createRepositoryList(listBorder);

    add(new ModalCloseLink("cancel"));
    //Submit button
    importButton = getImportButton(cachingDescriptorHelper, listForm);
    importButton.setOutputMarkupId(true);
    add(importButton);
    listForm.add(new DefaultButtonBehavior(importButton));
}