当前位置: 首页>>代码示例>>Java>>正文


Java Binder.bindInstanceFields方法代码示例

本文整理汇总了Java中com.vaadin.data.Binder.bindInstanceFields方法的典型用法代码示例。如果您正苦于以下问题:Java Binder.bindInstanceFields方法的具体用法?Java Binder.bindInstanceFields怎么用?Java Binder.bindInstanceFields使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.vaadin.data.Binder的用法示例。


在下文中一共展示了Binder.bindInstanceFields方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: init

import com.vaadin.data.Binder; //导入方法依赖的package包/类
@Override
protected void init(VaadinRequest vaadinRequest) {
    // crate a binder for a form, specifying the data class that will be used in binding
    Binder<ImageData> binder = new Binder<>(ImageData.class);

    // specify explicit binding in order to add validation and converters
    binder.forMemberField(imageSize)
            // input should not be null or empty
            .withValidator(string -> string != null && !string.isEmpty(), "Input values should not be empty")
            // convert String to Integer, throw ValidationException if String is in incorrect format
            .withConverter(new StringToIntegerConverter("Input value should be an integer"))
            // validate converted integer: it should be positive
            .withValidator(integer -> integer > 0, "Input value should be a positive integer");

    // tell binder to bind use all fields from the current class, but considering already existing bindings
    binder.bindInstanceFields(this);

    // crate data object with predefined imageName and imageSize
    ImageData imageData = new ImageData("Lorem ipsum", 2);

    // fill form with predefined data from data object and
    // make binder to automatically update the object from the form, if no validation errors are present
    binder.setBean(imageData);

    binder.addStatusChangeListener(e -> {
        // the real image drawing will not be considered in this article

        if (e.hasValidationErrors() || !e.getBinder().isValid()) {
            Notification.show("Form contains validation errors, no image will be drawn");
        } else {
            Notification.show(String.format("I will draw image with \"%s\" text and width %d\n",
                    imageData.getText(), imageData.getSize()));
        }
    });

    // add a form to layout
    setContent(new VerticalLayout(text, imageSize));
}
 
开发者ID:SomeoneToIgnore,项目名称:vaadin-binders,代码行数:39,代码来源:BinderUI.java

示例2: getFieldGroupFor

import com.vaadin.data.Binder; //导入方法依赖的package包/类
protected final Binder<ET> getFieldGroupFor(ET pojo) {
    EditorStuff es = pojoToEditor.get(pojo);
    if (es == null) {
        Object o = createEditorInstance(pojo);
        Binder<ET> binder = new BeanValidationBinder<>(elementType);
        binder.bindInstanceFields(o);
        binder.setBean(pojo);
        binder.addStatusChangeListener(scl);
        es = new EditorStuff(binder, o);
        // TODO listen for all changes for proper modified/validity changes
        pojoToEditor.put(pojo, es);
    }
    return es.bfg;
}
 
开发者ID:viritin,项目名称:viritin,代码行数:15,代码来源:AbstractElementCollection.java

示例3: getComponentFor

import com.vaadin.data.Binder; //导入方法依赖的package包/类
protected final Component getComponentFor(ET pojo, String property) {
    EditorStuff editorsstuff = pojoToEditor.get(pojo);
    if (editorsstuff == null) {
        Object o = createEditorInstance(pojo);
        Binder<ET> binder = new BeanValidationBinder<>(elementType);
        binder.bindInstanceFields(o);
        binder.addStatusChangeListener(scl);
        editorsstuff = new EditorStuff(binder, o);
        // TODO listen for all changes for proper modified/validity changes
        pojoToEditor.put(pojo, editorsstuff);
    }
    Component c = null;
    Optional<Binder.Binding<ET, ?>> binding = editorsstuff.bfg.getBinding(property);
    if (binding.isPresent()) {
        c = (Component) binding.get().getField();
    } else {
        try {
            // property that is not a property editor field but custom UI "column"
            java.lang.reflect.Field f = editorType.getDeclaredField(property);
            f.setAccessible(true);
            c = (Component) f.get(editorsstuff.editor);
        } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException ex) {
            Logger.getLogger(AbstractElementCollection.class.getName()).
                    log(Level.SEVERE, null, ex);
        }
        if (c == null) {
            c = new Label("");
        }
    }

    return c;
}
 
开发者ID:viritin,项目名称:viritin,代码行数:33,代码来源:AbstractElementCollection.java

示例4: enter

import com.vaadin.data.Binder; //导入方法依赖的package包/类
@Override
public void enter(ViewChangeEvent event) {
    final VerticalLayout layout = new VerticalLayout();
    layout.addComponent(new Label("Create new user"));

    final Binder<User> binder = new Binder<>(User.class);
    layout.addComponent(firstName);
    layout.addComponent(lastName);
    layout.addComponent(username);
    layout.addComponent(password);
    layout.addComponent(email);

    binder.forField(username).withValidator((value, context) -> {
        if (value.isEmpty()) {
            return ValidationResult.error("Username cannot be empty");
        }

        if (userDAO.getUserBy(value) != null) {
        	return ValidationResult.error("Username is taken");
        }
        return ValidationResult.ok();
    }).bind("username");

    final Label messageLabel = new Label();
    layout.addComponent(messageLabel);

    Button commitButton = new Button("Create");
    commitButton.addClickListener(clickEvent -> {
        User user = binder.getBean();
        if (user != null) {
            try {
                binder.writeBean(user);
                userDAO.saveUser(user);
                binder.setBean(new User(ID_FACTORY.incrementAndGet(), "", "", "", "", "", false));
                messageLabel.setValue("User created");
            } catch (ValidationException e) {
                messageLabel.setValue(e.getMessage());
            }
        }
    });

    // bind remaining fields
    binder.bindInstanceFields(this);
    binder.setBean(new User(ID_FACTORY.incrementAndGet(), "",
            "", "", "", "", false));

    layout.addComponent(commitButton);
    setCompositionRoot(layout);
}
 
开发者ID:vaadin,项目名称:cdi-tutorial,代码行数:50,代码来源:CreateUserView.java


注:本文中的com.vaadin.data.Binder.bindInstanceFields方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。