ICEfaces 2 真的有用吗?

发布于 2024-11-10 02:52:16 字数 1715 浏览 0 评论 0原文

根据文档,它应该是世界上最容易使用的产品:

只需将icefaces.jar 添加到应用程序,我们就可以将 Direct-to-Dom (D2D) 渲染应用到页面。

但即使是他们最基本的教程ICEfaces 2 入门 似乎不起作用。我下载了页面底部的代码,将其构建为 WAR 并将其部署到 Tomcat 6.0.32 和 Tomcat 7.0.14。我注意到的第一件事是,由于某种原因,复合组件无法工作:

/job-applicant.xhtml @39,78 以下属性是必需的,但尚未为其提供值:id。

但这感觉更像是一个 JSF 问题(JSF 2 Composite 组件 required 属性抛出异常),所以我通过删除 ID 属性上的 required 来解决这个问题(尽管值上仍然有一个 required="true" ,但似乎没有问题)。无论如何,现在应用程序已部署。如上所述,当您单击“清除”按钮时,它会使用 AJAX 调用,最终获取响应 XML 中表单的完整 DOM。下一步是添加icefaces.jar,它应该添加 Direct-to-DOM 功能,以确保仅在响应中发送差异:

ICEfaces 2 将组件标记呈现到反映当前客户端视图的服务器端 DOM(文档对象模型)。每次 JSF 生命周期运行时都会进行 DOM 比较,如果有任何更改,则会将一组简洁的页面更新发送回客户端以应用到页面。我们称之为 Direct-to-DOM 或 D2D 渲染。

然而,我得到了完整的回复,加上一些额外的 ICEfaces 内容,比如:

<input name="ice.window" type="hidden" value="epgo74zmvc" />
<input name="ice.view" type="hidden" value="vs4ik661" />

很明显,ICEfaces 正在做一些事情,但不是它所承诺的。它实际上比普通的 AJAX 响应更长。因此,我忽略了这实际上是一个更大的响应这一事实,继续进行下一个承诺:

通过 Direct-to-DOM 渲染,我们不再需要嵌套在“清除”按钮中的 f:ajax 标签

听起来很简单,对吧?在该页面的示例中,他们只是将侦听器的 EL 表达式从 f:ajax 标记移动到 h:commandButton 标记。问题在于方法签名不同。这应该是入门教程,但它并不关心实际引导您完成这些步骤。不管怎样,我可以通过修改支持 bean 中的clearForm 方法的方法签名来解决这个问题,以便它的参数是 now 和 ActionEvent 而不是 AjaxBehaviorEvent。这样做,ICEfaces 实际上确实用 AJAX 操作取代了整页操作,这非常令人难以置信,但我仍然有一种酸涩的味道。有谁知道为什么 D2D 似乎不起作用?我做错了什么吗?我还应该尝试使用 ICEfaces 吗?

According to the documentation, it should be the easiest product in the world to use:

Simply add the icefaces.jar to the application and we have Direct-to-Dom (D2D) rendering applied to the page.

But even their most basic tutorial Getting Started with ICEfaces 2 doesn't appear to work. I downloaded the code at the bottom of the page, built it into a WAR and deployed it to both Tomcat 6.0.32 and Tomcat 7.0.14. The first thing I noticed was that for some reason the composite component didn't work:

/job-applicant.xhtml @39,78 The following attribute(s) are required, but no values have been supplied for them: id.

