[英]component.namingContainer.parent skips h:form
I made a composite component, inside it is an <f:ajax> tag, and its "render" attribute is a parameter of the cc. 我做了一个复合组件,它的内部是一个<f:ajax>标记,其“ render”属性是cc的参数。
something like this: 像这样的东西:
...
<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>
...
I use this cc inside a form, thats already in an outer naming container: 我在表单中使用了该抄送,这已经在外部命名容器中了:
<h:form id="myForm">
...
<mycomp:myComponent id="myCC" additionalAjaxRenderIds=":#{component.namingContainer.parent.clientId}:myPanel" />
<h:panelGroup id="myPanel">
...
</h:panelGroup>
...
</h:form>
The problem is, if i write 问题是,如果我写
additionalAjaxRenderIds=":#{component.namingContainer.clientId}:myPanel"
i get this error: 我收到此错误:
<f:ajax> contains an unknown id ':j_idt44:myForm:myCC:myPanel' - cannot locate it in the context of the component testLink
while if i use this (+ .parent): 而如果我使用这个(+ .parent):
additionalAjaxRenderIds=":#{component.namingContainer.parent.clientId}:myPanel"
the error is: 错误是:
<f:ajax> contains an unknown id ':j_idt44:myPanel' - cannot locate it in the context of the component testLink
instead of the expected id: 而不是预期的ID:
':j_idt44:myForm:myPanel'
so it seems like the parent of my cc's naming container is not the form, but the outer namingcontainer 所以看来我抄送的命名容器的父级不是表单,而是外部namingcontainer
Is there any way to: 1, get the right parent (the form) 2, evaluate the EL before i pass it as a parameter (so i can pass the calculated clientId to my cc instead of the EL expression, so the component wont refer to the commandLink tag, but to the h:form in which i put my cc) 有什么方法可以:1,获得正确的父级(窗体)2,在将EL作为参数传递之前评估EL(这样我就可以将计算出的clientId传递给我的cc而不是EL表达式,因此该组件不会引用到commandLink标记,但到h:form放在我的CC)
I know i could use 我知道我可以用
additionalAjaxRenderIds=":#{component.namingContainer.parent.clientId}:myForm:myPanel"
but i dont like that solution 但我不喜欢那种解决方案
Also, setting the form's prependId attribute to false breaks the whole component lookup (and the ajax tag too as a result) 另外,将表单的prependId属性设置为false会破坏整个组件查找(结果也是ajax标记)
EL expressions are not evaluated at the moment the component is built, but at the moment the attribute is accessed. 在构建组件时不评估EL表达式,但是在访问属性时不评估EL表达式。 In other words, they're runtime and not buildtime .
换句话说,它们是运行 时而不是buildtime 。 The
#{component}
refers to the current UI component at the moment the EL expression is evaluated, which is in your particular case the <h:commandLink>
. #{component}
指的是在评估EL表达式时的当前 UI组件,在您的特定情况下为<h:commandLink>
。 That explains the different outcome. 这解释了不同的结果。
You need to approach this differently, without using #{component}
. 您需要以不同的方式处理此问题,而不使用
#{component}
。
Eg 例如
<h:form id="myForm" binding="#{myForm}">
...
<mycomp:myComponent id="myCC" additionalAjaxRenderIds=":#{myForm.clientId}:myPanel" />
<h:panelGroup id="myPanel">
...
</h:panelGroup>
...
</h:form>
or 要么
<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.