开发者

pager taglib not renaming exported url variables as documented

I'm using this pager taglib solution, it generates the links to the pages almost as instructed. It offers a way to customize the variable names that are used to iterate over the data set, and that's precisely what is causing problems.

This is how I've got set up so far

<pg:pager url="/search" 
items="1000" 
maxPageItems="10"
export="from=offset,currentPageNumber=pageNumber"
scope="request">
<pg:param name="w" value="${w}"/>
<pg:param name="e" value="${e}"/>

<pg:first unless="current"><a href="${pageUrl}"> &lt;&lt; first</a>&nbsp;</pg:first>
<pg:prev><a href="${pageUrl}"> &lt; prev</a开发者_StackOverflow中文版>&nbsp;</pg:prev>    
<pg:pages>
    <c:choose>
        <c:when test="${pageNumber == currentPageNumber}">
            ${pageNumber}
        </c:when>
        <c:otherwise>
            <a href="${pageUrl}">${pageNumber}</a>
        </c:otherwise>
    </c:choose>
&nbsp;</pg:pages>
<pg:next><a href="${pageUrl}">next &gt;</a>&nbsp;</pg:next>
<pg:last unless="current"><a href="${pageUrl}">last &gt;&gt;</a></pg:last>
</pg:pager>

Note, that based on the documentation you can control the name of the exported variables

The export expression export="versatz=offset" would cause the pageOffset variable to be available as <%= versatz %>

As you can see I'm trying to rename too the offset to from (This is what the backend is expecting)

export="from=offset,currentPageNumber=pageNumber"

But all the generated links are in the form (Note the pager.offset=[number])

http://localhost:8080/search?w=param1&e=param2&pager.offset=10

What's that, that I'm doing wrong? Anybody has experimented with this taglib?

Any feedback is deeply appreciated


I realize this is a bit late, but I encountered this same issue using the pager taglib mentioned above to support multiple unique pagers on a single page. Hope someone finds this useful...

It seems this parameter name is baked into the pager tag source code:

static final String OFFSET_PARAM = ".offset";

However, there is an id tag attribute whose value gets prefixed to the OFFSET_PARAM constant above during tag rendering. Its default value is pager:

static final String DEFAULT_ID = "pager";

These two values get concatenated to form an idOffsetParam field which is the final parameter name used internally by the pager tag:

private String idOffsetParam = DEFAULT_ID+OFFSET_PARAM;

Solution: If you specify your own id value in the tag declaration, you'll have partial control over the rendered parameter name:

<pg:pager 
    id="stackoverflow" 
    url="/search" 
    items="1000"
    ...
    ..
    .

This will make navigational links render as ?stackoverflow.offset=10. The .offset portion of the param will remain, but at least you'll have some flexibility as to the uniqueness of the parameter name.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