pager taglib 没有按照记录重命名导出的 url 变量

发布于 2024-12-06 13:45:41 字数 1814 浏览 1 评论 0原文

我正在使用这个 pager taglib 解决方案,它生成指向几乎按照指示翻页。它提供了一种自定义用于迭代数据集的变量名称的方法,而这正是导致问题的原因。

这就是我到目前为止的设置方式

<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>&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>

注意,基于 文档您可以控制导出变量的名称

导出表达式export="versatz=offset"会导致 pageOffset 变量可用作 <%=Versatz %>

正如您所看到的,我正在尝试将 offset 重命名为 from (这是后端所期望的),

export="from=offset,currentPageNumber=pageNumber"

但是所有生成的链接都采用以下形式( >注意 pager.offset=[number]

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

那是什么,我做错了? 有人尝试过这个标签库吗?

非常感谢任何反馈

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}"> << first</a> </pg:first>
<pg:prev><a href="${pageUrl}"> < prev</a> </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>
 </pg:pages>
<pg:next><a href="${pageUrl}">next ></a> </pg:next>
<pg:last unless="current"><a href="${pageUrl}">last >></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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

若有似无的小暗淡 2024-12-13 13:45:41

我意识到这有点晚了,但我使用上面提到的寻呼机标签库来支持单个页面上的多个唯一寻呼机时遇到了同样的问题。希望有人发现这很有用...

似乎这个参数名称已融入寻呼机标签源代码中:

static final String OFFSET_PARAM = ".offset";

但是,有一个 id 标签属性,其值以 OFFSET_PARAM 标签渲染期间上面的常量。它的默认值为 pager

static final String DEFAULT_ID = "pager";

这两个值连接起来形成一个 idOffsetParam 字段,该字段是 pager 标记内部使用的最终参数名称:

private String idOffsetParam = DEFAULT_ID+OFFSET_PARAM;

解决方案:如果您在标记声明中指定自己的 id 值,您将可以部分控制呈现的参数名称:

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

这将使导航链接呈现为 ?stackoverflow.offset=10< /代码>。参数的 .offset 部分将保留,但至少您对参数名称的唯一性有一定的灵活性。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文