在UI组件ID:重复问题组件、问题、UI、ID

2023-09-10 21:28:40 作者:南歌初妤

我试图渲染祖父母组成部分。 在code:

I'm trying to render a grandparent component. The code:

<h:form prependId="false>
<h:panelGroup id="outer_panel">
    <ui:repeat var="curr" value="#{bean.map}">
        <h:panelGroup id="inner_panel">
            <h:commandButton value="Remove" action="actionThing" >
                <f:ajax render="outer_panel" />
            </h:commandButton>
        </h:panelGroup>
    </ui:repeat>
</h:panelGroup>
</h:form>

我得到一个异常:

I get an exception:

javax.faces.FacesException: Component with id:outer_panel not found

尝试添加索引的ID,没有工作也不:

Tried to add the index to the id, which didn't work neither:

<h:form prependId="false>
<h:panelGroup id="outer_panel">
    <ui:repeat var="curr" value="#{bean.map}" varStatus="loop">
        <h:panelGroup id="inner_panel">
            <h:commandButton value="Remove" action="actionThing" >
                <f:ajax render="#{loop.index+1}:outer_panel" />
            </h:commandButton>
        </h:panelGroup>
    </ui:repeat>
</h:panelGroup>
</h:form>

为什么找不到该ID的任何想法?

Any idea why the ID is not found?

感谢。

推荐答案

这是没有发现,因为你使用相对客户端ID渲染属性。它成为相对于最接近的父命名容器零件。在这种情况下,这就是&LT; UI:重复&GT; (它prepends产生的行索引的儿童客户端ID)。因此,与ID组件 outer_panel 必须是&LT内部; UI:重复&GT; 为了得到它的工作。但是, outer_panel 是的实际上的外面。

It is not found because you used a relative client ID in render attribute. It becomes relative to the closest parent naming container component. In this case, that's the <ui:repeat> (it prepends generated client ID of the children with the row index). So the component with ID outer_panel has to be inside the <ui:repeat> in order to get it to work. However, the outer_panel is actually outside it.

您需要指定一个相对客户端ID的绝对客户端ID来代替。为了让绝对的(所以它基本上会从视图根扫描),preFIX与客户端ID

You need to specify an absolute client ID instead of a relative client ID. To make it absolute (so that it will basically scan from the view root on), prefix the client ID with :.

<f:ajax render=":outer_panel" />

有关,你没有使用 prependId =假&LT的情况下,H:形式GT; ,那么你就应该用

For the case that you didn't use prependId="false" on the <h:form>, then you should have used

<f:ajax render=":form_id:outer_panel" />

来代替。

 
精彩推荐
图片推荐