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 7544007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:34:28+00:00 2026-05-30T08:34:28+00:00

I need to set focus to an h:inputText which is in a component like

  • 0

I need to set focus to an h:inputText which is in a component like this:

    <h:panelGroup id="bidView">
        <h:panelGroup rendered="#{some conditions}">            
            <h:outputText>
            Some text</h:outputText>                
            <p:inputText id="amountInput" value="#{bean.bidAmount}" />
            <h:commandButton value="Submit">
                <f:ajax listener="#{bean.submit(item)}" execute="@form" render="bidView "/>
            </h:commandButton>
        </h:panelGroup>
            <script>document.getElementById('amountInput').focus()</script>

    </h:panelGroup>

The input text that needs to get the focus is “amountInput.” The javascript code I was thinking should do it is

<script>document.getElementById('amountInput').focus()

but it generates the following error: “Cannon call method ‘focus’ of null.” What am I missing?

(I should add that bidView is rendered when the user clicks a Submit button next to each row inside a table. It, bidView, then shows up under that clicked row and allows the user to enter a number and have the server process it.)

  • 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-30T08:34:29+00:00Added an answer on May 30, 2026 at 8:34 am

    The document.getElementById() expects the generated HTML client ID, not JSF component ID. You need to open the page in browser, do rightclick and View Source to see it yourself. Locate the generated HTML <input> element of <p:inputText> and use exactly its id. This ID is prepended with the component ID of every parent NamingContainer component such as <h:form>, <h:dataTable>, <p:tabView>, etc.

    You seem to be using PrimeFaces. You can use the p:component() EL function to print the client ID of the given component ID.

    <script>document.getElementById("#{p:component('amountInput')}").focus()</script>
    

    An alternative, if you were not using PrimeFaces, is to bind the component to the view and use UIComponent#getClientId().

    <h:inputText id="amountInput" binding="#{amountInput}" value="#{bean.bidAmount}" />
    ...
    <script>document.getElementById("#{amountInput.clientId}").focus()</script>
    

    Coming back to PrimeFaces, are you aware of the <p:focus> component? You could also use it as well.

    <h:panelGroup id="bidView">
        <p:focus context="bidView" />
        ...
    </h:panelGroup>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'd like to keep focus on the entry text widget, which will pass whatever's
I need to set the height of every textbox on my form, some of
I need to set the text within a DIV element dynamically. What is the
I need to set up this scenario: A SQL Server 2005 database will create
I use h:selectOneRadio tag. I need to set the cursor focus to first radio
My goal is to set the focus to a specific inputText. As there seems
i'm having a textbox where i need to set focus/ cursor at required index
I am unable to set focus to my php page dc-test.php (this is a
I need to set up an icon for my application which must change when
I am trying to set the focus of a uitextfield. Using this code [_partNoTextField

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.