0

I have a <h:commandLink id="link1" ..> within a <div id="div1">. I want to get the id of this div( the parent element of <h:commandLink id="link1" ..> in the backing bean, I don't want to get it directly but I want get it going through its child( ).

Please How could I achieve this. Here you can find a sample of my code.

<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>
Kukeltje
  • 12,223
  • 4
  • 24
  • 47
B.Bechir
  • 21
  • 1
  • 6

1 Answers1

0

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).

Jasper de Vries
  • 19,370
  • 6
  • 64
  • 102
  • Was writing this as a comment too with one addition: Using the 11 upvoted answer in https://stackoverflow.com/questions/951593/what-jsf-component-can-render-a-div-tag is a solution to with plain html (using passtrough attributes). I just could not find if it would be a namingcontainer then... But I would not rely on the id of a parent in a bean for 'businesslogic' (although it is hopefully in the controller and not in the real service, but still)... Coupling becomes to tight then – Kukeltje Jun 29 '18 at 10:27