tapestry jquery PageScroll

时间:2016-03-15 00:34:25

标签: jquery infinite-scroll tapestry

我正在尝试使用tapestry5 jquery组件PageScroll进行无限滚动。

  • tapestry5 - 5.3.8
  • tapestry5-jquery - 3.4.2

到目前为止我得到了这个:

public class PageScrollDemo {
    private static final int PageSize = 100;

    @Property
    private int value;

    @OnEvent("nextPage")
    List<Integer> moreValues(int pageNumber) throws InterruptedException {
        List<Integer> values = new ArrayList<Integer>();
        int first = pageNumber * PageSize;
        for(int i = 0; i < PageSize; ++i){
            values.add(first + i);
        }

        Thread.sleep(1000);
        return values;
    }
}

PageScrollDemo.tml

<html xmlns:t='http://tapestry.apache.org/schema/tapestry_5_3.xsd'>
<body>
<h1>BEGIN</h1>
<ul>
    <li t:type='jquery/pagescroll' row='value' scroller='scroller' zone='zone' pageNumber="1">

        <li>${value}</li>
    </li>
    <li class='zone' t:type='zone' t:id='zone'/>
</ul>
<div id='scroller'></div>
<h1>END</h1>
</body>
</html>

但是我得到了这个错误

java.lang.RuntimeException
Coercion of [] to type java.lang.Integer (via String --> Long, Long --> Integer) failed: For input string: "[]"
java.lang.NumberFormatException
For input string: "[]"

Filter stack frames Stack trace

        java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
        java.lang.Long.parseLong(Long.java:589)
        java.lang.Long.<init>(Long.java:965) 

据我所知,tapestry正在尝试将参数“[]”传递给方法moreValues(int),该方法失败。

我的问题是为什么不传递String“1”(pageNumber),它可以被转换为int?

我的第二个问题是为什么PageScrollDemo.tml中的pageNumber是必需的?如果我从moreValues()中删除params,我得到这个:

trace

        Triggering event 'scroll' on PageScrollDemo:pagescroll

org.apache.tapestry5.runtime.ComponentEventException
Failure writing parameter 'pageNumber' of component PageScrollDemo:pagescroll: Literal values are not updateable.

有人可以解释一下如何使用Pagescroll吗?

1 个答案:

答案 0 :(得分:1)

https://tawus.wordpress.com/2012/11/25/scrolling-pages-tapestry5-onscrollbeyond/

提供了该组件作者的一些文档

如果您查看源文档,https://github.com/got5/tapestry5-jquery/blob/master/src/main/java/org/got5/tapestry5/jquery/components/PageScroll.java,您会找到以下代码

@Parameter(value = "literal:[]")
private Object[] context;

我想你可以从中获取代码 https://github.com/got5/tapestry5-jquery/blob/master/src/test/resources/org/got5/tapestry5/jquery/pages/PageScroll.tml

您的错误消息

java.lang.RuntimeExceptionCoercion of [] to type java.lang.Integer
(via String --> Long, Long --> Integer) failed: For input string: "[]"
java.lang.NumberFormatExceptionFor input string: "[]"

来自您从模板中删除的参数上下文的默认值。