Hi guys,
Michael Heinen just wrote on the user list about a javascript problem in the
onclick attribute of a commandLink (see forwarded mail).
The problem is that you cannot use "this" correctly, because in jsf 1.2 the
javascript code in onclick of a commandLink is automatically put in a custom
javascript object. Thus, "this" references to the custom javascript object
instead of the HTML element.
My idea to deal with this would be to replace »this« with
»document.getElementById('clienId')« automatically. However, I don't know if
this violates the spec when we implement it on h:commandLink, because it's
not allowed to change the javascript code in the renderer, I think.
However, we could add this functionality to t:commandLink.
Any comments about this?
Regards,
Jakob Korherr
---------- Forwarded message ----------
From: Michael Heinen <[email protected]>
Date: 2010/1/4
Subject: javascript problem with commandlink and onclick after update to JSF
1.2
To: MyFaces Discussion <[email protected]>
Hi,
I have another problem after my update from myfaces 1.1.5 to 1.2.8.
I cannot use "this" anymore in onclick attributes of commandLinks due to
changed rendering of commandLinks. Instead of the link the outer form is
accessed via "this".
sample:
<h:form id="tabform" ...>
<t:commandLink id="tabTemplates" forceId="true"
onclick="alert(this.id);"
action="#{...}">
output with 1.1.5: tabTemplates
output with 1.2.8: tabform
rendered html onclick attributes:
myfaces 1.2.8: onclick=var cf = function(){alert(this.id);var oamSF =
function(){return oamSubmitForm('tabform','tabTemplates');};return
(cf()==false)? false : oamSF();
myfaces 1.1.5: onclick=alert(this.id);
One workaround is something like this:
onclick="var me1=getObj('tabTemplates'); alert(m1);"
This change is unfortunately really expensive and error-prone for me because
I used this construct more than hundred times and often it is generated
dynamically :-(
Is there any other workaround or trick to access the clicked link in the
onclick attribute via javascript inside a function definition?
How is the id of the commandLink placed into oamSubmitForm as parameter?
Michael