在 Apache Wicket Web 框架中,每个组件默认从 getOuputMarkupId() 返回 false。
我很好奇原因。背后的设计决策。
我正在使用 ajax 组件,我需要刷新页面上的其他一些组件。为此,我必须在涉及 ajax 页面刷新的每个组件上设置输出标记 (true)。因为我大量使用 ajax,所以我必须经常这样做。而且不是很方便。除了“最好的代码根本就是没有代码”。
我可以这样处理:
class MyApp extends Application {
@Override
public init() {
Application.addComponentInstantiationListener(
new IComponentInstantiationListener() {
public void onInstantiation(Component component) {
component.setOutputMarkupId(true);
component.setOutputMarkupPlaceholderTag(true);
}
}
);
但是有什么取舍吗?我想到的唯一权衡是:
- 呈现的页面 (html) 更大
- 有一些渲染开销(即当 id 属性写到 html 时)
但那些只有很小的足迹恕我直言。