<h:commandLink id="#{id}" value="#{value}" action="#{actionBean.getAction}" onclick="alert(this);"/>
In the previous simplified example, the 'this' keyword used in the Javascript function will not refer to the generated HREF element, but will refer to the global window because JSF generates the following (simplified) code:
<a onclick="var a=function(){alert(this)};var b=function(){if(typeof jsfcljs == 'function'){jsfcljs(document.forms['mainForm'],'generatedId,action,action','');}return false};return (a()==false) ? false : b();" href="#" id="generatedId">text</a>
So, since JSF wraps the user installed onclick in a function, this will point to a global window. I do not have access to the element identifier, because my code is used in a common component that can be used in loops, etc., And I do not use beans support (Facelets + JSF).
So my question is: is there a way to access the HREF element from my onclick javascript function without knowing the id?
source
share