4 Replies Latest reply on Nov 16, 2012 9:43 AM by Dan Cretu

    Focus event prevents validation in JSF process validation phase

    Dan Cretu
      Hi Everyone

      My customer has an application that uses UI Dynamic tabs pattern. I have one main dynamic region where all the taskflows are using page fragments are displayed and another taskflow in another region for displaying help information about the screen that is loaded in the main region.
      Customer would like to have a contextual help, that is each time someone puts the focus in one field the help region gets updated with some detailed information in the help region.

      I have used a contextual event for refreshing the help region and one client listener and a server listener for each field to enqueue the event using the javascript

      <af:clientListener method="handleFocus" type="focus"/>
      <af:serverListener type="FocusListener" method="#{pageFlowScope.HelpBean.handleServerEvent}"/>

      function handleFocus(evt) {
      // get the focus inputText
      var curentId = evt.getSource().getId();
      // query suggest list on the server
      AdfCustomEvent.queue(evt.getSource(), "FocusListener",{clientid : curentId},true);

      This was working fine when tabbing in/out throuout the page. However the problem was that while filling in the information, the fields which were mandatory validated and displayed a validation message even if the page was not submitted (by using a save button for example).
      I have resolved that by skipping the process validations phase in the managed bean associated to the server listener, by adding this line in the pageFlowScope.HelpBean.handleServerEvent


      This is working fine as long as the page is not submitted or I am not changing tabs. The page is submitted and the process validations occurs,and the empty required fields are gaining focus, thus triggering my custom focus event. The managed bean code gets executed and showing help information but it no longer displays the validation message, in fact the validation message is displayed initially and then it disappears because I am skipping to the render response phase in the custom event execution.

      How can I realise in the custom event code that I am submitting the page or I am just navigating inside the page so I can decide or not to skip validation phase? I basically need to show the validation error message if I am submitting the page, or trying to leave the page (by switching the tab for example) and I need to hide the validation message while tabbing in/out inside the page.

      The contextual event part is not relevant here, I have the same problem with/without the contextual event.
      I am working on JDev version

      Thank you in advance for any inputs
        • 2. Re: Focus event prevents validation in JSF process validation phase
          Dan Cretu
          Hi Peter

          Thanks for the reply.
          I had already used that to skip process validations when setting the focus inside the page, and this is working. The problem is that when the page is submitted I really want to execute the process validations phase and to display the error message.
          The lifecycle is executed completely when the page is submitted and focuses on the inputText thus triggering my event which will skip the process validation phase.

          Any other idea?

          Best regards,
          • 3. Re: Focus event prevents validation in JSF process validation phase

            basically I think you have to set a flag in a bean when you press the submit button or change a tab and make the validation skip dependent on this flag.

            Maybe other ADF developers can give more details on this as I'm unfortunatelly not very experienced with submit/validation lifecycle.

            • 4. Re: Focus event prevents validation in JSF process validation phase
              Dan Cretu
              Yes, the problem is that I need to design this functionality generically in a template, and not for a specific screen, so I do not know all the buttons on the page that will submit the form and a validation is needed. The validation logic will probably be defined at model layer and each page, screen will behave differently and will have it's own validation logic, so even if this would work for one submit button, I cannot expand this for all the screens. What I need to implement is at pseudo-code level is "whenever there is an action that submits the page for some reason, execute the validation phase, display the error messages and focus on the field that generated the message by triggering the custom event that updates the help region so that the user can get some information on the field that generated the error.". The interesting thing is that if I have 2 required fields that are failing on the page, this is working fine, as neither of the fields is getting the focus, thus my custom focus event does not gets executed, but the help region does not get updated either as there are multiple fields that did not pass the validation so I cannot know whose help to display. This is acceptable from client's perspective.