2011-02-14 64 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的呈現錨定標記。