規定Pageクラスの
条件に
参考に した サイト
プログラム
1. BasePage.html
<!DOCTYPE html> <html xmlns:wicket="http://wicket.apache.org" lang="ja"> <head wicket:id="headPanel"></head> <body wicket:id="body"> <header wicket:id="headerPanel"></header> <wicket:child/> <footer wicket:id="footerPanel"></footer> </body> </html>
2. BasePage.java
public abstract class BasePage extends WebPage { private static final long serialVersionUID = -8517634810326079326L; public BasePage() { super(); } public BasePage(final PageParameters parameters) { super(parameters); } @Override protected void onInitialize() { super.onInitialize(); // Add Panel add(new HeadPanel("headPanel")); // Add BodyContainer TransparentWebMarkupContainer bodyContainer = new TransparentWebMarkupContainer("body"); BodyCssClass css = getBodyCssClass(); bodyContainer.add(AttributeModifier.replace("class", css.getCssClass())); add(bodyContainer); add(new HeadPanel("headerPanel")); add(new FooterPanel("footerPanel")); // initPage() initPage(getPageParameters()); } protected BodyCssClass getBodyCssClass() { return BodyCssClass.NORMAL; } }
2.1 プログラムの 補足説明
wicket:id=”body”に
設定する Containerと して、
TransparentWebMarkupContainerをを使用しています。 protected メソッド getBodyCssClass() で
Css定義を 表すenumクラスを 取得。
cssの変更が 必要な 場合は、 継承クラス側で、 オーバーライドします。 bodyContainer.add(AttributeModifier.replace(“class”, css.getCssClass()));
でbodyタグの cssを enumクラスの css定義で 上書きします。
2.2 TransparentWebMarkupContainerに ついて
Wicket - Add body tag attribute に
bodyContainer.setTransparentResolver(true);
MarkupContainer.isTransparentResolver() removed
We removed MarkupContainer.isTransparentResolver() in favor of the more general IComponentResolver. To mitigate the transition, we >provide a TransparentWebMarkupContainer. But please note it does not solve all use cases isTransparentResolver() did.
There are several solutions for you. Your component may implement IComponentResolver itself and resolve the child component. The TransparentWebMarkupContainer implementation may serve as an example.
The main reason why we removed MarkupContainer.isTransparentResolver() has been the magic necessary in Wicket’s core and the number of issues/questions, where we identified isTransparentResolver() as the root cause. It all boils down to that with isTransparentResolver() the markup and component hierarchies get out of sync.
Noteable difference: different than MarkupContainer.isTransparentResolver() where the component id wasn’t needed in the path (transparent), with IComponentResolver it must be included. Imagine you used to have a transparent container such as , where you were able to access a label from the Page just by “myLabel”. In 1.5. you must use “myBody:myLabel”.
- 上記の
日本語訳(適当)
MarkupContainer.isTransparentResolver() は削除されました。
私たちは、より 汎用的な IComponentResolverを 選び、 MarkupContainer.isTransparentResolver()を 削除しました。 移行負荷の 軽減の ため、 私たちは、 TransparentWebMarkupContainerを 提供します。
しかし、TransparentWebMarkupContainerが、 isTransparentResolver()の 全ての ユースケースを カバーするわけではないことに 注意してください。
ユースケースに応じたIComponentResolverを 実装する ことが、 解決策と なります。 TransparentWebMarkupContainerは その 一例です。
私たちがMarkupContainer.isTransparentResolverを 削除した 主な 理由は、 isTransparentResolver()を 根本的な 原因と する、 かなりの 数の 課題が 存在した ためです。
isTransparentResolver()を使用すると、 マークアップと コンポーネントの 階層が 同期し、 値を 取得する ため、 パフォーマンスに 悪影響を 与えます。
重要な違い:
MarkupContainer.isTransparentResolver()はcomponent idに 対する 明確な pathを 必要と しませんが、 IComponentResolverは component idに 対する 明確な pathを 必要と します。のようなtagが あるとすると、
Pageクラスから、“myBody”の 子コンポーネントには、 “myLabel”で アクセスできましたが、 1.5からは、 “myBody:myLabel”で アクセスしなければいけません。
と記載が
ちなみに
ERROR [2015-11-29 10:51:14,506] org.apache.wicket.MarkupContainer: Unable to find component with id 'headerPanel' in [WebMarkupContainer [Component id = body]] Expected: 'body:headerPanel'. Found with similar names: 'headPanel', headerPanel'
※bodyタグの
上記エラーも
TransparentWebMarkupContainerを
ちなみに、
コメント