i have jsf page in app table using primefaces. table has ajax method should execute when specific event fired:
if client browser mobile device (handheld), event should fire ajax request must onselect
, otherwise (for desktops) event must ondblselect
(double click).
this ajax inside table:
<p:ajax event="rowdblselect" listener="#{productcontroller.productselect}" update=":mainform" />
as can see, event right fixed. know can device type using command window.matchmedia('screen , (max-width: 765px)').matches
in javascript, returns true
or false
. how can bind event, since "event" attribute of ajax tag not accept javascript code?
i solved creating 2 ajax listeners, 1 each event, , 1 not fit specific device cancelled trough javascript on onstart method, this:
<p:ajax event="rowdblselect" onstart="return !ismobiledevice();" listener="#{productcontroller.productselect}" update=":mainform" /> <p:ajax event="rowselect" onstart="return ismobiledevice();" listener="#{productcontroller.productselect}" update=":mainform" />
ismobiledevice simple js function:
function ismobiledevice() { return window.matchmedia("screen , (max-width: 765px)").matches; }