首页 > 解决方案 > 如何获取知道其 id 的 jsf 组件父级的 id?

问题描述

我有一个<h:commandLink id="link1" ..>内一个<div id="div1">。我想得到这个 div 的 id(<h:commandLink id="link1" ..>支持 bean 的父元素,我不想直接得到它,但我想让它通过它的 child( )。

请问我怎么能做到这一点。在这里您可以找到我的代码示例。

<div style="text-align:center;    height: 50px; width: 100%; background: wheat; 
                border: 1px #6e5d40 solid; margin-top: 5px;">
        <h:form>
            <ui:repeat var="label1" value="#{backingBean.listOfSearchValue}">
                <span class="filterLabel">#{label1} <h:commandLink class="glyphicon glyphicon-remove"></h:commandLink>
                </span>
            </ui:repeat>
        </h:form>
    </div>

标签: jsfmanaged-bean

解决方案


Don't just use a plain HTML div, but use a h:panelGroup layout="block". Then it is just a matter of getting the parent of the UIComponent (the button in your case).

See also OmniFaces Components for help with finding components from within your bean, especially getClosestParent(UIComponent component, Class<C> parentType).


推荐阅读