component.namingContainer.parent跳过h:form(component.namingContainer.parent skips h:form)

编程入门 行业动态 更新时间:2024-10-23 21:33:33
component.namingContainer.parent跳过h:form(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> ...

我在表单中使用此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 testLink

while 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 testLink

instead 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>

更多推荐

本文发布于:2023-08-04 09:58:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1415315.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:跳过   namingContainer   component   parent   skips

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!