Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
GWT编辑器框架:实现HasEditorErrors的自定义LeafValueEditor_Gwt_Validation_Bean Validation - Fatal编程技术网

GWT编辑器框架:实现HasEditorErrors的自定义LeafValueEditor

GWT编辑器框架:实现HasEditorErrors的自定义LeafValueEditor,gwt,validation,bean-validation,Gwt,Validation,Bean Validation,我已经将自己的表单字段实现为IsEditor,我希望在应用程序的表单中使用它 public class FormField extends Composite implements IsEditor<LeafValueEditor<String>> { interface FormFieldUiBinder extends UiBinder<Widget, FormField> { } private static FormFiel

我已经将自己的表单字段实现为
IsEditor
,我希望在应用程序的表单中使用它

public class FormField extends Composite implements IsEditor<LeafValueEditor<String>> {

    interface FormFieldUiBinder extends UiBinder<Widget, FormField> {
    }

    private static FormFieldUiBinder uiBinder = GWT.create(FormFieldUiBinder.class);

    interface FormFieldStyle extends CssResource {
        String error();
    }

    @UiField
    TextBox wrapped;

    private String placeholder;

    public FormField() {
        initWidget(uiBinder.createAndBindUi(this));
        wrapped.setTitle("");
    }

    @UiHandler("wrapped")
    public void onFocus(FocusEvent event) {
        Scheduler.get().scheduleDeferred(new ScheduledCommand() {
            @Override
            public void execute() {
                wrapped.selectAll();
            }
        });
    }

    public String getText() {
        return wrapped.getText();
    }

    public void setText(String text) {
            wrapped.setText(text);
    }

    /**
     * Gets the current placeholder text for the text box.
     * 
     * @return the current placeholder text
     */
    public String getPlaceholder() {
        return placeholder;
    }

    /**
     * Sets the placeholder text displayed in the text box.
     * 
     * @param placeholder
     *            the placeholder text
     */
    public void setPlaceholder(String text) {
        placeholder = (text != null ? text : "");
        wrapped.getElement().setPropertyString("placeholder", placeholder);
    }

    public String getTitle() {
        return wrapped.getTitle();
    }

    public void setTitle(String title) {
        wrapped.setTitle(title);
    }

    @Override
    public LeafValueEditor<String> asEditor() {
        return wrapped.asEditor();
    }

    public int getVisibleLength() {
        return wrapped.getVisibleLength();
    }

    public void setVisibleLength(int length) {
        wrapped.setVisibleLength(length);
    }

    public boolean isReadOnly() {
        return wrapped.isReadOnly();
    }

    public void setReadOnly(boolean readOnly) {
        wrapped.setReadOnly(readOnly);
    }

    public boolean isEnabled() {
        return wrapped.isEnabled();
    }

    public void setEnabled(boolean enabled) {
        wrapped.setEnabled(enabled);
    }

    public void setWidth(String width) {
        wrapped.setWidth(width);
    }

}
以及在编辑后获取值:

Account account = editorDriver.flush();
现在我想对错误实施反馈。我的GWTBean验证框架也运行良好。我只需要显示错误

因此,我接下来要尝试的是让FormField实现HasEditorErrors。这是我的问题

public class FormField extends Composite implements IsEditor<LeafValueEditor<String>>, HasEditorErrors<String> 
这似乎很琐碎。我曾尝试为wrapped添加getter/setter,但这并没有真正的帮助

EDIT:有一段时间,我认为解决方案应该是实现
HasEditorErrors
而不是
HasEditorErrors
,以防止层次结构下降到包装的文本框,但结果类似:

            [ERROR] [klawtapp] - Could not find a getter for path wrapped in proxy type com.google.gwt.editor.client.LeafValueEditor

只需使用
@Editor注释您的
包装的
文本框。忽略

或者,您可以删除
实现IsEditor
,而是用
@Path(“”
)注释
包装的
字段(您必须使用
null
值进行测试,尽管您可能会遇到这些值,因为我不确定它是否能正常工作)


或者,您可以选择实现自己的
LeafValueEditor
,而不是依赖
TextBox

中的编辑器,只需使用
@Editor.Ignore
包装的
文本框进行注释即可

或者,您可以删除
实现IsEditor
,而是用
@Path(“”
)注释
包装的
字段(您必须使用
null
值进行测试,尽管您可能会遇到这些值,因为我不确定它是否能正常工作)


或者,您也可以选择实现自己的
LeafValueEditor
,而不是依赖
文本框中的编辑器,谢谢。这是可行的,或者至少编译/生成,但editorDriver始终不报告错误,而使用验证器“手动”时,会正确报告冲突。有什么想法吗?我为FormField类实现了HasEditorErrors,并在包装的文本框中添加了@Editor.Ignore。我相信您必须“手动”使用验证器(与编辑器框架AFAIK没有“集成”),并在
editordrive
上调用
setConstraintViolations
。好的,我明白了。javadoc似乎暗示这是自动的,请参阅“boolean hasrerrors”=>指示上次调用{@link#flush()}是否导致任何错误。但是对flush()的调用根本不会影响错误。这些错误是由编辑器自己生成的(
EditorDelegate
上的
reportError
IntegerBox
将生成一个这样的错误,例如,如果您在框中键入无法解析为整数的内容),谢谢。这可以工作,或者至少编译/生成,但是editorDriver在使用validator“手动”时总是报告没有错误,这些违规行为会被正确报告。有什么想法吗?我为FormField类实现了HasEditorErrors,并在包装的文本框中添加了@Editor.Ignore。我相信您必须“手动”使用验证器(与编辑器框架AFAIK没有“集成”),并在
editordrive
上调用
setConstraintViolations
。好的,我明白了。javadoc似乎暗示这是自动的,请参阅“boolean hasrerrors”=>指示上次调用{@link#flush()}是否导致任何错误。但是对flush()的调用根本不会影响错误。这些错误是由编辑器本身生成的(
EditorDelegate
上的
reportError
IntegerBox
将生成一个这样的错误,例如,如果您在框中键入无法解析为整数的内容)
    editorDriver.initialize(editor);
    editorDriver.edit(presenter.getAccount());
Account account = editorDriver.flush();
public class FormField extends Composite implements IsEditor<LeafValueEditor<String>>, HasEditorErrors<String> 
[DEBUG] [klawtapp] - Rebinding com.example.screen.ui.center.AccountPersonaliaImpl.EditorDriver
    [DEBUG] [klawtapp] - Invoking generator com.google.gwt.editor.rebind.SimpleBeanEditorDriverGenerator
        [DEBUG] [klawtapp] - Creating Editor model for com.example.screen.ui.center.AccountPersonaliaImpl.EditorDriver
            [DEBUG] [klawtapp] - Descending into firstName
                [ERROR] [klawtapp] - Could not find a getter for path wrapped in proxy type java.lang.String
            [DEBUG] [klawtapp] - Descending into lastName
                [ERROR] [klawtapp] - Could not find a getter for path wrapped in proxy type java.lang.String
            [ERROR] [klawtapp] - Unable to create Editor model due to previous errors
[ERROR] [klawtapp] - Deferred binding failed for 'com.example.screen.ui.center.AccountPersonaliaImpl.EditorDriver'; expect subsequent failures
            [ERROR] [klawtapp] - Could not find a getter for path wrapped in proxy type com.google.gwt.editor.client.LeafValueEditor