[英]component.namingContainer.parent skips h:form
我做了一個復合組件,它的內部是一個<f:ajax>標記,其“ render”屬性是cc的參數。
像這樣的東西:
...
<cc:attribute name="additionalAjaxRenderIds" type="java.lang.String"></cc:attribute>
...
<h:commandLink value="test" action="#{myBean.someAction}" id="testLink" >
<f:ajax execute="@this" render="#{cc.attrs.additionalAjaxRenderIds} "/>
</h:commandLink>
...
我在表單中使用了該抄送,這已經在外部命名容器中了:
<h:form id="myForm">
...
<mycomp:myComponent id="myCC" additionalAjaxRenderIds=":#{component.namingContainer.parent.clientId}:myPanel" />
<h:panelGroup id="myPanel">
...
</h:panelGroup>
...
</h:form>
問題是,如果我寫
additionalAjaxRenderIds=":#{component.namingContainer.clientId}:myPanel"
我收到此錯誤:
<f:ajax> contains an unknown id ':j_idt44:myForm:myCC:myPanel' - cannot locate it in the context of the component testLink
而如果我使用這個(+ .parent):
additionalAjaxRenderIds=":#{component.namingContainer.parent.clientId}:myPanel"
錯誤是:
<f:ajax> contains an unknown id ':j_idt44:myPanel' - cannot locate it in the context of the component testLink
而不是預期的ID:
':j_idt44:myForm:myPanel'
所以看來我抄送的命名容器的父級不是表單,而是外部namingcontainer
有什么方法可以:1,獲得正確的父級(窗體)2,在將EL作為參數傳遞之前評估EL(這樣我就可以將計算出的clientId傳遞給我的cc而不是EL表達式,因此該組件不會引用到commandLink標記,但到h:form放在我的CC)
我知道我可以用
additionalAjaxRenderIds=":#{component.namingContainer.parent.clientId}:myForm:myPanel"
但我不喜歡那種解決方案
另外,將表單的prependId屬性設置為false會破壞整個組件查找(結果也是ajax標記)
在構建組件時不評估EL表達式,但是在訪問屬性時不評估EL表達式。 換句話說,它們是運行 時而不是buildtime 。 #{component}
指的是在評估EL表達式時的當前 UI組件,在您的特定情況下為<h:commandLink>
。 這解釋了不同的結果。
您需要以不同的方式處理此問題,而不使用#{component}
。
例如
<h:form id="myForm" binding="#{myForm}">
...
<mycomp:myComponent id="myCC" additionalAjaxRenderIds=":#{myForm.clientId}:myPanel" />
<h:panelGroup id="myPanel">
...
</h:panelGroup>
...
</h:form>
要么
<h:form id="myForm">
...
<mycomp:myComponent id="myCC" additionalAjaxRenderIds=":#{myPanel.clientId}" />
<h:panelGroup id="myPanel" binding="#{myPanel}">
...
</h:panelGroup>
...
</h:form>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.