0

I repeatedly fail to find a matrix that maps different JSF/PrimeFaces tags to supported <p:ajax> events. It is very frustrating because it limits my grasp on how to use ajax.

One particular example is within an <h:form> tag when I want the view to notify the controller whenever the user sets the focus on anywhere in the form:

<h:form>
    <p:ajax event="onClick" listener="#{myController.clickListener}"/>

But I get

<p:ajax> Event:onClick is not supported.

How do I find a list of all the supported p:ajax events for a tag (in this case h:form but any other really) when it is nested inside that tag? I am aware of the existence of this related thread but it does not offer a solution anywhere (I tried going to the PF documentation PDF but did not find it).

Community
  • 1
  • 1
amphibient
  • 29,770
  • 54
  • 146
  • 240

1 Answers1

4

Usually, ajax methods are alternatives to javascript methods, running on the server of course. And basically to tell what is the name of the event, you just need to look up the names of their javascript equivalents.

So for example, if you have in the form, the javascript event onclick, then the ajax event for the form is going to be just "click". On your example:

<h:form>
   <p:ajax event="click" listener="#{myController.clickListener}"/>
</h:form>
Mateus Viccari
  • 7,389
  • 14
  • 65
  • 101
  • funny, i arrived to the same finding in the meantime. However, I have another related question: do you know what is a good `h:form` field for passing a single parameter from the view back to the controller? i tried using ID but that is not programmatically settable. then I tried `title` and that worked (`String title = form.getTitle();` in the controller) but i am not sure if there are bad side effects to using the form title for that, i.e. if that bastardizes the title attribute. also, is there a way to retrieve the form fields in the controller via `javax.faces.component.html.HtmlForm` – amphibient Dec 17 '14 at 23:14
  • Well, that's a different question, and i am not sure if i understood what you meant. What is the "parameter" you've mentioned? Because if it's a value of another component or something like that, and it is bound to a property on your controller, and you want to recover this attribute in an ajax method, all you have to do is to process only that specific component when executing the ajax. So on your example above, it woulb be something like this: `` – Mateus Viccari Dec 17 '14 at 23:33
  • And about your question of retrieving the fields through the form on java side, i don't know because I've never worked with bound components. Do you have a specific reason to bind the whole field to the java side, instead of the field's values? – Mateus Viccari Dec 17 '14 at 23:37
  • here is the new question: http://stackoverflow.com/questions/27552465/passing-hform-parameters-to-controller-via-pajax-call – amphibient Dec 18 '14 at 17:36