1

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>

1 Answer 1

1

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");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.