我有这个 ListEditor 负责编辑客户的许可证。在我的CustomerEditor
中,thieLicensesEditor
绑定到类型为 的路径许可证List<License>>
。
客户 (1)--> (许多) 许可证 (java.util.List)
现在,验证规则规定每个客户至少需要一个许可证。约束违规工作完美。但是如何为 ListEditor 实现 HasEditorErrors ...我想提供自己的错误标记。
我为 HasEditorErrors < T > 的泛型参数 T 注入什么类型?
public interface HasEditorErrors<T> extends Editor<T>
ListEditor 的签名如下...
public class LicensesEditor extends Composite implements IsEditor<ListEditor<License, LicenseInListEditor>>
我试图实现HasEditorErrors<List<License>>
在运行时给出错误:
[调试] [klawtapp] - 下降到许可证 [错误] [klawtapp] - 在代理类型 java.util.List 中找不到路径编辑器的 getter
如果我实施HasEditorErrors<LicensesEditor>
[错误] [klawtapp] 在代理类型 com.klawt.screen.ui.customers.LicensesEditor 中找不到路径编辑器的 getter
在 HasEditorErrors 中保留问号作为实现的接口会产生编译时错误:
LicensesEditor 类型不能扩展或实现 HasEditorErrors。超类型不能指定任何通配符 LicensesEditor.java
有人吗?
更新,下面的完整代码:
public class LicensesEditor extends Composite implements IsEditor<ListEditor<License, LicenseInListEditor>> {
@UiField
Image validationErrorIcon;
interface LicensesEditorUiBinder extends UiBinder<Widget, LicensesEditor> {
}
private static LicensesEditorUiBinder uiBinder = GWT.create(LicensesEditorUiBinder.class);
@UiField
VerticalPanel container;
ListEditor<License, LicenseInListEditor> editor;
public LicensesEditor() {
initWidget(uiBinder.createAndBindUi(this));
editor = ListEditor.of(new LicenseInListEditorSource());
clearErrors();
}
@Override
public ListEditor<License, LicenseInListEditor> asEditor() {
return editor;
}
public void addLicense(License emailAddress) {
editor.getList().add(emailAddress);
if (emailAddress.getAdministrator()) {
setPrimary(editor.getList().size() - 1);
}
}
public void remove(int index) {
editor.getList().remove(index);
}
public void update(int index, License emailAddress) {
editor.getList().remove(index);
editor.getList().add(index, emailAddress);
}
/**
* make the phonenumber at the index the primary phonenumber and the other
* phone numbers not primary.
*
* @param index
*/
public void setPrimary(int index) {
int loop = 0;
for (License emailAddress : Collections.unmodifiableList(editor.getList())) {
emailAddress.setAdministrator(index == loop);
update(loop, emailAddress);
loop++;
}
}
private class LicenseInListEditorSource extends EditorSource<LicenseInListEditor> {
@Override
public LicenseInListEditor create(final int index) {
LicenseInListEditor editor = new LicenseInListEditor();
editor.addDeleteHandler(new ListEditorDeleteEventHandler() {
@Override
public void onEditorEvent(ListEditorDeleteEvent event) {
remove(index);
}
});
editor.addUpdateHandler(new EditorUpdateEventHandler() {
@Override
public void onEditorUpdate(EditorUpdateEvent event) {
License emailAddress = (License) event.getUpdated();
update(index, emailAddress);
if (emailAddress.getAdministrator()) {
setPrimary(index);
}
}
});
container.insert(editor, index);
updateOddEven();
return editor;
}
@Override
public void dispose(LicenseInListEditor subEditor) {
container.remove(subEditor);
updateOddEven();
}
@Override
public void setIndex(LicenseInListEditor editor, int index) {
container.insert(editor, index);
updateOddEven();
}
public void updateOddEven() {
for (int widgetIndex = 0; widgetIndex < container.getWidgetCount(); widgetIndex++) {
container.getWidget(widgetIndex).setStyleName(KlawtResources.INSTANCE.form().listEditorEven(),
(widgetIndex % 2 == 0));
container.getWidget(widgetIndex).setStyleName(KlawtResources.INSTANCE.form().listEditorOdd(),
(widgetIndex % 2 == 1));
}
}
}
// @Override
// public void showErrors(List<EditorError> errors) {
// StringBuilder sb = new StringBuilder();
// int errorCount = 0;
// for (EditorError editorError : errors) {
// if (errorCount > 0) {
// sb.append("\n");
// }
// errorCount++;
// sb.append(editorError.getMessage());
// }
// if (errorCount == 0) {
// clearErrors();
// } else {
// container.setStyleName(KlawtResources.INSTANCE.form().formError(), true);
// validationErrorIcon.setVisible(true);
// validationErrorIcon.setTitle(sb.toString());
// }
// }
private void clearErrors() {
container.setStyleName(KlawtResources.INSTANCE.form().formError(), false);
validationErrorIcon.setVisible(false);
validationErrorIcon.setTitle("");
}
}