Pages

Wednesday, May 9, 2012

Vaadin - Form Data Saving into a second form

Add the following unit into your vaadin application (it runs under the lehel.sipos.vaadin package):

/*
 * MyApplication.java
 *
 * Created on 2012. május 9., 12:16
 */

package lehel.sipos.vaadin;          

import com.vaadin.Application;
import com.vaadin.data.Validator.EmptyValueException;
import com.vaadin.data.util.ObjectProperty;
import com.vaadin.data.util.PropertysetItem;
import com.vaadin.data.validator.StringLengthValidator;
import com.vaadin.ui.*;
import com.vaadin.ui.themes.Reindeer;
/**
 *
 * @author Sipos Lehel
 * @version
 */

public class MyApplication extends Application {

    @Override
    public void init() {
    Window mainWindow = new Window("MyApplication");
              
        // Some data source
        PropertysetItem item = new PropertysetItem();
        item.addItemProperty("firstName", new ObjectProperty<String>(""));
        item.addItemProperty("lastName",  new ObjectProperty<String>(""));
       
        // A buffered form bound to a data source - main form for input data
        final Form form = new Form();
        form.setItemDataSource(item);
        form.setWriteThrough(false);
       
        //caption of text fields in main form
        form.getField("firstName").setCaption("Keresztnév");
        form.getField("lastName").setCaption("Vezetéknév");       

        // A required field
        form.getField("firstName").setRequired(true);
       
        // A required field with an error message
        TextField lastName = (TextField) form.getField("lastName");
        lastName.setRequired(true);
        lastName.setRequiredError("Add meg a vezetéknevet");
        lastName.setImmediate(true);
        lastName.setValidationVisible(true);
        lastName.addValidator(new StringLengthValidator("Nem lehet üres", 1, 100, false));

        // Commit the buffered form data to the data source
        form.getFooter().addComponent(new Button("Mentés", new Button.ClickListener() {
            public void buttonClick(Button.ClickEvent event) {
                try {
                    if (!form.isValid())
                        form.setValidationVisible(true);
                    else
                        form.commit();
                } catch (EmptyValueException e) {
                    // A required value was missing
                }
            }
        }));

        // Have a read-only form that displays the content of the first form after a data commit
        Form roform = new Form();
        roform.setItemDataSource(item);       
        roform.addStyleName(Reindeer.LAYOUT_WHITE);       
        roform.setReadOnly(true);
        //caption of text fields in the readonly form form
        roform.getField("firstName").setCaption("Elmentett keresztnév");
        roform.getField("lastName").setCaption("Elmentett vezetéknév");       
       
       
       
        //putting the input form near the readonly form
        HorizontalLayout hlayout = new HorizontalLayout();
        hlayout.setSpacing(true);
        hlayout.setWidth("600px");
        hlayout.addComponent(form);
        hlayout.addComponent(roform);       
       
        mainWindow.addComponent(hlayout);
        setMainWindow(mainWindow);
    }

}

Tuesday, May 8, 2012

Vaadin

Vaadin is a web application framework for Rich Internet Applications (RIA). In contrast to Javascript libraries and browser-plugin based solutions, it features a robust server-side architecture. This means that the largest part of the application logic runs securely on the server. Google Web Toolkit (GWT) is used on the browser side to ensure a rich and fluent user experience.

JavaFX

JavaFX is the next step in the evolution of Java as a rich client platform. It is designed to provide a lightweight, hardware-accelerated Java UI platform for enterprise business applications. With JavaFX, developers can preserve existing investments by reusing Java libraries in their applications. They can even access native system capabilities, or seamlessly connect to server-based middleware applications.