我做了什么破坏了我的 xForms?

发布于 2024-07-08 15:35:59 字数 267 浏览 9 评论 0 原文

我正在学习 xForms,但显然还不够好,因为我不明白为什么 这个代码 不起作用。

它在 FF2 中使用 xForms 扩展进行解析,但不呈现表单控件。 IE7 和 X-Smiles 给我带来了不同的问题,但我不确定这些问题是因为我的 xForms 还是其他原因 - 直到我让它在 FF2 中工作之前我真的无法判断。

I'm learning xForms, but apparently not well enough because I can't figure out why this code doesn't work.

It parses in FF2 w/ the xForms extension but does not render the form controls. IE7 and X-Smiles give me different problems, but I'm not sure if those problems are becaause of my xForms or because of something else- until I get it working in FF2 I can't really tell.

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

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

发布评论

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

评论(4

枕梦 2024-07-15 15:35:59

不幸的是,本文档包含大量问题,我将依次讨论每个问题。

1) 最大的问题出现了几次,似乎源于模型和 UI 之间的一些混淆。 这两者在 XForms 中是完全独立的,它遵循模型-视图-控制器设计模式。 因此,您需要记住,模型中的所有内容与 UI 中的所有内容完全分开。 两者之间的关系很简单,UI 控件可以绑定到模型中的实例数据节点。 实际上,就您的文档而言,这意味着您的 select1repeat 元素不应该是 model 元素的子元素。 只有instancebind 和action 元素可以是model 的子元素。

2) 您正在使用多个 model 元素,这在如此简单的形式中是不必要的(因为每个 model 可能包含许多 instance绑定)。 我之所以提出这一点,是因为您通过使用多个模型引入了一些潜在的陷阱,最好通过尽可能坚持使用一个模型来避免这些陷阱。 例如,instance XPath 函数无法跨model 工作,因此您必须非常小心它们之间的数据依赖关系。 此外,UI 控件根据其绑定的 model 进行刷新,这在过去当控件明显刷新不正常时经常给我带来问题。

3) 您尝试使用 repeat 元素将子 bind 应用到许多节点。 这是错误的,因为 repeat 是 UI 元素,而不是模型元素。 但是,由于 bind 采用 nodeset 属性而不是 ref 属性,因此您实际上不需要 repeat根本不。 相反,您可以这样做:

<xf:bind nodeset="//want" readonly="true()" />

4) 在许多 UI 控件上,您指定了一个 bind 属性和一个 ref 属性。 这些属性是互斥的,因为它们代表实现同一目标的不同方法。 ref 属性应包含标识要将 UI 控件绑定到的实例数据节点的 XPath。 bind 属性应包含已在其他地方定义的绑定元素的 id(在这种情况下,绑定元素本身将通过其节点集属性来标识控件绑定到的节点)。 因此,通过在同一个 UI 控件上使用这两个属性,您就会自相矛盾。

5) 在某些地方,您尝试使用 ref 属性将控件绑定到 UI 中的另一个元素。 控件只能绑定到实例数据。

6) 您在 repeat 中有一个 setvalue,您尝试在 xforms-value-changed 事件上调用它。 此事件不会分派到 repeat 元素,因此您的 setvalue 将永远不会被调用。 xforms-value-changed 事件仅分派到核心表单控件,即 XForms 规范中定义为:

input|secret|textarea|output|upload|range|trigger|submit|select|select1

7) 此问题的另一个答案提到您将 model 元素放入文档正文中是错误的。 不幸的是,我没有足够的声誉来发表评论,但我只是想指出这个答案实际上是错误的。 尽管将 model 元素放在文档 head 中已成为惯例,但 XForms 规范中没有任何规定这样做。 事实上,一个主要的 XForms 处理器 Ubiquity XForms 实际上需要 model由于浏览器的限制,必须位于文档 body 中。

This document contains a ton of problems unfortunately, I'll go through each of them in turn.

1) The biggest problem occurs a few times and seems to stem from some confusion between the model and the UI. The two are entirely separate beasts in XForms, which adheres to the model-view-controller design pattern. So you need to remember that everything in the model is entirely separate from everything in the UI. The relationship between the two is simply that UI controls may bind to instance data nodes in your models. Practically, in terms of your document, this means that your select1 and repeat elements should not be children of model elements. Only instance, bind and the action elements may be children of model.

2) You are using multiple model elements, which is unnecessary in such a simple form (because each model may contain many instances and binds). The reason I flag this is up is because you introduce a couple of potential pitfalls by using multiple models, which are best avoided by sticking to one model where possible. For example, the instance XPath function will not work across models, so you have to be very careful about data dependencies between them. Also, a UI control is refreshed according to which model it is bound to, which has often caused me problems in the past when controls are apparently not refreshing sanely.

3) You've tried to use a repeat element to apply a child bind to many nodes. This is wrong because repeat is a UI element, not a model element. However, since bind takes a nodeset attribute instead of a ref attribute, you don't actually need a repeat at all. Instead, you can just do this:

<xf:bind nodeset="//want" readonly="true()" />

4) On many of your UI controls, you are specifying both a bind attribute and a ref attribute. These attributes are mutually exclusive, since they represent different ways to achieve the same thing. The ref attribute should contain XPath that identifies an instance data node that you want to bind the UI control to. The bind attribute should contain the id of a bind element that has been defined elsewhere (the bind element itself will identify the node that the control binds to in this case, via its nodeset attribute). So by using both attributes on the same UI control, you are contradicting yourself.

5) In some places, you've attempted to use a ref attribute to bind a control to another element in the UI. Controls may only be bound to instance data.

6) You have a setvalue inside a repeat, which you are attempting to invoke on the xforms-value-changed event. This event is not dispatched to the repeat element, so your setvalue will never be invoked. The xforms-value-changed event is only dispatched to the core form controls, which are defined in the XForms spec as:

input|secret|textarea|output|upload|range|trigger|submit|select|select1

7) Another answer to this question mentions that you are wrong to put your model elements in the document body. Unfortunately I don't have enough reputation to comment there, but I just wanted to point out that answer is actually wrong. Although it has become conventional to put the model elements in the document head, nothing in the XForms spec mandates this. In fact, one major XForms processor, Ubiquity XForms, actually requires models to be in the document body, because of browser limitations.

反差帅 2024-07-15 15:35:59

您不应该将模型放置在主体部分。 相反,所有模型定义都应位于头部。 现在,您的代码不符合标准并且非常难以理解。

Xforms Wiki 书籍 是学习 XForms 的良好资源。

You shouldn't place your models in the body section. Instead all model definitions should be in the head section. As it is now, your code isn't standard compliant and is very difficult to understand.

Xforms Wiki book is a good resource for learning XForms.

小…红帽 2024-07-15 15:35:59

我将添加 xf:repeat、xf:group、xf:input,... 不能是 xf:model 的子级

I'll add that xf:repeat, xf:group, xf:input,... can't be children of xf:model

甜宝宝 2024-07-15 15:35:59

XForms 验证器 是一个不错的起点。 之后,我建议从一个工作示例开始,逐渐添加代码,以观察哪个部分出现故障。

A good place to start could be an XForms validator. Afterwards, I'd recommend starting from a working example and adding your code gradually, to observe which part is failing.

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