我做了一个复合组件,里面是<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> ...我在表单中使用此cc,已经在外部命名容器中:
<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'所以看起来我cc的命名容器的父级不是表单,而是外部命名容器
有没有办法:1,得到正确的父(表格)2,在我作为参数传递它之前评估EL(所以我可以将计算的clientId传递给我的cc而不是EL表达式,所以组件不会引用到commandLink标签,但到h:表格,我把我的cc)
我知道我可以使用
additionalAjaxRenderIds=":#{component.namingContainer.parent.clientId}:myForm:myPanel"但我不喜欢那个解决方案
此外,将窗体的prependId属性设置为false会破坏整个组件查找(以及结果的ajax标记)
I made a composite component, inside it is an <f:ajax> tag, and its "render" attribute is a parameter of the 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 testLinkwhile if i use this (+ .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 testLinkinstead of the expected 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
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)
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)
最满意答案
在构建组件时,不会评估EL表达式,但是在访问该属性时。 换句话说,它们是运行 时而不是构建时 。 #{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>EL expressions are not evaluated at the moment the component is built, but at the moment the attribute is accessed. In other words, they're runtime and not 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>. That explains the different outcome.
You need to approach this differently, without using #{component}.
E.g.
<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>更多推荐
发布评论