Directory

← Back

Forms

Forms for Vaadin

Author

Rating

Popularity

<100

Forms aims to provide the developer with easier ways to create Vaadin Form objects and more control over the layout of the form.

Currently, this add-on only provides a single implementation named GridForm. This object is a Vaadin Form using a GridLayout to lay out the components. While a Vaadin Form can use a GridLayout already, there is no support for actually telling the form where to place the components nor is there the ability to have components span multiple rows and columns. GridForm attempts to solve this problem.

Inspiration for this add-on comes from the excellent JGoodies Forms library. The goal of this add-on is to provide the developer means for easily creating elegant forms and components using methods crafted by JGoodies Forms.

Sample code

import com.vaadin.data.util.BeanItem;
import com.vaadin.ui.Button;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Label;

import org.vaadin.addons.forms.GridConstraints;
import org.vaadin.addons.forms.GridForm;

public class LocationForm extends GridForm {

    public LocationForm() {
        super(3, 5);
        this.setSizeFull();
        this.setImmediate(false);
        this.setWriteThrough(false);
        this.setReadThrough(false);

        GridConstraints constraints = new GridConstraints();
        constraints.addConstraint("address1", 0, 0, 1, 0);
        constraints.addConstraint("address2", 2, 0);
        constraints.addConstraint("city", 0, 1);
        constraints.addConstraint("state", 1, 1);
        constraints.addConstraint("zip", 2, 1);
        constraints.addConstraint("notes", 0, 2, 1, 4);
        constraints.addConstraint("county", 2, 2);
        constraints.addConstraint("x", 2, 3);
        constraints.addConstraint("y", 2, 4);

        this.setItemDataSource(new BeanItem<Location>(new Location()), constraints);

        this.getField("address1").setCaption("Address");
        this.getField("address1").setRequired(true);
        this.getField("address2").setCaption("Apt./Suite");

        HorizontalLayout layout = new HorizontalLayout();
        layout.setSpacing(true);
        layout.setWidth("100%");

        Label label = new Label();
        layout.addComponent(label);

        Button cancelButton = new Button("Cancel");
        cancelButton.addListener(new Button.ClickListener() {
            public void buttonClick(Button.ClickEvent event) {
                discard();
                close();
            }
        });
        layout.addComponent(cancelButton);

        Button saveButton = new Button("Save");
        saveButton.addListener(new Button.ClickListener() {
            public void buttonClick(Button.ClickEvent event) {
                commit();
                close();
            }
        });
        layout.addComponent(saveButton);

        layout.setExpandRatio(label, 1);

        this.setFooter(layout);
    }

    private void close() {
        getApplication().getMainWindow().removeWindow(getWindow());
    }
}
public class Location implements Serializable {

    private String address1 = "";
    private String address2 = "";
    private String city = "";
    private String state = "";
    private String zip = "";
    private String county = "";
    private String notes = "";
    private double x;
    private double y;

    public String getAddress1() {
        return address1;
    }

    public void setAddress1(String address1) {
        this.address1 = address1;
    }

    public String getAddress2() {
        return address2;
    }

    public void setAddress2(String address2) {
        this.address2 = address2;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    public String getZip() {
        return zip;
    }

    public void setZip(String zip) {
        this.zip = zip;
    }

    public String getCounty() {
        return county;
    }

    public void setCounty(String county) {
        this.county = county;
    }

    public String getNotes() {
        return notes;
    }

    public void setNotes(String notes) {
        this.notes = notes;
    }

    public double getX() {
        return x;
    }

    public void setX(double x) {
        this.x = x;
    }

    public double getY() {
        return y;
    }

    public void setY(double y) {
        this.y = y;
    }
}
import com.vaadin.Application;
import com.vaadin.ui.Button;
import com.vaadin.ui.Window;

public class LocationApplication extends Application {

    public void init() {
        Window mainWindow = new Window("Location Form Sample");

        Button button = new Button("Open Location Form");
        button.setWidth("150px");
        button.setHeight("30px");
        button.addListener(new Button.ClickListener() {
            public void buttonClick(Button.ClickEvent event) {
                Window window = new Window("Update Location");
                window.addComponent(new LocationForm());
                window.setModal(true);
                window.setResizable(false);
                window.setWidth("510px");
                window.setHeight("370px");
                getMainWindow().addWindow(window);
                window.center();
            }
        });
        mainWindow.addComponent(button);
        setMainWindow(mainWindow);
    }
}

Compatibility

(Loading compatibility data...)

Was this helpful? Need more help?
Leave a comment or a question below. You can also join the chat on Discord or ask questions on StackOverflow.

Version

  • Fixed bug that nulled out any Existing GridConstraints after call setItemDataSource() without a GridConstraints parameter
Released
2011-10-27
Maturity
BETA
License
Apache License 2.0

Compatibility

Framework
Vaadin 6.6+
Browser
Browser Independent

Forms - Vaadin Add-on Directory

Forms for Vaadin Forms - Vaadin Add-on Directory
Forms aims to provide the developer with easier ways to create Vaadin Form objects and more control over the layout of the form. Currently, this add-on only provides a single implementation named GridForm. This object is a Vaadin Form using a GridLayout to lay out the components. While a Vaadin Form can use a GridLayout already, there is no support for actually telling the form where to place the components nor is there the ability to have components span multiple rows and columns. GridForm attempts to solve this problem. Inspiration for this add-on comes from the excellent JGoodies Forms library. The goal of this add-on is to provide the developer means for easily creating elegant forms and components using methods crafted by JGoodies Forms.
Online