使用 Wicket 的 Ajax 请求,但有多个可能的模型值

发布于 2024-08-26 22:06:50 字数 161 浏览 8 评论 0原文

我是 wicket 新手,并遇到以下问题:

我有一张 5 行的桌子。每行包含 7 个单元格。每个细胞都有独特的价值。单击某个单元格后,应将其唯一值发布到服务器。

我想在表格上只注册一个 ajaxfallbacklink (或类似的),并将模型的值调整为已单击的单元格的唯一值。

I'm new to wicket and stuck with the following problem:

I have a table with 5 rows. Each row contains 7 cells. Each cell has a unique value. Once a cell is clicked, its unqiue value should be posted to the server.

I would like to register only one ajaxfallbacklink (or similar) on the table and adjust the value of the model to the unique value of cell that has been clicked.

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

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

发布评论

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

评论(3

似梦非梦 2024-09-02 22:06:50

我的立即反应是“为什么你想要这样” - 明显的解决方案是向每个单元格/单元格内容组件添加 ajax onClick 行为(显然你只需要编写一个行为)。这就是它的设计原理。

您可以按照您的建议编写一个处理程序,但它必须遍历表的组件树,向每个单元格添加正确的 JS onClick 回调。然后,您必须考虑向实际上不表达 onClick 事件的组件添加 onClick 行为的语义。

基本上是一堆自定义代码,绕过框架(非常简洁)ajax 模型,没有任何好处。

My immediate response would be "why do you want to it like that" - the obvious solution is to add an ajax onClick behaviour to each cell/cell content component (obviously you only have to write one behaviour). That's how it is designed to work.

You could write a handler as you suggest, but it would have to trawl through the table's component tree, adding the correct JS onClick callbacks to each cell. You then have to think about the semantics of adding an onClick behaviour to a component that doesn't actually express the onClick event.

Basically a load of custom code, circumventing the frameworks (pretty neat) ajax model for no benefit at all.

浪漫人生路 2024-09-02 22:06:50

一般来说,当您只有一个处理程序时,您如何知道哪个单元格已被单击?听起来几乎不可能。

但 Wicket 方面的问题很简单,您始终可以编写自己的 IModel,或扩展 AbstractReadOnlyModel。您只需要实现一种方法:getObject()。

How can you know, in general, which cell has been clicked when you only have one handler for all? Sounds pretty much impossible.

But the Wicket side of the problem is easy, you can always write your own IModel, or extend AbstractReadOnlyModel. You only need to implement one method, getObject().

青衫负雪 2024-09-02 22:06:50

显然这需要客户端 JavaScript 提取信息发送到服务器。
当该信息准备好后,以下代码可以生成 ajax 回调(来自 AbstractDefaultAjaxBehavior 子类)

generateCallbackScript(new AppendingStringBuffer("wicketAjaxPost(\'").append(getCallbackUrl(false)).append("\', 'param=' + Wicket.Form.encode(yourDataGoesHere) "));

和 RequestCycle.get().getRequest().getParameter("param") 来获取 java 端的解码值。

Obviously this will need client side javascript extract the information to send to the server.
when that information is ready the following code can generate a ajax callback (from an AbstractDefaultAjaxBehavior subclass)

generateCallbackScript(new AppendingStringBuffer("wicketAjaxPost(\'").append(getCallbackUrl(false)).append("\', 'param=' + Wicket.Form.encode(yourDataGoesHere) "));

and RequestCycle.get().getRequest().getParameter("param") to get the decoded value on the java side of things.

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