Rajat Gupta
Rajat Gupta

Reputation: 26597

How to retrieve an element within composite component in javascript?

I want to be able to access an element in composite component within javascript. Since there may be several instances of this component on the page. how do I access some specific element within a specific instance of that component?

<ui:component
    xmlns="http://www.w3.org/1999/xhtml" 
    xmlns:h="http://java.sun.com/jsf/html" 
    xmlns:cc="http://java.sun.com/jsf/composite"
    xmlns:p="http://primefaces.org/ui">

    <cc:implementation> 
        <script type='text/javascript'>
            function getAddedTagsInputField(){
                return ...;
            }             
        </script>        
        ...
        ...        
        ...
        <h:inputHidden id="tagsToAdd_in" /> 
    </cc:implementation>

</ui:component>

Upvotes: 1

Views: 1515

Answers (1)

BalusC
BalusC

Reputation: 1108782

Just let JSF print the element's client ID dynamically. You can use #{cc.clientId} to get the client ID of the composite itself and then append the JSF component's ID to it.

var hiddenElement = document.getElementById("#{cc.clientId}:tagsToAdd_in");

Upvotes: 1

Related Questions