2011-02-14 65 views
2

我正在使用自定义的PagingNavigator组件,并且正在寻找一种方法来更改为第一个,上一个和当前页面分页项目生成的标记。如何修改PagingNavigator中Wicket链接生成的标记?

这里是我的PaginingNavigator:

<wicket:panel> 
<ul class="pagination"> 
    <li class="first"> 
     <a wicket:id="first">&lt;&lt;</a> 
    </li> 
    <li class="prev"> 
     <a wicket:id="prev">&#060;</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">&#062;</a> 
    </li> 
    <li class="last"> 
     <a wicket:id="last">&gt;&gt;</a>  
    </li> 
</ul> 

不活动的项目(最初,​​以前,第一,和当前页面)的LIS内生成的标记是这样的:

<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标记成一个标签,当你通过结果开始分页,并且由于它们没有特定的类,因此正确设置风格非常繁琐。

我一直在挖掘我们的代码库,无法找到任何我们将要指定的地方,但由于我是前端人员,因此我很容易忽视。就我所知,它们似乎是标准的PagingNavigationLinks。

任何想法?

回答

3

如果你看看这里:

Apache Wicket - Search Engine Optimization

下“使寻呼无状态”,你可以得到如何重写分页导航的各个部分的想法。

+2

该链接无效。以下是最新的链接:https://cwiki.apache.org/confluence/display/WICKET/SEO+-+Search+Engine+Optimization#SEO-SearchEngineOptimization-MakingPagingStateless – 2013-06-24 21:17:55

2

可以扩展核心PagingNavigator

import org.apache.wicket.markup.html.navigation.paging.IPageable; 
import org.apache.wicket.markup.html.navigation.paging.IPagingLabelProvider; 
import org.apache.wicket.markup.html.navigation.paging.PagingNavigator; 

class MyPagingNavigator extends PagingNavigator { 

    public MyPagingNavigator(String id, IPageable pageable) { 
     super(id, pageable); 
    } 

    public MyPagingNavigator(String id, IPageable pageable, IPagingLabelProvider labelProvider) { 
     super(id, pageable, labelProvider); 
    } 



} 

然后创建一个MyPagingNavigator.html在那里你可以进行更改。但请确保您不会从MyPagingNavigator.html中删除任何组件

您可以使用来自检票源(src/wicket/src/main/java/org/apache/wicket/markup/html /导航/分页/ PagingNavigator.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> 
<body> 
    <wicket:panel> 
    <a wicket:id="first">&lt;&lt;</a>&nbsp;<a wicket:id="prev">&lt;</a> 
    <span wicket:id="navigation"> 
      <a wicket:id="pageLink" href="#"><span wicket:id="pageNumber">5</span></a> 
    </span> 
    <a wicket:id="next">&gt;</a>&nbsp;<a wicket:id="last">&gt;&gt;</a> 
    </wicket:panel> 
</body> 
</html> 
0

为了解决这个问题,我不得不延长类屈指可数。特别是,我需要覆盖org.apache.wicket.markup.html.link.AbstractLink.disableLink(最终ComponentTag标签) 的行为

在AbstractLink的disableLink函数中,“a”标签已更改到“跨度”,href和onclick属性被剥离出来。我第一次退步到PagingNavigator和扩展这个如下:

public class DreamPagingNavigator extends PagingNavigator { 

    public DreamPagingNavigator(String id, IPageable pageable) { 
     super(id, pageable); 
    } 

    public DreamPagingNavigator(String id, IPageable pageable, IPagingLabelProvider labelProvider) { 
     super(id, pageable, labelProvider); 
    } 

    @Override 
    protected PagingNavigation newNavigation(final String id, final IPageable pageable, 
      final IPagingLabelProvider labelProvider) { 
     return new DreamPagingNavigation(id, pageable, labelProvider); 
    } 

    @Override 
    protected AbstractLink newPagingNavigationIncrementLink(String id, IPageable pageable, 
      int increment) { 
     return new DreamPagingNavigationIncrementLink<Void>(id, pageable, increment); 
    } 

    @Override 
    protected AbstractLink newPagingNavigationLink(String id, IPageable pageable, int pageNumber) { 
     return new DreamPagingNavigationLink<Void>(id, pageable, pageNumber); 
    } 

} 

对于我的“梦想”的主题,这让我重写newPagingNavigationLink,newPagingNavigationIncrementLink,等我实施PagingNavigationLink(ET。人)中,然后修改为禁止行为,这样的:

public class DreamPagingNavigationLink<T> extends PagingNavigationLink<T> { 

    public DreamPagingNavigationLink(String id, IPageable pageable, long pageNumber) { 
     super(id, pageable, pageNumber); 
    } 

    @Override 
    protected void disableLink(final ComponentTag tag) 
    { 
     // if the tag is an anchor proper 
     if (tag.getName().equalsIgnoreCase("a") || tag.getName().equalsIgnoreCase("link") || 
      tag.getName().equalsIgnoreCase("area")) 
     { 
      // Remove any href from the old link 
      tag.remove("href"); 
      tag.remove("onclick"); 

     } 
     // if the tag is a button or input 
     else if ("button".equalsIgnoreCase(tag.getName()) || 
      "input".equalsIgnoreCase(tag.getName())) 
     { 
      tag.put("disabled", "disabled"); 
     } 
    } 

} 

在“a”的标签,而不是改变为“跨度”,我刚剥离出href和的onclick属性。

现在我得到了一个不带href的呈现锚定标记。