But that feels more like a JSF issue (JSF 2 Composite component required attribute throws exception), so I resolved that by removing the required on the ID attribute (though there is still a required="true" on value that doesn't seem to have a problem). Anyway, now the app deploys. And as stated, it uses an AJAX call when you click the Clear button that ends up getting the full DOM for the form in the response XML. The next step is to add the icefaces.jar and it is supposed to add the Direct-to-DOM functionality that will ensure only the differences are sent in the response:

ICEfaces 2 renders component markup to a server-side DOM (Document Object Model) that reflects the current client view. Each time the JSF lifecycle runs a DOM comparison is done and, if there are any changes, a concise set of page updates are sent back to the client to be applied to the page. We call this Direct-to-DOM or D2D rendering.

However, I get the full form as a response, plus some additional lines of ICEfaces stuff like this:

<input name="ice.window" type="hidden" value="epgo74zmvc" />
<input name="ice.view" type="hidden" value="vs4ik661" />

So clearly, ICEfaces is doing something, but NOT what it promised. It is actually LONGER than the plain AJAX response. So ignoring the fact that it is actually a larger response, I moved on to the next promise:

With Direct-to-DOM rendering, we no longer need the f:ajax tag nested in our "Clear" button

Sounds straight forward right? In the example on the page, they just move the EL expression for the listener from the f:ajax tag to the h:commandButton tag. The problem there is that the method signatures are different. This is supposed to be the Getting Started tutorial, but it doesn't care to actually walk you through the steps. Anyway, I can fix that, by modifying the method signature of the clearForm method in the backing bean so that its argument is now and ActionEvent instead of AjaxBehaviorEvent. Doing that, ICEfaces does actually replace what would be a full page action with an AJAX action, which is pretty incredible, but I still have a sour taste in my mouth. Does anyone have any idea why the D2D doesn't seem to work? Am I doing something wrong? Should I still try to use ICEfaces?

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

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

发布评论

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

评论(2

嘦怹 2024-11-17 02:52:16

您为什么认为此功能运行不正确?

所发生的情况是,您获得整个表单作为响应,以便可以在 JSF 生命周期期间刷新服务器端视图和控件状态。当您使用 ajax 标签调用表单的部分更新时,实际发生的情况是,它只会将 DOM 更新呈现给指定的组件。

AJAX 确实在这里发挥了作用,但它需要发送整个 DOM,否则服务器端的逻辑可能会查看过时的数据。

这不仅仅是 ICEFaces,这也是 JSF。事实上,这与 ASP.NET 的工作原理基本相似。请参阅此链接以了解 JSF 生命周期。

http://balusc.blogspot.com/2006/09/debug-jsf -lifecycle.html

如果这不是您对这项技术的期望,我很抱歉。

Why do you assume that this is functioning incorrectly?

What is happening is that you get the whole form as a response so that the server side view and control state can be refreshed during the JSF lifecycle. What is really happening when you call a partial update of a form with an ajax tag is that it will only render DOM updates to the specified components.

AJAX really is at play here, but it needs to send the entire DOM or else logic on the server side could be looking at stale data.

This isn't just ICEFaces, this is JSF. In fact, this is fundamentally similar to even how ASP.NET works as well. See this link to understand the JSF lifecycle.

http://balusc.blogspot.com/2006/09/debug-jsf-lifecycle.html

I am sorry if this isn't what you expect out of the technology.

淡淡の花香 2024-11-17 02:52:16

ICEfaces 完成 DOM 比较后,需要发送更新。为了告诉桥的客户端部分将更新的内容放在哪里,ICEfaces 需要指定祖先 DOM 节点的一些已知 ID。服务器端渲染器只知道 JSF 组件的 ID,包括自动生成的 ID 和手动指定的 ID。它无法寻址原始 HTML 标记。因此,对于您对胖更新的观察,我的最佳猜测是您使用了大量 HTML 标签。

D2D 和 ICEfaces 桥接的另一件事是它无法添加或删除子元素。它只能完全替代ID可寻址标签。因此,如果您向表中添加新行,整个表将被更新。

不过,我的知识是基于 ICEfaces 1.8.2 的。

After ICEfaces has done its DOM comparison, it needs to send the update. To tell the client-side part of the bridge where to put the updated content, ICEfaces needs to specify some known ID of an ancestor DOM node. The server-side renderer only knows ID's of the JSF components, both autogenerated ID's and manually specified. It can't address a raw HTML tag. So my best guess for your observation of the fat update is that you're using a lot of HTML tags.

Another thing about D2D and ICEfaces bridge is that it can't add or remove a child element. It can only replace an ID-addressable tag completely. So if you, i.e. add a new row to the table, the whole table will be updated.

My knowledge is based on the ICEfaces 1.8.2 though.

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