在Apache Wicket Web框架中,每个组件默认从getOuputMarkupId()返回false 。
我很好奇这个原因。背后的设计决定。
我正在使用ajax组件,我需要刷新页面上的其他组件。为此,我得到了ajax页面刷新中涉及的每个组件的setOutputMarkupId(true)。因为我经常使用ajax,所以我经常这样做。 这不是很方便。除了“最佳代码完全没有代码”。
我可以这样处理:
class MyApp extends Application {
@Override
public init() {
Application.addComponentInstantiationListener(
new IComponentInstantiationListener() {
public void onInstantiation(Component component) {
component.setOutputMarkupId(true);
component.setOutputMarkupPlaceholderTag(true);
}
}
);
但是有任何权衡吗? 我认为只有权衡取舍:
但那些只有很小的足迹。
答案 0 :(得分:4)
它无法从.html中提取id(但是,它可以在1.5中)。 所以这会覆盖那些你可能用于css / js等的id
答案 1 :(得分:0)
从内存中我认为它没有默认设置它会覆盖任何现有的dom id,如果你使用dom id选择器,这可能会弄乱你的css。
如果您没有看到此问题,那么您的解决方案似乎很好。