如何修改 PagingNavigator 中 Wicket 链接生成的标记?
我正在使用自定义的 PagingNavigator 组件,并且正在寻找一种方法来更改为第一个、上一个和当前页面分页项生成的标记。
这是我的 PaginingNavigator:
<wicket:panel>
<ul class="pagination">
<li class="first">
<a wicket:id="first"><<</a>
</li>
<li class="prev">
<a wicket:id="prev"><</a>
</li>
<li wicket:id="navigation" class="page">
<a wicket:id="pageLink" href="#">
<span wicket:id="pageNumber">5</span>
</a>
</li>
<li class="dots">...</li>
<li wicket:id="lastPage" class="jump"></li>
<li class="next">
<a wicket:id="next">></a>
</li>
<li class="last">
<a wicket:id="last">>></a>
</li>
</ul>
在非活动项(最初是前一页、第一页和当前页)的 LI 中生成的标记是这样的:
<span title="Item Title" id="RandomID">
<em>
<span>ItemText</span>
</em>
</span>
这使得以不同方式设置非活动分页项和当前页的内容样式变得非常困难。我希望它为非活动项目输出类似这样的内容:
<a href="#" title=ItemTitle" id="RandomID" class="inactive">ItemText</a>
对于当前页面:
<a href="#" title=ItemTitle" id="RandomID" class="currentPage">ItemText</a>
我还注意到,当您开始分页结果时,它会将 SPAN 标记插入到 A 标记中,因为这些没有特定的类在它们身上,正确地设计样式变得非常乏味。
我一直在研究我们的代码库,但找不到我们指定这一点的任何地方,但由于我是一名前端人员,所以我很容易忽视这一点。据我所知,它们似乎是标准的 PagingNavigationLinks。
有什么想法吗?
I'm using a customized PagingNavigator component, and I'm looking for a way to change markup generated for the first, previous, and current page paging items.
Here's my PaginingNavigator:
<wicket:panel>
<ul class="pagination">
<li class="first">
<a wicket:id="first"><<</a>
</li>
<li class="prev">
<a wicket:id="prev"><</a>
</li>
<li wicket:id="navigation" class="page">
<a wicket:id="pageLink" href="#">
<span wicket:id="pageNumber">5</span>
</a>
</li>
<li class="dots">...</li>
<li wicket:id="lastPage" class="jump"></li>
<li class="next">
<a wicket:id="next">></a>
</li>
<li class="last">
<a wicket:id="last">>></a>
</li>
</ul>
The markup generated within the LIs of inactive items (initially, the previous, first, and current page) is this:
<span title="Item Title" id="RandomID">
<em>
<span>ItemText</span>
</em>
</span>
This makes it pretty difficult to style the content of inactive paging items and the current page differently. I'd prefer it to output something like this for the inactive items:
<a href="#" title=ItemTitle" id="RandomID" class="inactive">ItemText</a>
and this for the current page:
<a href="#" title=ItemTitle" id="RandomID" class="currentPage">ItemText</a>
I also noticed that it inserts SPAN tags into the A tags when you start paging through results, and since these don't have particular classes on them, it gets pretty tedious to style correctly.
I've been digging around in our codebase and can't find anywhere that we'd be specifying this, but since I'm a front-end guy, it'd be pretty easy for me to overlook. They seem to be standard PagingNavigationLinks, as far as I can tell.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您查看此处:
Apache Wicket - 搜索引擎优化
在“使分页无状态”下,您可以了解如何覆盖分页导航的各个部分。
If you look here:
Apache Wicket - Search Engine Optimization
under "Making Paging Stateless", you can get an idea of how to override the various parts of paging navigation.
您可以扩展核心
PagingNavigator
:然后创建一个
MyPagingNavigator.html
,您可以在其中进行更改。但请确保您没有从 MyPagingNavigator.html 中删除任何组件您可以使用 wicket 源中的原始内容 (src/wicket/src/main/java/org/apache/wicket/markup/html/navigation/paging/ PagingNavigator.html):
You can extend the core
PagingNavigator
:Then you create a
MyPagingNavigator.html
where you can make your changes. But be sure that you don't remove any components from MyPagingNavigator.htmlYou can use the original content from the wicket source (src/wicket/src/main/java/org/apache/wicket/markup/html/navigation/paging/PagingNavigator.html):
为了解决这个问题,我不得不扩展一些类。特别是,我需要重写的行为
org.apache.wicket.markup.html.link.AbstractLink.disableLink(final ComponentTag tag)
就是在AbstractLink的disableLink函数中,将“a”标签改为“span”,并且去掉了href和onclick属性。我首先回溯到 PagingNavigator 并将其扩展如下:
对于我的“梦想”主题,这允许我覆盖 newPagingNavigationLink、newPagingNavigationIncrementLink 等。然后,我对 PagingNavigationLink(等)的实现修改了禁用行为,如下所示
:将“a”标签更改为“span”,我只是删除了 href 和 onclick 属性。
现在我得到了一个没有 href 的锚标记。
To solve this I had to extend a handful of classes. In particular, I needed to override the behavior of
org.apache.wicket.markup.html.link.AbstractLink.disableLink(final ComponentTag tag)
It's in the disableLink function of AbstractLink that the "a" tag is changed to "span" and the href and onclick attributes are stripped out. I first backtracked to PagingNavigator and extended this as follows:
For my "Dream" theme, this allowed me to override the newPagingNavigationLink, newPagingNavigationIncrementLink, etc. My implementation for PagingNavigationLink (et. al) then modified the disable behavior, like this:
Rather than change the "a" tag to a "span", I just strip out the href and onclick attributes.
Now I get an anchor tag rendered without an href.