I have a table with controls in rows. I want to process another elements in the row when the input is changed:
<p:inputText value="#{item.text}">
<p:ajax event="change" onstart="refreshColumn(this)"/>
</p:inputText>
However, 'this' is something that I can't identify here:
Object { encodeViewState=function(), updateState=function(), updateElement=function(), mehr...}
Surely it doesn't contain source
attribute, as that link would suggest: .php?f=3&t=14871
Is it possible (how) to get the element that triggered the event from p:ajax
callbacks?
I have a table with controls in rows. I want to process another elements in the row when the input is changed:
<p:inputText value="#{item.text}">
<p:ajax event="change" onstart="refreshColumn(this)"/>
</p:inputText>
However, 'this' is something that I can't identify here:
Object { encodeViewState=function(), updateState=function(), updateElement=function(), mehr...}
Surely it doesn't contain source
attribute, as that link would suggest: http://forum.primefaces/viewtopic.php?f=3&t=14871
Is it possible (how) to get the element that triggered the event from p:ajax
callbacks?
-
Note that in pure JSF (
f:ajax
) you can access the id of the calling element by usingdata.source.id
– Daniel Commented Apr 8, 2014 at 13:17
1 Answer
Reset to default 6You can pass the event
instead....
XHTML
<p:inputText value="#{item.text}">
<p:ajax event="change" onstart="refreshColumn(event)"/>
</p:inputText>
JS
function refreshColumn(event) {
// "event.target.id" is the id of the inputText
console.log(event.target.id)
}
The object that you are referring in the question is PrimeFaces.ajax.AjaxUtils
.
The PrimeFaces ajax/callback functions are PrimeFaces.Behaviors.
As for what you can pass more:
PrimeFaces.bc = function(source, event, ext, behaviorsArray) {
PrimeFaces.Behavior.chain(source, event, ext, behaviorsArray);
}
The output of the change event should be something like this (passing only event):
PrimeFaces.bc(this, event, ext, ['PrimeFaces.ab({source:\'form:inputId\',event:\'change\',process:\'form:inputId\',onstart:function(cfg){refreshColumn(event);}}, arguments[1]);']);
Hope this helps.