1

I would like to trigger an AJAX call when the user sets focus within an h:form, any field in the form. I explicitly do not want the call to be triggered when (s)he moves the cursor between different form fields. I currently do it using the click event in an f:ajax tag:

<h:form>                        
    <f:ajax event="click" listener="#{myController.formFocusResponse}"/>

However, that triggers each time the user clicks on the form. If there are 5 form fields, the ajax call is triggered each time the user moves onto the next field.

The available events for the form are:

click
dblclick
keydown
keypress
keyup
mousedown
mousemove
mouseout
mouseover
mouseup

Q1: Why is something like a focus or select event supported for h:form which, unlike the click, only gets triggered when the user first enters the form component?

Q2: Is there a way to hack or simulate a call trigger using other events or any other tool from the JSF kit?

amphibient
  • 29,770
  • 54
  • 146
  • 240
  • 1
    If you convert all the JSF components into its HTML code, then this question can suit for `html` and `javascript` tags, where you could get more help. JSF doesn't have an important role in this. – Luiggi Mendoza Dec 19 '14 at 21:19
  • your suggestion has merit, however, my API is JSF and not HTML/JS, despite being the foundational platform for JSF. because I plan to implement this in JSF and not straight JS (IOW, I like having HSF-generated JS), i would prefer to retain the scope of JSF – amphibient Dec 19 '14 at 21:34
  • I think you misunderstood my comment. I'm not saying stop using JSF by any mean, but giving you a recommendation about how to solve your problem. Your problem boils down to a javascript event on `
    ` HTML component, and for that point, JSF is just a mere HTML generator. So, you would have more people to help you if you focus your question as HTML + Javascript. The real implementation can be done using JSF and/or another framework like PrimeFaces.
    – Luiggi Mendoza Dec 19 '14 at 21:37
  • Also, note that `event` in `` can support any defined event on the HTML component. – Luiggi Mendoza Dec 19 '14 at 21:38
  • actually, your last statement is not true. the availability of ajax events in JSF is contingent on the component into which the ajax tag is nested. the list i provided above is for h:form. some of HTML supported events are `select` and `focus` but they are not supported for `h:form` – amphibient Dec 19 '14 at 21:40
  • refer this this answer for a full list of supported events. now, some may not be available for some components: http://stackoverflow.com/questions/7886453/what-values-can-i-pass-to-the-event-attribute-of-the-fajax-tag – amphibient Dec 19 '14 at 21:41
  • I was about to tell you to check that Q/A where BalusC cearly status that `focus` is supported. Then again, probably you cannot replicate this. I've just made a test for `
    ` and **doesn't work**, which means your problem is not about JSF but about HTML + JavaScript. Then again, JSF is just a mere HTML generator for your problem.
    – Luiggi Mendoza Dec 19 '14 at 21:47

0 Answers0