Wicket の Pagination を表示する PagingNavigation
public PagingNavigation(final String id, final IPageable pageable)
通常は、
Dataview dataview = /* org.apache.wicket.markup.repeater.data.DataView の生成 */ add(new PagingNavigator("paging", dataview));
と書くと、
の表示であるが、先頭(first)と末尾(last)を表示させないようにするには、トリッキーなことをする。
このようにするには、PagingNavigator の onInitialize をオーバーライドして、
先頭(first)と末尾(last)を、onRender() で何もしない処理で付け直してしまうのである。
PagingNavigator pagingNavigator = new PagingNavigator("paging", dataview){ @Override protected void onInitialize(){ super.onInitialize(); remove("first"); add(new WebMarkupContainer("first"){ @Override protected void onRender(){ } }); remove("last"); add(new WebMarkupContainer("last"){ @Override protected void onRender(){ } }); } }; add(pagingNavigator);
これは、Wicket の PagingNavigator .html が、以下のHTMLだからだ。
<?xml version="1.0" encoding="UTF-8" ?> <!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <html xmlns:wicket="http://wicket.apache.org"> <body> <wicket:panel> <a wicket:id="first" class="first"><<</a> <a wicket:id="prev" rel="prev" class="prev"><</a> <span wicket:id="navigation" class="goto"> <a wicket:id="pageLink" href="#"><span wicket:id="pageNumber">5</span></a> </span> <a wicket:id="next" rel="next" class="next">></a> <a wicket:id="last" class="last">>></a> </wicket:panel> </body> </html>
しかし、これを Bootstrap の PagingNavigation として描画したい場合は、
https://getbootstrap.com/docs/4.1/components/pagination/
span で囲んだ a タグの繰り返しではなく、
li で囲んだ a タグの繰り返しで描画しなくてはならないとなると、
結局、Wicket の PagingNavigator を、Bootstrap 用のHTMLを用意して
リメイク(別名クラスで再コーディング)した PagingNavigator を作らなきゃならないのか!?
それとも、Wicket の PagingNavigatorで描画させた後で、spanタグを li タグで置換するか?
span → li 置換を JavaScript で実行するなんて JSを書くのが嫌なだけでなく、
危険かもしれないし。。。