问题描述
我定义了一个自定义组件,并尝试如下使用绑定:
I defined a custom component and tried to use binding as the following:
<ui:composition ...>
<div>
<f:subview>
<a4j:outputPanel>
<h:commandButton id="t1" value="test!" />
...
</a4j:outputPanel>
</f:subview>
</div>
</ui:composition>
在添加如下所示的绑定属性之前,该组件才能正常工作:
This component works properly until I added a binding attribute like this:
<h:commandButton id="t1" binding="#{foo}" value="test!" onclick="alert('I am #{id:cid(foo)}'); return false;" />
此组件未显示,并且我找不到该按钮的相应代码.
This component doesn't show up, and I can't find the corresponding piece of code for this button.
有人知道解决办法吗?
推荐答案
有原因. binding
应该引用该组件的唯一参考.现在,您实际上已经有多个组件引用了一个和相同的引用.
There's the cause. The binding
should refer an unique reference for the component. Right now you've physically multiple components referring to one and same reference.
我不确定具体的功能要求是什么,但是当您已经在JavaScript上下文中时,通常不需要这种方法.然后,可以仅按以下方式解决特定示例:
I'm not sure what's the concrete functional requirement is, but more than often this approach is unnecessary when you're already inside the JavaScript context. The particular example can then also just be solved as follows:
<h:commandButton id="t1" value="test!" onclick="alert('I am ' + id); return false;" />
生成的HTML元素本身的ID与JSF组件客户端ID完全相同.
The ID of the generated HTML element itself is namely exactly the same as JSF component client ID.
这篇关于绑定后,JSF组件消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!