0

In Wicket when I disable a Form instance it perfectly disables my input fields, but it fails to disable the submit button, too.

How to disable the submit button, too, preferable without the need to add wicket:id for the submit button?

4

2 回答 2

1

使用 anAjaxSubmitLink并将其添加到表单中。它将与表单一起启用/禁用:

HTML:

<button wicket:id="submit">Submit</button>

爪哇:

form.add(new AjaxSubmitLink("submit"));
于 2014-05-27T19:45:48.333 回答
0

我已经通过自动创建解决了这个问题Buttons。在我WebApplication的 's init()-method 中,我安装了一个AbstractMarkupFilter自动<input type="submit"/>链接:

markupSettings.setMarkupParserFactory(new IMarkupParserFactory() {
    public MarkupParser newMarkupParser(MarkupResourceStream resource) {
        final MarkupParser parser = new MarkupParser(new XmlPullParser(), resource);
        parser.appendMarkupFilter(new AbstractMarkupFilter() {
            public MarkupElement nextTag() throws ParseException {
                final ComponentTag tag = (ComponentTag)getParent().nextTag();
                if (tag == null) {
                    return null;
                }

                if (tag.getId() != null) {
                    return tag;
                }

                if (!tag.isOpen() && !tag.isOpenClose()) {
                    return tag;
                }

                if (tag.getName().equals("input") && !(tag instanceof WicketTag)) {
                    final String type = tag.getAttributes().getString("type");
                    if ("submit".equals(type)) {
                        tag.enableAutolink(true);
                        tag.setId(WicketLinkTagHandler.AUTOLINK_ID);
                        tag.setAutoComponentTag(true);
                        tag.setModified(true);
                    }
                }
                return tag;
            }
        };
        return parser;
    }
});

IComponentResolver然后我在现有的之前安装一个AutoLinkResolver

final List<IComponentResolver> componentResolvers = getPageSettings().getComponentResolvers();
for (int i ; i < componentResolvers.size(); i++) {
    final IComponentResolver resolver = componentResolvers.get(i);
    if (resolver instanceof AutoLinkResolver) {
        componentResolvers.add(i, new IComponentResolver() {
            @Override
            public boolean resolve(MarkupContainer container, MarkupStream markupStream, ComponentTag tag) {
                if (tag.isAutolinkEnabled()) {
                    if (tag.getName().equals("input")) {
                        final String type = tag.getAttribute("type");
                        if ("submit".equals(type)) {
                            final Page page = container.getPage();
                            final String autoId = WicketLinkTagHandler.AUTOLINK_ID + Integer.toString(page.getAutoIndex());
                            if (tag.getId() == null) {
                                tag.setId(autoId);
                                tag.setAutoComponentTag(true);
                            }
                            container.autoAdd(new Button(autoId));
                            return true;
                        }
                    }
                }

                return false;
            }
        });
        break;
    }
}
于 2014-06-05T10:29:22.280 回答