Wicket 1.4中使用DataView作为动态搜索结果表
我对 Wicket 还很陌生,但我已经遇到了一个非常奇怪的问题。
我正在创建一个页面,其中包含一个非常基本的搜索表单和一个最初为空的结果表(DataView)。当用户在字段中输入数据并单击“搜索”时,应用程序会调用一些后端服务,然后将这些服务用于填充数据视图。
然而,用户必须单击“搜索”两次才能显示数据。
我终于找到了这个问题,这是因为 Wicket 使用零来表示第一次“搜索”点击时显示的项目数。第二次单击时,行已添加,Wicket 已计算出要显示的正确行数,因此它决定显示数据。
在 AbstractPageableView.getItemModels() 中,要显示的结果的大小最初为零,因为我可能没有加载带有任何初始数据的表。
我通过在页面加载时加载带有空行的 DataView 解决了这个问题。这似乎欺骗 DataView 使用显示第一次“搜索”点击的数据。
我的问题是:我这样做对吗?还有其他中继器更适合这项任务吗?这是一个错误还是什么?
I'm fairly new to Wicket but I've already run into a very strange problem.
I'm creating a page with a pretty basic search form and a results table (a DataView) which is initially empty. When the user enters data into the fields and clicks "Search", the app calls some backend services which are then used to populate the DataView.
However the user has to click "Search" twice for the data to be displayed.
I finally tracked this down, and it's because Wicket is using zero for the number of items to be displayed for the first "Search" click. At the second click, the rows have already been added and Wicket has already calculated the proper number of rows to display, so it decides it will show the data.
In AbstractPageableView.getItemModels(), the size of the results to display is initially zero, because I don't load the table with any initial data probably.
I got around this problem by loading the DataView with empty rows on page load. This seems to trick the DataView into using the displaying the data for the first "Search" click.
My question is: am I doing this right? Is there another repeater that is better for this task? Is this a bug or something?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
终于破解了:这是因为我只在 iterator() 方法中加载数据提供程序中的数据,而数据提供程序的 size() 方法通常在 iterator() 方法之前调用。我应该在它自己的方法中加载数据并从 iterator() 和 size() 调用该方法。这样做解决了它。
之前的数据提供者(Splc 是 DTO):
之后的数据提供者:
Finally cracked it: it was because I was loading the data in my data provider only in the iterator() method, and the data provider's size() method is usually called before the iterator() method is. I should have been loading the data in its own method and calling that method from iterator() and size(). Doing that fixed it.
Data Provider before (Splc is the DTO):
Data Provider after: