我在Wicket中有这个表单,当具有某个Role的用户登录时必须禁用它。
在onConfigure()方法中,我检查角色,如果它是不允许更改任何内容的那个我禁用表单:
getForm().setEnabled(!isSponsor());
但是,我得到了这个错误:
org.apache.wicket.markup.MarkupException: file:/bla/bla/bla/Panel.html: Component [printButton] (path = [1:work:child:bla:7:bla:fieldContainer:field:modal:content:form:Panel:printButton]) must be applied to a tag of type [button,input,a], not: '<span wicket:id="printButton" id="printButtonb3">' (line 0, column 0)
at de.agilecoders.wicket.core.util.Components.createMarkupException(Components.java:96) ~[wicket-bootstrap-core-0.8.4.jar:?]
at de.agilecoders.wicket.core.util.Components.assertTag(Components.java:80) ~[wicket-bootstrap-core-0.8.4.jar:?]
at de.agilecoders.wicket.core.util.Components.assertTag(Components.java:65) ~[wicket-bootstrap-core-0.8.4.jar:?]
at de.agilecoders.wicket.core.markup.html.bootstrap.button.ButtonBehavior.onComponentTag(ButtonBehavior.java:134) ~[wicket-bootstrap-core-0.8.4.jar:?]
at org.apache.wicket.Component.renderComponentTag(Component.java:3970) ~[wicket-core-6.9.0.jar:6.9.0]
at org.apache.wicket.Component.internalRenderComponent(Component.java:2540) ~[wicket-core-6.9.0.jar:6.9.0]
at org.apache.wicket.MarkupContainer.onRender(MarkupContainer.java:1493) ~[wicket-core-6.9.0.jar:6.9.0]
at org.apache.wicket.Component.internalRender(Component.java:2379) ~[wicket-core-6.9.0.jar:6.9.0]
at org.apache.wicket.Component.render(Component.java:2307) ~[wicket-core-6.9.0.jar:6.9.0]
at org.apache.wicket.MarkupContainer.renderNext(MarkupContainer.java:1390) ~[wicket-core-6.9.0.jar:6.9.0]
at org.apache.wicket.MarkupContainer.renderAll(MarkupContainer.java:1554) ~[wicket-core-6.9.0.jar:6.9.0]
at org.apache.wicket.MarkupContainer.renderComponentTagBody(MarkupContainer.java:1529) ~[wicket-core-6.9.0.jar:6.9.0]
at org.apache.wicket.MarkupContainer.renderAssociatedMarkup(MarkupContainer.java:689) ~[wicket-core-6.9.0.jar:6.9.0]
at org.apache.wicket.markup.html.panel.AssociatedMarkupSourcingStrategy.renderAssociatedMarkup(AssociatedMarkupSourcingStrategy.java:76) ~[wicket-core-6.9.0.jar:6.9.0]
at org.apache.wicket.markup.html.panel.PanelMarkupSourcingStrategy.onComponentTagBody(PanelMarkupSourcingStrategy.java:112) ~[wicket-core-6.9.0.jar:6.9.0]
at org.apache.wicket.Component.internalRenderComponent(Component.java:2549) ~[wicket-core-6.9.0.jar:6.9.0]
at org.apache.wicket.MarkupContainer.onRender(MarkupContainer.java:1493) ~[wicket-core-6.9.0.jar:6.9.0]
at org.apache.wicket.Component.internalRender(Component.java:2379) ~[wicket-core-6.9.0.jar:6.9.0]
at org.apache.wicket.Component.render(Component.java:2307) ~[wicket-core-6.9.0.jar:6.9.0]
at org.apache.wicket.MarkupContainer.renderNext(MarkupContainer.java:1390) ~[wicket-core-6.9.0.jar:6.9.0]
at org.apache.wicket.MarkupContainer.renderAll(MarkupContainer.java:1554) ~[wicket-core-6.9.0.jar:6.9.0]
at org.apache.wicket.MarkupContainer.renderComponentTagBody(MarkupContainer.java:1529) ~[wicket-core-6.9.0.jar:6.9.0]
at org.apache.wicket.MarkupContainer.onComponentTagBody(MarkupContainer.java:1484) ~[wicket-core-6.9.0.jar:6.9.0]
at org.apache.wicket.markup.html.panel.DefaultMarkupSourcingStrategy.onComponentTagBody(DefaultMarkupSourcingStrategy.java:71) ~[wicket-core-6.9.0.jar:6.9.0]
at org.apache.wicket.Component.internalRenderComponent(Component.java:2549) ~[wicket-core-6.9.0.jar:6.9.0]
at org.apache.wicket.MarkupContainer.onRender(MarkupContainer.java:1493) ~[wicket-core-6.9.0.jar:6.9.0]
at org.apache.wicket.Component.internalRender(Component.java:2379) ~[wicket-core-6.9.0.jar:6.9.0]
at org.apache.wicket.Component.render(Component.java:2307) ~[wicket-core-6.9.0.jar:6.9.0]
at org.apache.wicket.MarkupContainer.renderNext(MarkupContainer.java:1390) ~[wicket-core-6.9.0.jar:6.9.0]
at org.apache.wicket.MarkupContainer.renderAll(MarkupContainer.java:1554) ~[wicket-core-6.9.0.jar:6.9.0]
at org.apache.wicket.MarkupContainer.renderComponentTagBody(MarkupContainer.java:1529) ~[wicket-core-6.9.0.jar:6.9.0]
at org.apache.wicket.MarkupContainer.onComponentTagBody(MarkupContainer.java:1484) ~[wicket-core-6.9.0.jar:6.9.0]
at org.apache.wicket.markup.html.panel.DefaultMarkupSourcingStrategy.onComponentTagBody(DefaultMarkupSourcingStrategy.java:71) ~[wicket-core-6.9.0.jar:6.9.0]
at org.apache.wicket.Component.internalRenderComponent(Component.java:2549) ~[wicket-core-6.9.0.jar:6.9.0]
at org.apache.wicket.MarkupContainer.onRender(MarkupContainer.java:1493) ~[wicket-core-6.9.0.jar:6.9.0]
at org.apache.wicket.Component.internalRender(Component.java:2379) ~[wicket-core-6.9.0.jar:6.9.0]
at org.apache.wicket.Component.render(Component.java:2307) ~[wicket-core-6.9.0.jar:6.9.0]
at org.apache.wicket.MarkupContainer.renderNext(MarkupContainer.java:1390) ~[wicket-core-6.9.0.jar:6.9.0]
at org.apache.wicket.MarkupContainer.renderAll(MarkupContainer.java:1554) ~[wicket-core-6.9.0.jar:6.9.0]
at org.apache.wicket.MarkupContainer.renderComponentTagBody(MarkupContainer.java:1529) ~[wicket-core-6.9.0.jar:6.9.0]
at org.apache.wicket.MarkupContainer.onComponentTagBody(MarkupContainer.java:1484) ~[wicket-core-6.9.0.jar:6.9.0]
at org.apache.wicket.markup.html.form.Form.onComponentTagBody(Form.java:1683) ~[wicket-core-6.9.0.jar:6.9.0]
at org.apache.wicket.markup.html.panel.DefaultMarkupSourcingStrategy.onComponentTagBody(DefaultMarkupSourcingStrategy.java:71) ~[wicket-core-6.9.0.jar:6.9.0]
at org.apache.wicket.Component.internalRenderComponent(Component.java:2549) ~[wicket-core-6.9.0.jar:6.9.0]
at org.apache.wicket.MarkupContainer.onRender(MarkupContainer.java:1493) ~[wicket-core-6.9.0.jar:6.9.0]
at org.apache.wicket.Component.internalRender(Component.java:2379) ~[wicket-core-6.9.0.jar:6.9.0]
at org.apache.wicket.Component.render(Component.java:2307) ~[wicket-core-6.9.0.jar:6.9.0]
at org.apache.wicket.MarkupContainer.renderNext(MarkupContainer.java:1390) ~[wicket-core-6.9.0.jar:6.9.0]
at org.apache.wicket.MarkupContainer.renderAll(MarkupContainer.java:1554) ~[wicket-core-6.9.0.jar:6.9.0]
at org.apache.wicket.MarkupContainer.renderComponentTagBody(MarkupContainer.java:1529) ~[wicket-core-6.9.0.jar:6.9.0]
at org.apache.wicket.MarkupContainer.renderAssociatedMarkup(MarkupContainer.java:689) ~[wicket-core-6.9.0.jar:6.9.0]
at org.apache.wicket.markup.html.panel.AssociatedMarkupSourcingStrategy.renderAssociatedMarkup(AssociatedMarkupSourcingStrategy.java:76) ~[wicket-core-6.9.0.jar:6.9.0]
at org.apache.wicket.markup.html.panel.PanelMarkupSourcingStrategy.onComponentTagBody(PanelMarkupSourcingStrategy.java:112) ~[wicket-core-6.9.0.jar:6.9.0]
at org.apache.wicket.Component.internalRenderComponent(Component.java:2549) ~[wicket-core-6.9.0.jar:6.9.0]
at org.apache.wicket.MarkupContainer.onRender(MarkupContainer.java:1493) ~[wicket-core-6.9.0.jar:6.9.0]
at org.apache.wicket.Component.internalRender(Component.java:2379) ~[wicket-core-6.9.0.jar:6.9.0]
at org.apache.wicket.Component.render(Component.java:2307) ~[wicket-core-6.9.0.jar:6.9.0]
at org.apache.wicket.MarkupContainer.renderNext(MarkupContainer.java:1390) ~[wicket-core-6.9.0.jar:6.9.0]
at org.apache.wicket.MarkupContainer.renderAll(MarkupContainer.java:1554) ~[wicket-core-6.9.0.jar:6.9.0]
at org.apache.wicket.MarkupContainer.renderComponentTagBody(MarkupContainer.java:1529) ~[wicket-core-6.9.0.jar:6.9.0]
at org.apache.wicket.MarkupContainer.renderAssociatedMarkup(MarkupContainer.java:689) ~[wicket-core-6.9.0.jar:6.9.0]
at org.apache.wicket.markup.html.panel.AssociatedMarkupSourcingStrategy.renderAssociatedMarkup(AssociatedMarkupSourcingStrategy.java:76) ~[wicket-core-6.9.0.jar:6.9.0]
at org.apache.wicket.markup.html.panel.PanelMarkupSourcingStrategy.onComponentTagBody(PanelMarkupSourcingStrategy.java:112) ~[wicket-core-6.9.0.jar:6.9.0]
at org.apache.wicket.Component.internalRenderComponent(Component.java:2549) ~[wicket-core-6.9.0.jar:6.9.0]
at org.apache.wicket.MarkupContainer.onRender(MarkupContainer.java:1493) ~[wicket-core-6.9.0.jar:6.9.0]
at org.apache.wicket.Component.internalRender(Component.java:2379) ~[wicket-core-6.9.0.jar:6.9.0]
at org.apache.wicket.Component.render(Component.java:2307) ~[wicket-core-6.9.0.jar:6.9.0]
at org.apache.wicket.ajax.XmlAjaxResponse.writeComponent(XmlAjaxResponse.java:127) ~[wicket-core-6.9.0.jar:6.9.0]
at org.apache.wicket.ajax.AbstractAjaxResponse.writeComponents(AbstractAjaxResponse.java:213) ~[wicket-core-6.9.0.jar:6.9.0]
at org.apache.wicket.ajax.AbstractAjaxResponse.writeTo(AbstractAjaxResponse.java:145) ~[wicket-core-6.9.0.jar:6.9.0]
at org.apache.wicket.ajax.AjaxRequestHandler.respond(AjaxRequestHandler.java:363) ~[wicket-core-6.9.0.jar:6.9.0]
at org.apache.wicket.request.cycle.RequestCycle$HandlerExecutor.respond(RequestCycle.java:861) ~[wicket-core-6.9.0.jar:6.9.0]
at org.apache.wicket.request.RequestHandlerStack.execute(RequestHandlerStack.java:64) ~[wicket-request-6.9.0.jar:6.9.0]
at org.apache.wicket.request.RequestHandlerStack.execute(RequestHandlerStack.java:97) ~[wicket-request-6.9.0.jar:6.9.0]
at org.apache.wicket.request.cycle.RequestCycle.execute(RequestCycle.java:261) [wicket-core-6.9.0.jar:6.9.0]
at org.apache.wicket.request.cycle.RequestCycle.processRequest(RequestCycle.java:218) [wicket-core-6.9.0.jar:6.9.0]
at org.apache.wicket.request.cycle.RequestCycle.processRequestAndDetach(RequestCycle.java:289) [wicket-core-6.9.0.jar:6.9.0]
at org.apache.wicket.protocol.http.WicketFilter.processRequestCycle(WicketFilter.java:259) [wicket-core-6.9.0.jar:6.9.0]
at org.apache.wicket.protocol.http.WicketFilter.processRequest(WicketFilter.java:201) [wicket-core-6.9.0.jar:6.9.0]
at org.apache.wicket.protocol.http.WicketServlet.doGet(WicketServlet.java:137) [wicket-core-6.9.0.jar:6.9.0]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707) [servlet-api-2.5-20081211.jar:?]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820) [servlet-api-2.5-20081211.jar:?]
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:502) [jetty-6.1.15.jar:6.1.15]
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1148) [jetty-6.1.15.jar:6.1.15]
at org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal(OpenEntityManagerInViewFilter.java:180) [spring-orm-3.2.8.RELEASE.jar:3.2.8.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-3.2.8.RELEASE.jar:3.2.8.RELEASE]
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1139) [jetty-6.1.15.jar:6.1.15]
at org.apache.logging.log4j.core.web.Log4jServletFilter.doFilter(Log4jServletFilter.java:66) [log4j-core-2.0-beta9.jar:2.0-beta9]
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1139) [jetty-6.1.15.jar:6.1.15]
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:378) [jetty-6.1.15.jar:6.1.15]
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216) [jetty-6.1.15.jar:6.1.15]
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181) [jetty-6.1.15.jar:6.1.15]
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765) [jetty-6.1.15.jar:6.1.15]
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:417) [jetty-6.1.15.jar:6.1.15]
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152) [jetty-6.1.15.jar:6.1.15]
at org.mortbay.jetty.Server.handle(Server.java:324) [jetty-6.1.15.jar:6.1.15]
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:535) [jetty-6.1.15.jar:6.1.15]
at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:865) [jetty-6.1.15.jar:6.1.15]
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:539) [jetty-6.1.15.jar:6.1.15]
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212) [jetty-6.1.15.jar:6.1.15]
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404) [jetty-6.1.15.jar:6.1.15]
at org.mortbay.jetty.bio.SocketConnector$Connection.run(SocketConnector.java:228) [jetty-6.1.15.jar:6.1.15]
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:520) [jetty-util-6.1.15.jar:6.1.15]
2014-10-27 12:22:10,627 WARN [6748295@qtp-24450551-0 RequestCycleExtra] ********************************
2014-10-27 12:22:10,627 ERROR [6748295@qtp-24450551-0 DefaultExceptionMapper] Unexpected error occurred
但是在标记中我有这个:
<a wicket:id="printButton">Print View</a>
在java文件中,printButton是BootstrapAjaxLink
。
如果我删除了禁用表单的行,那么一切正常......
答案 0 :(得分:0)
所以我发现BootrstrapAjaxLink扩展了具有以下方法的AjaxLink:
@Override
protected void onComponentTag(ComponentTag tag)
{
super.onComponentTag(tag);
if (isLinkEnabled())
{
// disable any href attr in markup
if (tag.getName().equalsIgnoreCase("a") || tag.getName().equalsIgnoreCase("link") ||
tag.getName().equalsIgnoreCase("area"))
{
tag.put("href", "#");
}
}
else
{
disableLink(tag);
}
}
和disableLink如下:
/**
* Alters the tag so that the link renders as disabled.
*
* This method is meant to be called from {@link #onComponentTag(ComponentTag)} method of the
* derived class.
*
* @param tag
*/
protected void disableLink(final ComponentTag tag)
{
// if the tag is an anchor proper
if (tag.getName().equalsIgnoreCase("a") || tag.getName().equalsIgnoreCase("link") ||
tag.getName().equalsIgnoreCase("area"))
{
// Change anchor link to span tag
tag.setName("span");
// Remove any href from the old link
tag.remove("href");
tag.remove("onclick");
}
// if the tag is a button or input
else if ("button".equalsIgnoreCase(tag.getName()) ||
"input".equalsIgnoreCase(tag.getName()))
{
tag.put("disabled", "disabled");
}
}
这就是问题所以...所以如果我覆盖它,它会起作用......但是如果wicket稍后会抱怨它,为什么会将链接更改为span?
答案 1 :(得分:0)
大约是BootstrapAjaxLink
,如果你look的源代码,那么你会看到,它添加了ButtonBehavior
,它覆盖了onComponentTag
方法({{ 3}})以下检查:
Components.assertTag(component, tag, "a", "button", "input");
此代码会引发错误,因为已禁用的链接包含标记span
,如您所述。
不知道,为什么它是这样实现的,是的,您可以覆盖disableLink
方法,但更好的方法是使用BootstrapAjaxButton
和<input type="submit" value="ok"/>
标记。
它只会将disabled="disabled"
标记添加到禁用按钮的标记中,并且不会抛出错误。