我想实现的是能够从其他命名容器中解决一些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我实际上并没有看到任何其他方式来寻找交叉命名容器,而不是通过specyfing根(即“:foo:...:nameTxt”)的整个(绝对)id路径。在更改页面结构后,这既笨拙又容易出错。
因此 - 如何正确解决复合组件中消息中的字段“nameTxt”?
您使用的是JSF impl/version?我无法在Mojarra 2.1.4上重现这一点(也不适用于旧版本2.0.2)。 – BalusC
这是MyFaces 2.1.2。但如果我没有错,它直接来自findComponent中的解析算法,所以meaby只需要另一种方法。但它对你有用吗? - 即你可以引用其他组件,只是普通的id,没有命名容器路径? –