1 Reply Latest reply on Aug 3, 2010 7:46 AM by ilya_shaikovsky

    required fields x focus

    edilmar

      Hi,

       

      I have a webapp JSF2+RichFaces3.3.3.

      I use required and requiredMessage to control required fields.

      All works fine when user doesn't fill the field.

      But, I would to know if there is some way to focus the field required

      after the requiredMessage is showed by JSF. I didn't find how to

      do this because I didn't know how to call some javascript code to

      implement the focus.

        • 1. Re: required fields x focus
          ilya_shaikovsky

          just add some code to server side which check's if there are some faces messages (for example in phaseListener before render - add check for FacesContext.getClientIdsWithMessages()). if some components failed - store the first one in some view bean property. Then there are different options - you could add the clientId to focus attribute of the action component using EL binding or just add to inline script (which will be reRender'ed after request) like

           

          <script>

          focusTheFiled(#{someBean.storedIdOfFailedComponent});

          </script>