You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Jakob Korherr <ja...@gmail.com> on 2010/01/04 16:04:35 UTC

Re: javascript problem with commandlink and onclick after update to JSF 1.2

Hi Michael,

Unfortunately I don't think it is possible to refer to the clicked link
inside the function definition. The only way I know is to use
document.getElementById('...').

»How is the id of the commandLink placed into oamSubmitForm as parameter?«
The renderer of the command link generates this javascript and so it puts
the id there.

>From my point of view it would be great if myfaces would replace »this« with
»document.getElementById('clienId')« automatically. However, I don't know if
this violates the jsf 1.2 spec.

Regards,
Jakob

2010/1/4 Michael Heinen <mi...@recommind.com>

> 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
>

RE: javascript problem with commandlink and onclick after update to JSF 1.2

Posted by Michael Heinen <mi...@recommind.com>.
Hi Jakob,

Thanks for the initiative.

BTW Richfaces does not render command links this "new" way.
They do it still in the "old" way. The user specific content of the onclick attribute is not wrapped in a js function and "this" is still working.
Maybe they are not spec compliant, don't know whether there are differences for ajax and non-ajax commandlinks.

Michael


-----Original Message-----
From: sethfromaustria@gmail.com [mailto:sethfromaustria@gmail.com] On Behalf Of Jakob Korherr
Sent: Montag, 4. Januar 2010 16:46
To: MyFaces Discussion
Subject: Re: javascript problem with commandlink and onclick after update to JSF 1.2

Hi Michael,

I'll write a mail to the dev list and ask for opinions. On my opinion we
surely can implement this in tomahawk, because the spec does not define the
behavior of the tomahawk components and it certainly is an improvement.

I'll keep you up to date!

Regards,
Jakob

2010/1/4 Michael Heinen <mi...@recommind.com>

> Hi Jakob,
>
> I feared this.
> I used "this" often in dynamic expressions returned from managed beans to
> do some client side stuff e.g.
>
> getOnclick(){
>  doit(this);
> }
>
> "From my point of view it would be great if myfaces would replace »this«
> with »document.getElementById('clienId')« automatically."
>
> This would be a great improvement!
> +1 from my side.
>
> Michael
>
>
> -----Original Message-----
> From: sethfromaustria@gmail.com [mailto:sethfromaustria@gmail.com] On
> Behalf Of Jakob Korherr
> Sent: Montag, 4. Januar 2010 16:05
> To: MyFaces Discussion
> Subject: Re: javascript problem with commandlink and onclick after update
> to JSF 1.2
>
> Hi Michael,
>
> Unfortunately I don't think it is possible to refer to the clicked link
> inside the function definition. The only way I know is to use
> document.getElementById('...').
>
> »How is the id of the commandLink placed into oamSubmitForm as parameter?«
> The renderer of the command link generates this javascript and so it puts
> the id there.
>
> From my point of view it would be great if myfaces would replace »this«
> with
> »document.getElementById('clienId')« automatically. However, I don't know
> if
> this violates the jsf 1.2 spec.
>
> Regards,
> Jakob
>
> 2010/1/4 Michael Heinen <mi...@recommind.com>
>
> > 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
> >
>

Re: javascript problem with commandlink and onclick after update to JSF 1.2

Posted by Jakob Korherr <ja...@gmail.com>.
Hi Michael,

I'll write a mail to the dev list and ask for opinions. On my opinion we
surely can implement this in tomahawk, because the spec does not define the
behavior of the tomahawk components and it certainly is an improvement.

I'll keep you up to date!

Regards,
Jakob

2010/1/4 Michael Heinen <mi...@recommind.com>

> Hi Jakob,
>
> I feared this.
> I used "this" often in dynamic expressions returned from managed beans to
> do some client side stuff e.g.
>
> getOnclick(){
>  doit(this);
> }
>
> "From my point of view it would be great if myfaces would replace »this«
> with »document.getElementById('clienId')« automatically."
>
> This would be a great improvement!
> +1 from my side.
>
> Michael
>
>
> -----Original Message-----
> From: sethfromaustria@gmail.com [mailto:sethfromaustria@gmail.com] On
> Behalf Of Jakob Korherr
> Sent: Montag, 4. Januar 2010 16:05
> To: MyFaces Discussion
> Subject: Re: javascript problem with commandlink and onclick after update
> to JSF 1.2
>
> Hi Michael,
>
> Unfortunately I don't think it is possible to refer to the clicked link
> inside the function definition. The only way I know is to use
> document.getElementById('...').
>
> »How is the id of the commandLink placed into oamSubmitForm as parameter?«
> The renderer of the command link generates this javascript and so it puts
> the id there.
>
> From my point of view it would be great if myfaces would replace »this«
> with
> »document.getElementById('clienId')« automatically. However, I don't know
> if
> this violates the jsf 1.2 spec.
>
> Regards,
> Jakob
>
> 2010/1/4 Michael Heinen <mi...@recommind.com>
>
> > 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
> >
>

