以 Wicket 形式显示搜索结果数量
在我当前的 Apache Wicket 项目中,我有一个用于查询数据库并在 ListView
中显示查询结果的搜索表单。搜索输入框与带有结果的 ListView
位于同一页面,并且在调用 onSubmit() 方法期间,ListView
填充了来自 DAO 的查询结果的形式。
一切正常,但我需要显示搜索结果的数量。我尝试创建一个 Label,其中填充了通过 ListView
实例的 getList()
方法获取的列表的 size() 方法的值,但没有成功。
感谢您提前提供的任何帮助。
In my current Apache Wicket project I have a search form for querying the database and displaying the query results in a ListView
. The search input box is on the same page as the ListView
with the results, and that ListView
is filled with query results from a DAO, during invocation of the onSubmit() method of the form.
Everything works fine, but I need to display the number of search results. I tried to create a Label that is filled with the value of the size() method of the list got by the getList()
method of the ListView
instance, but no luck.
Thank you for any help in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据您构建此表单的方式,您可能只需要执行
label.setModelObject(listResults.size())
操作。如果不看看你是如何做的,就很难判断。根据您在问题中所说的内容,您可能正在创建这样的标签
new Label(labelId, listView.getList().size()
。这是行不通的,您在构造时使用常量值设置标签的模型,这就是构造时列表的大小,您需要在Model
的getObject()
中获取该值。使值“动态”,例如,for。例如,这样,每次页面呈现时,都会调用
sizeModel().getObejct()
来检索Label
的值。 code>Label 有一个带有常量值的Model
,您甚至可以在
onSubmit 中执行
方法label.setModelObject(list.size())
。 ()。不知道如何构建此表单,我将向您展示如何使用
LoadableDetachableModel
检索结果的List
。ListView
的代码>模型。然后,Label
可以有一个AbstractReadOnlyModel
,它使用ListView
的 modelObject 来获取其大小。使用
LoadableDetachableModel
对于ListView
来说,它的优点是自动分离Model
,从而避免整个List
结果被序列化到会话
。Depending on how you have built this form, you might only need to do
label.setModelObject(listResults.size())
. It's difficult to tell without seeing how are you doing it.By what you're telling in your question, probably you're creating your Label like this
new Label(labelId, listView.getList().size()
. This won't work, you're setting the Label's Model at construction time with a constant value, that's the size of the list at construction time. You need to get that value inside aModel
'sgetObject()
to make the value "dynamic". Like, for instance,With this, every time the page renders,
sizeModel().getObejct()
will be called to retrieve the value for theLabel
. In that other way, theLabel
has got aModel
with a constant value.You could even do
label.setModelObject(list.size())
in theonSubmit()
method.From my ignorance on how you have built this form, I'll show you how would I do this. The
List
of results would be retrieved with aLoadableDetachableModel
. That would be theModel
of theListView
. Then, theLabel
can have for instance anAbstractReadOnlyModel
that uses theListView
s modelObject to get its size.Using a
LoadableDetachableModel
for theListView
has the advantage of automatically detaching theModel
, and therefore avoiding the wholeList
of results to get serialized into theSession
.