如何预测哪些 Wicket 组件将在最终页面中呈现其标签?
对于某些 Wicket 组件,如果我调用 setOutputMarkupId(true)
,它们会在渲染时发出警告。
Markup id set on a component that is usually not rendered into markup.
我想为实际上最终出现在 HTML 中的每个组件输出一个 id,以便我可以使用 XPath 找到它们进行测试。如何从 Component
的类或属性预测它对 setOutputMarkupId(true)
是否合理?
更多细节 - 在我的 Application
中,我重写了
protected void init() {
super.init();
addComponentInstantiationListener(new IComponentInstantiationListener() {
public void onInstantiation(Component component) {
if (!(component instanceof WebMarkupContainer)) return;
if (component instanceof WebMarkupContainerWithAssociatedMarkup) return;
if (component instanceof Border.BorderBodyContainer) return;
WebMarkupContainer container = (WebMarkupContainer) component;
if (container.isTransparentResolver()) return;
component.setOutputMarkupId(true);
}});
对于页面示例,这个任意的 gubbins 可以达到目的,但它看起来确实相当任意!
For some Wicket components, if I call setOutputMarkupId(true)
they warn when they are rendered.
Markup id set on a component that is usually not rendered into markup.
I'd like to output an id for every component that will actually end up in the HTML in order that I can find them with XPath for testing. How can I predict from class or properties of a Component
whether it is sensible to setOutputMarkupId(true)
?
More detail - in my Application
I'm overriding
protected void init() {
super.init();
addComponentInstantiationListener(new IComponentInstantiationListener() {
public void onInstantiation(Component component) {
if (!(component instanceof WebMarkupContainer)) return;
if (component instanceof WebMarkupContainerWithAssociatedMarkup) return;
if (component instanceof Border.BorderBodyContainer) return;
WebMarkupContainer container = (WebMarkupContainer) component;
if (container.isTransparentResolver()) return;
component.setOutputMarkupId(true);
}});
For a sample of pages, this arbitrary gubbins does the trick, but it does seem pretty arbitrary!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
DataView
和ListView
等转发器组件没有自己的标记,但使用Item
重复标记。您可以检查该组件是否是instanceof RepeatingView
。这个问题很容易通过下面的错误示例来说明:
这里我们没有将标签添加到列表项,而是添加到列表视图。但这失败了。代码应该是:
Repeater components like
DataView
andListView
don't have their own markup, but repeat the markup withItem
s. You can check if the component isinstanceof RepeatingView
.This problem is easily shown by the following, wrong, example:
Here we don't add the label to the list item, but rather the listview. And that fails. The code should've been:
还要忽略自动组件 (Component.isAuto())。
此类组件例如:
、
等。Also ignore auto-components (Component.isAuto()).
Such components are for example:
<wicket:container>
,<wicket:enclosure>
, etc.这只是一个想法。我没有尝试这个,现在不能...
您可以通过检查是否绑定到 WicketTag 来找到可能会呈现的组件(未呈现或至少是导致此消息的组件) )。
这可以像这样完成:
再次强调:这不是经过尝试的解决方案,只是侵入此编辑器的一些代码行。它被设计为一个指针,而不是一段随时可用的代码。
This is just an idea. I didn't try this ans can't right now...
You could find the components, that will propably be rendered by checking if the are tied to a WicketTag (which are not rendered or at least which are the ones causing this message).
This can be done like this:
Again: This is no tried solution, just some lines of code hacked into this editor. It's indended as a pointer not as a ready to use piece of code.