我想實現的是能夠從其他命名容器中解決一些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,沒有命名容器路徑? –