Package com.vaadin.ui

Examples of com.vaadin.ui.Form


import com.vaadin.ui.FormFieldFactory;

public class FormWithPropertyFormatterConnected extends TestBase {
    @Override
    protected void setup() {
        Form form2 = new Form();
        form2.setFormFieldFactory(new FormFieldFactory() {

            @Override
            public Field createField(Item item, Object propertyId,
                    Component uiContext) {
                AbstractField f = (AbstractField) DefaultFieldFactory.get()
                        .createField(item, propertyId, uiContext);
                if (propertyId.equals("age")) {
                    f.setPropertyDataSource(new PropertyFormatter() {

                        @Override
                        public Object parse(String formattedValue)
                                throws Exception {
                            String str = formattedValue.replaceAll("[^0-9.]",
                                    "");
                            if (formattedValue.toLowerCase().contains("months")) {
                                return Double.parseDouble(str) / 12;
                            }
                            return Double.parseDouble(str);
                        }

                        @Override
                        public String format(Object value) {
                            Double dValue = (Double) value;
                            if (dValue < 1) {
                                return ((int) (dValue * 12)) + " months";
                            }
                            return dValue + " years";
                        }
                    });
                    f.setImmediate(true);
                }
                return f;
            }
        });
        form2.setItemDataSource(createItem());

        addComponent(form2);
        addComponent(new Button("B"));
    }
View Full Code Here


    public void init() {

        LegacyWindow w = new LegacyWindow("Test");
        setMainWindow(w);

        final Form f = new Form();
        w.addComponent(f);
        f.setSizeUndefined();
        f.getLayout().setSizeUndefined();

        f.setCaption("Test form with a really long caption");
        f.addField("foo", new TextField("Foo"));
        f.addField("bar", new TextField("A bit longer field caption"));

        HorizontalLayout hl = new HorizontalLayout();
        hl.setWidth("100%");
        Button b = new Button("right aligned");
        hl.addComponent(b);
        hl.setComponentAlignment(b, Alignment.TOP_RIGHT);
        f.setFooter(hl);
    }
View Full Code Here

        getLayout().setSizeFull();

        TestUtils.injectCSS(getMainWindow(),
                ".v-form{ border: 10px solid red; padding:10px;}");

        final Form f = new Form();
        addComponent(f);
        f.setSizeUndefined();
        f.getLayout().setSizeUndefined();

        f.addField("foo", new TextField("Foo"));
        f.addField("bar", new TextField("A bit longer field caption"));

        HorizontalLayout hl = new HorizontalLayout();
        hl.setWidth("100%");
        Button b = new Button("right aligned");
        hl.addComponent(b);
        hl.setComponentAlignment(b, Alignment.TOP_RIGHT);
        f.setFooter(hl);
    }
View Full Code Here

public class FormDescription extends TestBase {

    @Override
    protected void setup() {
        final Form form = new Form();
        form.setDescription("Some description");
        form.addField("AAAA", new TextField());
        addComponent(form);

        addComponent(new Button("Toggle description",
                new Button.ClickListener() {
                    @Override
                    public void buttonClick(ClickEvent event) {
                        if (form.getDescription() == null) {
                            form.setDescription("Form description");
                        } else {
                            form.setDescription(null);
                        }
                    }
                }));

    }
View Full Code Here

    @Override
    protected Component initContent() {
        if (parentForm != null) {
            addressForm = new EmbeddedForm(parentForm);
        } else {
            addressForm = new Form();
        }
        addressForm.setCaption("Address");
        addressForm.setBuffered(true);

        // make sure field changes are sent early
View Full Code Here

    @Override
    public void init() {
        final LegacyWindow main = new LegacyWindow("Ticket2407");
        setMainWindow(main);

        Form form = new Form(new VerticalLayout());
        TextField text = new TextField("This caption shall be visible");
        text.setRequired(true);
        form.addField("test", text);
        main.addComponent(form);
    }
View Full Code Here

        }

    }

    private Form getFormPanelExample() {
        Form f = new Form();
        f.setCaption("Test form");
        CheckBox fb2 = new CheckBox("Test button", true);
        fb2.setComponentError(new SystemError("Test error"));
        f.addField("fb2", fb2);
        TextField ft1 = new TextField("With caption");
        ft1.setComponentError(new SystemError("Error"));
        f.addField("ft1", ft1);
        TextField ft2 = new TextField();
        ft2.setComponentError(new SystemError("Error"));
        ft2.setValue("Without caption");
        f.addField("ft2", ft2);
        TextField ft3 = new TextField("With caption and required");
        ft3.setComponentError(new SystemError("Error"));
        ft3.setRequired(true);
        f.addField("ft3", ft3);
        return f;
    }
View Full Code Here

    @Override
    protected void setup() {
        final VerticalLayout layout = new VerticalLayout();
        layout.setMargin(true);

        final Form form = new Form();
        form.setFooter(null);
        form.setFormFieldFactory(new DefaultFieldFactory() {
            @Override
            public Field createField(Item item, Object propertyId,
                    Component uiContext) {
                if ("custom".equals(propertyId)) {
                    return new BooleanField();
                }
                return super.createField(item, propertyId, uiContext);
            }
        });
        final TwoBooleans data = new TwoBooleans();
        form.setItemDataSource(new BeanItem<TwoBooleans>(data));

        layout.addComponent(form);

        Button submit = new Button("Submit", new ClickListener() {
            @Override
            public void buttonClick(ClickEvent event) {
                form.commit();
                Notification.show("The custom boolean field value is "
                        + data.isCustom() + ".\n"
                        + "The checkbox (default boolean field) value is "
                        + data.isNormal() + ".");
            }
View Full Code Here

                Component uiContext) {
            Field f = super.createField(item, propertyId, uiContext);
            if ("address".equals(propertyId)) {
                // create a custom field for the Address object
                if (addressField == null) {
                    Form form = (embeddedAddress && uiContext instanceof Form) ? (Form) uiContext
                            : null;
                    addressField = new AddressField(form);
                }
                f = addressField;
            }
View Full Code Here

                }
            });

            addComponent(addComp);

            componentEditor = new Form();
            componentEditor.setBuffered(true);
            componentEditor.setCaption("Component properties:");
            componentEditor.setFormFieldFactory(MFieldFactory.get());
            addComponent(componentEditor);

            positionEditor = new Form();
            positionEditor.setCaption("Component position");
            positionEditor.setBuffered(true);
            positionEditor.setFormFieldFactory(MFieldFactory.get());
            addComponent(positionEditor);
View Full Code Here

TOP

Related Classes of com.vaadin.ui.Form

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.