Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6935227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:04:28+00:00 2026-05-27T12:04:28+00:00

Imagine a JSF page with several components such as <h:selectOneMenu> , <h:dataTable> , <h:panelGrid>

  • 0

Imagine a JSF page with several components such as <h:selectOneMenu>, <h:dataTable>, <h:panelGrid>, etc. Each component has an ID. Is there any method or technique by which I can get the components programmatically when the constructor of the bean is invoked?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T12:04:29+00:00Added an answer on May 27, 2026 at 12:04 pm

    You can get the component tree by FacesContext#getViewRoot() and find a particular component by ID by UIComponentBase#findComponent():

    UIViewRoot viewRoot = FacesContext.getCurrentInstance().getViewRoot();
    UIComponent component = viewRoot.findComponent("someId");
    // ...
    

    However, the view root is not directly available in the bean’s constructor per se. It might return null on GET requests to a view wherein the bean is not referenced in a view build time tag or attribute. It’s however guaranteed to be available during the pre render view event.

    <f:event type="preRenderView" listener="#{bean.init}" />
    

    with

    public void init() {
        // ...
    }
    

    Unrelated to the concrete problem, it’s not clear why you need to do this, but I can tell that this is more than often a code smell. I suggest to investigate if this is really the right solution for the concrete functional requirement you’ve had in mind. For clues and hints, see also How does the 'binding' attribute work in JSF? When and how should it be used? and How to use component binding in JSF right ? (request-scoped component in session scoped bean).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Good morning all. Is there any jsf control that escapes the html tags? Imagine
Imagine we have a set of entities each of which has its state: free,
Imagine an object you are working with has a collection of other objects associated
Imagine there is a file of size 5 MB. I open it in write
Imagine there is a jar (named lib.jar ) that contains a single class and
Imagine you have a website with several drop-downs that are populated from the back-end
Imagine a view with, say, 4 subviews, next to each other but non overlapping.
My page consists of several areas which are created by iterating over a list
I am building a page that will have multiple instances of a tag such
Imagine an HTML form and the jQuery library is loaded. I'd like it such

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.