I'm trying to get the total number of clicks on a link in my webapp.
How do I implement this considering houtputlink don't have action attribute and calling a backing bean method with <p:remote command name="me"/> which will be triggered thus: <h:outputlink onclick="me()"/> wouldn't do justice to when user of the link right click on it to choose context menu I.e (open in new tab, new window, new incognito window etc).
Use outputLink when you must jump to a location external to your webapp or to an internal non-JSF URL. Otherwise use commandLink, which, of course, binds to a backend action and thus makes the update trivial.
like you suggested tim, to implement this i try to send the clicked url through ajax to a servlet that Updates the database. but i guess i'm still missing something as the code woudnt work.
here's what im doing thats not working. i didnt download jquery from cdn cause my project is predominantly primefaces based. adding jquery from cdn make my app behave abnormally as i have witnessed it. long story short, here's my code:
Here's what my h:outpulink looks like
and the servelet i'm trying to do database action in;
Note that the "$" notation for jQuery will really annoy the EL expression processor, which thinks that "$" heralds a variable read operation. use the "jQuery" form instead:
If you are using JSF version 2 - and by now you should be, the "f:ajax" element under the h:outputLink would be much cleaner and you could make your database operation be an AJAX action method in a backing bean.
Thanks for your time Tim. I'm on PrimeFaces 6.0, Jsf 2.2. The last time I checked I think we have now jsf 2.3 and PF 6.7? which is yet to have a community version.
Away from that really, I'd like to know what you mean by
Tim Holloway wrote: