4 Replies Latest reply on Oct 31, 2008 3:42 AM by cremersstijn

    set focus to element

    cremersstijn

      Does richfaces has a function to set the focus to an element (inputText) when the page is loading, or after an action is called?

      Greetz

        • 1. Re: set focus to element
          ma.aqcon
          • 2. Re: set focus to element
            cremersstijn

            I have some questions about that focus attribute:

            - how can i set the focus to an element when the page is loaded (so when an h:commandbutton is pressed an the page is refreshed.

            - i want to use it with modalpanel, so when i click a button to open to panel and make it visible, i want to set the focus to an element on that modalpanel, but IE gives an javascript error that the focus can't be set.


            • 3. Re: set focus to element
              nbelaevski

               

              "stijncremers" wrote:

              - how can i set the focus to an element when the page is loaded (so when an h:commandbutton is pressed an the page is refreshed.


              Try:
              <f:view>
               <html xmlns="http://www.w3.org/1999/xhtml">
               <body onload="#{rich:element('textInput')}.focus()">
               <h:form id="form">
               <h:inputText value="" id="textInput"/>
               </h:form>
               </body>
               </html>
               </f:view>


              "stijncremers" wrote:

              - i want to use it with modalpanel, so when i click a button to open to panel and make it visible, i want to set the focus to an element on that modalpanel, but IE gives an javascript error that the focus can't be set.


              Use "onshow" handler of modal panel to set focus.

              P.S. AJAX components have special "focus" attribute to point to the component you wish to give focus to...

              • 4. Re: set focus to element
                cremersstijn

                I think it works, but i can't test it due to a bug (i think) in the modalpanel:
                see http://www.jboss.com/index.html?module=bb&op=viewtopic&t=144786

                The modalpanel always hides itselfs when i do a ajax action on the modalpanel