Wicket 和复杂的 Ajax 场景

发布于 2024-11-14 22:06:43 字数 331 浏览 1 评论 0原文

当屏幕有多个交互的 Ajax 控件并且您想要控制组件的可见性以对这些控件做出反应(以便您只显示在任何给定情况下有意义的内容)时,请调用 target.addComponent()手动更新您想要更新的所有内容变得很麻烦并且不太可维护。

最终,onClickonUpdate 回调网络可能会达到这样一个程度:向屏幕添加新组件会比预想的更加困难。

避免这种复杂性增加的常用策略是什么(甚至是库,如果存在这样的东西)?

更新:感谢您的回答,我发现它们都非常有用,但我只能接受一个。对不起。

When a screen has multiple interacting Ajax controls and you want to control the visibility of components to react to these controls (so that you only display what makes sense in any given situation), calling target.addComponent() manually on everything you want to update is getting cumbersome and isn't very maintainable.

Eventually the web of onClick and onUpdate callbacks can reach a point where adding a new component to the screen is getting much harder than it's supposed to be.

What are the commonly used strategies (or even libraries if such a thing exists) to avoid this build-up of complexity?

Update: Thank you for your answers, I found all of them very useful, but I can only accept one. Sorry.

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

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

发布评论

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

评论(5

黎歌 2024-11-21 22:06:43

在 Wicket 1.5 中,有一个事件总线。每个组件都有 onEvent(Object Payload) 方法。使用component.send(),您可以广播事件,每个组件都可以检查有效负载(例如UserJoinedEvent对象)并决定是否要参与当前的Ajax响应。请参阅http://www.wicket-library.com/wicket-examples/events/< /a> 一个简单的演示。

In Wicket 1.5 there is an event bus. Each component has onEvent(Object payload) method. With component.send() you can broadcast events and each component can check the payload (e.g. UserJoinedEvent object) and decide whether it wants to participate in the current Ajax response. See http://www.wicket-library.com/wicket-examples/events/ for a simple demo.

旧情勿念 2024-11-21 22:06:43

您可以添加结构组件,例如 WebMarkupContainer,当您将其添加到 AjaxTarget 时,其中包含的所有内容也会更新。这允许您在一行中更新组件组。

You could add structural components such as WebMarkupContainers, when you add this to the AjaxTarget everything contained in it will also get updated. This allows you to update groups of components in a single line.

初见你 2024-11-21 22:06:43

当我为页面创建组件时,我倾向于将它们添加到组件数组中:

Component[] pageComponents = {
                  new TextField<String>("Field1"),
                  new TextField<String>("Field2"),
                  new TextField<String>("Field3")
}

从 Wicket 1.5 开始,添加函数采用数组参数 [1]。因此,可以将元素添加到页面或目标,如下所示:

add(pageComponents);
target.add(pageComponents);

然后可以根据要一起刷新的组件对组件进行分组。

[1] http://www.jarvana.com/jarvana/view/org/apache/wicket/wicket/1.5-M3/wicket-1.5-M3-javadoc.jar!/org/apache/wicket/ajax /AjaxRequestTarget.html

When I'm creating components for a page I tend to add them to component arrays:

Component[] pageComponents = {
                  new TextField<String>("Field1"),
                  new TextField<String>("Field2"),
                  new TextField<String>("Field3")
}

As of Wicket 1.5 the add functions take array parameters [1]. Therefore elements can be added to the page or target like this:

add(pageComponents);
target.add(pageComponents);

Components can then be grouped based on which you want to refresh together.

[1] http://www.jarvana.com/jarvana/view/org/apache/wicket/wicket/1.5-M3/wicket-1.5-M3-javadoc.jar!/org/apache/wicket/ajax/AjaxRequestTarget.html

寄居人 2024-11-21 22:06:43

好吧,我们这里讨论的是多少个组件?十?二十?数百个?

对于最多二十个或大约这个,您可以有一个状态控制器来控制应显示哪些组件。该控制器设置组件模型的可见字段,并且您始终将所有组件添加到控制器处理的请求中。您只需将组件 ajax 事件重定向到控制器处理方法即可。

对于大量的组件,其有效负载过重而无法获得良好的性能,您可以使用 jQuery 之类的 javascript 库来由客户端进行显示和隐藏。

Well, of how many components do we speak here? Ten? Twenty? Hundreds?

For up to twenty or about this you can have a state controller which controls which components should be shown. This controller sets the visible field of a components model and you do always add all components to your requests which are handled by the controller. The components ajax events you simply redirect to the controller handle method.

For really large numbers of components which have a too heavy payload for a good performance you could use javascript libraries like jQuery to do the show and hide things by the client.

巾帼英雄 2024-11-21 22:06:43

我目前使用某种修改过的观察者模式来模拟 Wicket 1.4 中的事件总线。

我的页面充当可观察的观察者,因为我的组件彼此不认识,并且在多个页面中以不同的组合重用。每当一个组件收到可能影响其他组件的 Ajax 事件时,它就会使用事件对象和 ajax 目标调用其页面上的方法。该页面对所有已为此类事件注册的组件调用类似的方法,并且每个组件可以根据提供的事件对象来决定是否以及如何做出反应并将其自身附加到目标。

可以通过使用检票口访客来存档相同内容。我不知道哪个更好,但我认为这主要是口味问题。

I currently use some sort of modified Observer-Pattern to simulate an event-bus in Wicket 1.4.

My Pages act as an observable observer since my components don't know each other and are reused in different combinations across multiple pages. Whenever one component receives an Ajax-event that could affect other components as well, it calls a method on it's page with an event-object and the ajax-target. The page calls a similar method on all components which have registered themselves for this kind of event and each component can decide, on the base of the supplied event-object if and how it has to react and can attach itself to the target.

The same can be archived by using the wicket visitor. I don't know which one is better, but I think that's mainly a matter of taste.

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