【发布时间】:2011-12-30 10:48:06
【问题描述】:
我想要实现的是能够从其他命名容器中处理一些 JSF 组件。
用例:复合组件,它使用 - 封装一些功能,用于在复合组件之外定义的字段。
一些代码:
<form id="foo">
...
<label for="nameTxt">Name:</label>
<component:customError forField="nameTxt" />
<h:inputText id="nameTxt" />
...
</form>
和组件:
<composite:implementation>
<h:panelGroup id="errorComponent">
...
<h:message for="#{cc.attrs.forField}" id="errorMsg" style="display:none;" />
...
</h:panelGroup>
</composite:implementation>
问题是在渲染我得到的消息时:
Could not render Message. Unable to find component 'nameTxt' (calling findComponent on component 'j_id963445801_469fc056:errorMsg')
我想我理解问题在于字段“nameTxt”和消息“errorMsg”位于其他命名容器中。所以我想要做的就是指定“nameTxt”的路径/id 与一些共同的祖先相关。
在研究了算法UIComponentBase:findComponent 之后,我实际上没有看到任何其他方法来处理交叉命名容器,而不是通过从根指定整个(绝对)id 路径(即“:foo:...:nameTxt”) )。而且这在更改页面结构后既笨拙又容易出错。
那么 - 如何从复合组件的消息中正确处理字段“nameTxt”?
【问题讨论】:
-
您使用的是什么 JSF impl/version?我不能在 Mojarra 2.1.4 上重现这个(也不能在旧的 2.0.2 上)。
-
这是 MyFaces 2.1.2。但如果我没记错的话,它直接来自 findComponent 中的解析算法,所以这里只需要另一种方法。但它对你有用吗? - 即您可以仅使用普通 id 引用其他组件,没有命名容器路径?
标签: jsf-2 facelets myfaces composite-component