【问题标题】:validation using fieldgroup property vaadin使用字段组属性 vaadin 进行验证
【发布时间】:2014-06-18 20:42:15
【问题描述】:

我有这个文本框

   firstNameField = new TextField("First Name");
    firstNameField.setRequired(true);
    firstNameField.setImmediate(true);
    firstNameField.setValidationVisible(true);
    firstNameField.setWidth(COMMON_FIELD_WIDTH);
    firstNameField.addValidator(new StringLengthValidator(
            "Allowed Length of Characters(2-30) ", 2, 30, true));

    firstNameField.setNullRepresentation(null);

此字段绑定到 bean 属性 firstName

  binderFieldGroupPersonalDetails.bind(firstNameField, "firstName");

现在当我使用时

  binderFieldGroupPersonalDetails.commit;

提交时图标没有验证错误
但是将鼠标悬停在字段上时会显示 requirederror

如何提示用户有关空字段的信息???
我试过这个

   Button.ClickListener btnSaveContinuePersonalDetailsClickListener = new Button.ClickListener() {

    public void buttonClick(ClickEvent event) {
        try {
            // changes
                // the
                // tab
                // layout
                // to
                // next
                // tab
                // on
                // Successful
                // commit
            binderFieldGroupPersonalDetails.commit();
            TabSheetLayout
                    .setSelectedTab(contentAccountDetailsRegistrationForm);

        } catch (CommitException e) {


            //lets add up all the error msg for missing fields
            Collection<Field<?>> fields = binderFieldGroupPersonalDetails.getFields();
            Iterator<Field<?>> it = fields.iterator();
            String errorMessage = "";
            while(it.hasNext()){
                if(it.next().getValue()==null||it.next().getValue()==""){
                    errorMessage=errorMessage.concat("  "+it.next().getCaption()+" is required <br>");

                }
            }
            getUI().showNotification("<h6>"+errorMessage+"<h6>",Notification.TYPE_ERROR_MESSAGE);

                e.printStackTrace();
        }

    }
};  

【问题讨论】:

    标签: java web frameworks vaadin


    【解决方案1】:
    binderFieldGroupPersonalDetails.setBuffered(true);
    
    // A button to commit the buffer
    button.addComponent(new Button("OK", new ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            try {
                binder.commit();
                Notification.show("Thanks!");
            } catch (CommitException e) {
                Notification.show(e.getMessage());
            }
        }
    }));
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-06-20
    • 1970-01-01
    • 1970-01-01
    • 2021-06-27
    • 2016-09-26
    • 1970-01-01
    • 1970-01-01
    • 2019-05-12
    相关资源
    最近更新 更多