headタグの
<wicket:header-items ></wicket:header-items>
と
以下、
ユーザーガイドの 抜粋
15.9 Header contributors positioning
Starting from version 6.15.0 we can specify where header contributors must be rendered inside tag using the placeholder tag
<wicket:header-items ></wicket:header-items>
:
<head> <meta charset="UTF-8"/> <wicket:header-items/> <script src="my-monkey-patch-of-wicket-ajax.js"></script> </head>
With the code above all header contributions done by using IHeaderResponse in your Java code or the special
<wicket:head >
tag will be put between the<meta >
and `This way you can make sure that some header item is always before or after the header items managed by Wicket.
<wicket:header-items ></wicket:header-items>
can be used only in the page’s<head >
element and there could be at most one instance of it.
ユーザーガイドの抜粋(訳)
15.9 ヘッダー記述の
挿入位置を 決める バージョン6.15.0から、
<head >
のタグの 中に レンダリングしなければならない 場合の、 リプレイスホルダーと して、 <wicket:header-items ></wicket:header-items>
が使用できるようになりました。
<head>
<meta charset="UTF-8"/>
<wicket:header-items/>
<script src="my-monkey-patch-of-wicket-ajax.js"></script>
</head>
javaコード内で、
IHeaderResponseで 追加した ヘッダー要素、 <wicket:head >
内に記述した ヘッダー要素のが 全て、
<meta >
タグ、`
<wicket:header-items ></wicket:header-items>
は<head >
タグ内に1つだけ 定義できます。
metaタグ、scriptタグがなくても、以下の記述で動作する。
Documentには
以下、
<head>
<wicket:header-items/>
</head>
Panelクラスに記述したら、エラーになった。
初めは
以下の
<wicket:head >
タグが
<wicket:head >
タグを
org.apache.wicket.markup.MarkupException: Failed to handle: <wicket:header-items>. It might be that no resolver has been registered to handle this special tag. But it also could be that you declared wicket:id=wicket_header-items4 in your markup, but that you either did not add the component to your page at all, or that the hierarchy does not match. Container: [HeaderTagPanel [Component id = headerTagPanel]]
! at org.apache.wicket.markup.MarkupStream.throwMarkupException(MarkupStream.java:526) ~[xxx-0.0.1.jar:0.0.1]
! at org.apache.wicket.MarkupContainer.throwException(MarkupContainer.java:1591) ~[xxx-0.0.1.jar:0.0.1]
! at org.apache.wicket.MarkupContainer.renderNext(MarkupContainer.java:1537) ~[xxx-0.0.1.jar:0.0.1]
! at org.apache.wicket.MarkupContainer.renderAll(MarkupContainer.java:1759) ~[xxx-0.0.1.jar:0.0.1]
! at org.apache.wicket.MarkupContainer.renderComponentTagBody(MarkupContainer.java:1734) ~[xxx-0.0.1.jar:0.0.1]
! at org.apache.wicket.MarkupContainer.renderAssociatedMarkup(MarkupContainer.java:797) ~[xxx-0.0.1.jar:0.0.1]
! at org.apache.wicket.markup.html.panel.AssociatedMarkupSourcingStrategy.renderAssociatedMarkup(AssociatedMarkupSourcingStrategy.java:77) ~[xxx-0.0.1.jar:0.0.1]
実際に書いたコードの抜粋
- HTML
<head>
<meta charset="utf-8">
<title wicket:id="headerTitle">Example Page</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<wicket:header-items/>
</head>
- Page#renderHead(IHeaderResponse response)
@Override
public void renderHead(IHeaderResponse response) {
super.renderHead(response);
// Meta Descreption
response.render(MetaDataHeaderItem.forMetaTag("description", getString("content")));
// Meta AUTHOR
response.render(MetaDataHeaderItem.forMetaTag("author", getString("author")));
// Meta Favicon
response.render(MetaDataHeaderItem.forLinkTag("shortcut icon", "/static/images/favicon.ico"));
// Web Fonts
response.render(CssHeaderItem.forUrl("http://fonts.googleapis.com/css?family=Open+Sans:400italic,700italic,400,700,300&subset=latin,latin-ext"));
response.render(CssHeaderItem.forUrl("http://fonts.googleapis.com/css?family=Raleway:700,400,300"));
// Jquery
response.render(JavaScriptHeaderItem.forUrl("/static/plugins/jquery.min.js"));
response.render(JavaScriptHeaderItem.forUrl("/static/plugins/jquery.tile.min.js"));
}
@Override
protected void onInitialize() {
super.onInitialize();
// add headerTitle
add(new Label("headerTitle", getRBString("siteTitle")));
}
- 補足
<header >
内の<title >
タグを生成するできる クラスが、
StringHeaderItem
しかなさそうです。
title を動的に 変更したかったため、
Label 化して、別途設定するようにしました。
以上です。
コメント