【问题标题】:How do I get the id of a jsf component parent knowing its id?如何获取知道其 id 的 jsf 组件父级的 id?
【发布时间】:2018-12-08 10:27:15
【问题描述】:

我在<div id="div1"> 中有一个<h:commandLink id="link1" ..>。我想得到这个 div 的 id(<h:commandLink id="link1" ..> 在 backing 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>

【问题讨论】:

    标签: jsf managed-bean


    【解决方案1】:

    不要只使用纯 HTML div,而是使用 h:panelGroup layout="block"。然后只需获取UIComponent 的父级(您的情况下的按钮)。

    另请参阅 OmniFaces Components 以获取从 bean 中查找组件的帮助,尤其是 getClosestParent(UIComponent component, Class&lt;C&gt; parentType)

    【讨论】:

    • 也将其作为评论写了一个补充:在stackoverflow.com/questions/951593/… 中使用 11 个赞成的答案是使用纯 html 的解决方案(使用 passtrough 属性)。我只是找不到它是否会是一个命名容器......但我不会依赖 bean 中父级的 id 来实现“业务逻辑”(尽管它希望在控制器中而不是在实际服务中,但仍然)... 耦合变得很紧
    猜你喜欢
    • 2019-03-17
    • 2012-05-11
    • 2013-03-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-30
    相关资源
    最近更新 更多