RE: javascript problem with commandlink and onclick after update to JSF 1.2

Posted by Michael Heinen <mi...@recommind.com>.
Hi Jakob,

I feared this. 
I used "this" often in dynamic expressions returned from managed beans to do some client side stuff e.g. 

getOnclick(){
  doit(this);
}

"From my point of view it would be great if myfaces would replace »this« with »document.getElementById('clienId')« automatically."

This would be a great improvement! 
+1 from my side.

Michael


-----Original Message-----
From: sethfromaustria@gmail.com [mailto:sethfromaustria@gmail.com] On Behalf Of Jakob Korherr
Sent: Montag, 4. Januar 2010 16:05
To: MyFaces Discussion
Subject: Re: javascript problem with commandlink and onclick after update to JSF 1.2

Hi Michael,

Unfortunately I don't think it is possible to refer to the clicked link
inside the function definition. The only way I know is to use
document.getElementById('...').

»How is the id of the commandLink placed into oamSubmitForm as parameter?«
The renderer of the command link generates this javascript and so it puts
the id there.

From my point of view it would be great if myfaces would replace »this« with
»document.getElementById('clienId')« automatically. However, I don't know if
this violates the jsf 1.2 spec.

Regards,
Jakob

2010/1/4 Michael Heinen <mi...@recommind.com>

> 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
>

Re: javascript problem with commandlink and onclick after update to JSF 1.2

Posted by Jakob Korherr <ja...@gmail.com>.
That's also an option!

2010/1/14 Mike Kienenberger <mk...@gmail.com>

> Wow.  I just saw this, and it's really ugly.   I wonder if some of my
> app's code is mysteriously breaking now.
>
> Why couldn't you do something like Michael's workaround instead of
> trying to replace "this" with "document.getElementById('...')".   Ie,
> pass "this" as an argument to the intermediate function, and use the
> argument passed wherever "this" appears?
>
> On Mon, Jan 4, 2010 at 10:04 AM, Jakob Korherr <ja...@gmail.com>
> wrote:
> > Hi Michael,
> >
> > Unfortunately I don't think it is possible to refer to the clicked link
> > inside the function definition. The only way I know is to use
> > document.getElementById('...').
> >
> > »How is the id of the commandLink placed into oamSubmitForm as
> parameter?«
> > The renderer of the command link generates this javascript and so it puts
> > the id there.
> >
> > From my point of view it would be great if myfaces would replace »this«
> with
> > »document.getElementById('clienId')« automatically. However, I don't know
> if
> > this violates the jsf 1.2 spec.
> >
> > Regards,
> > Jakob
> >
> > 2010/1/4 Michael Heinen <mi...@recommind.com>
> >
> >> 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
> >>
> >
>

Re: javascript problem with commandlink and onclick after update to JSF 1.2

Posted by Mike Kienenberger <mk...@gmail.com>.
Wow.  I just saw this, and it's really ugly.   I wonder if some of my
app's code is mysteriously breaking now.

Why couldn't you do something like Michael's workaround instead of
trying to replace "this" with "document.getElementById('...')".   Ie,
pass "this" as an argument to the intermediate function, and use the
argument passed wherever "this" appears?

On Mon, Jan 4, 2010 at 10:04 AM, Jakob Korherr <ja...@gmail.com> wrote:
> Hi Michael,
>
> Unfortunately I don't think it is possible to refer to the clicked link
> inside the function definition. The only way I know is to use
> document.getElementById('...').
>
> »How is the id of the commandLink placed into oamSubmitForm as parameter?«
> The renderer of the command link generates this javascript and so it puts
> the id there.
>
> From my point of view it would be great if myfaces would replace »this« with
> »document.getElementById('clienId')« automatically. However, I don't know if
> this violates the jsf 1.2 spec.
>
> Regards,
> Jakob
>
> 2010/1/4 Michael Heinen <mi...@recommind.com>
>
>> 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
>>
>