You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Philip Newton <ph...@gmail.com> on 2008/01/18 14:54:32 UTC

commandLink, onclick, and the JSF 1.2 spec

Are there plans for MyFaces' implementation of the onclick attribute
of h:commandLink to change?

Currently, the behaviour seems to be to render onclick code as <a
onclick="USERCODE; JSFCODE;" href="#">, which doesn't interact well
with user onclick attributes such as "return validate()" or "return
confirm('Are you sure?')".

Is this behaviour compatible with the spec?

http://java.sun.com/javaee/javaserverfaces/1.2/docs/tlddocs/h/commandLink.html
says that "If an "onclick" attribute was specified by the user, render
this JavaScript in a function, and render the user's JavaScript in a
function. Render both functions in a choice function [...] such that
if the user's JavaScript returns true, then the rendered JavaScript
will also execute."

I'm not sure whether that page documents Sun's implementation of JSF
1.2 or whether it documents the JSF 1.2 spec (i.e. whether the
behaviour is something that users may rely on with any JSF 1.2
compatible implementation); the page title is "commandLink
(jsf-ri-1.2)" which implies that it documents the RI, but that page is
part of the frameset
http://java.sun.com/javaee/javaserverfaces/1.2/docs/tlddocs/index.html
, which is linked to from
http://java.sun.com/javaee/javaserverfaces/reference/api/index.html
under the "JavaServer Faces Technology 1.2 Reference Documentation"
section.

Apparently, this change was made in the RI response to
https://javaserverfaces.dev.java.net/issues/show_bug.cgi?id=71 .

So, I suppose I have two questions. 1) Is the bit I quoted part of the
JSF 1.2 specification for h:commandLink? 2) If so, does MyFaces plan
to implement that portion of the specification at some point?

(And if that's not part of the spec but only part of the JSF 1.2 spec
- does someone know whether it's documented anywhere what the effect
of an "onclick" attribute with an h:commandLink does, or whether every
implementation is free to pick its own behaviour?)

I've seen a couple of workarounds (including an explicit onclick="if
(! myfunc()) return false" rather than an unconditional
onclick="return myfunc()", and using onsubmit instead of onclick), but
after having read that portion of the documentation of h:commandLink,
I thought I could rely on the behaviour I had read there.

Cheers,
-- 
Philip Newton <ph...@gmail.com>

Re: commandLink, onclick, and the JSF 1.2 spec

Posted by Bruno Aranda <br...@gmail.com>.
Hi, if it is part of the tlddocs, it is considered to be part of the
spec. Hence you are right. Can you open a JIRA issue with this? (and
even better, provide a patch if you have the time?).

Thank you!

Bruno

On 18/01/2008, Philip Newton <ph...@gmail.com> wrote:
> Are there plans for MyFaces' implementation of the onclick attribute
> of h:commandLink to change?
>
> Currently, the behaviour seems to be to render onclick code as <a
> onclick="USERCODE; JSFCODE;" href="#">, which doesn't interact well
> with user onclick attributes such as "return validate()" or "return
> confirm('Are you sure?')".
>
> Is this behaviour compatible with the spec?
>
> http://java.sun.com/javaee/javaserverfaces/1.2/docs/tlddocs/h/commandLink.html
> says that "If an "onclick" attribute was specified by the user, render
> this JavaScript in a function, and render the user's JavaScript in a
> function. Render both functions in a choice function [...] such that
> if the user's JavaScript returns true, then the rendered JavaScript
> will also execute."
>
> I'm not sure whether that page documents Sun's implementation of JSF
> 1.2 or whether it documents the JSF 1.2 spec (i.e. whether the
> behaviour is something that users may rely on with any JSF 1.2
> compatible implementation); the page title is "commandLink
> (jsf-ri-1.2)" which implies that it documents the RI, but that page is
> part of the frameset
> http://java.sun.com/javaee/javaserverfaces/1.2/docs/tlddocs/index.html
> , which is linked to from
> http://java.sun.com/javaee/javaserverfaces/reference/api/index.html
> under the "JavaServer Faces Technology 1.2 Reference Documentation"
> section.
>
> Apparently, this change was made in the RI response to
> https://javaserverfaces.dev.java.net/issues/show_bug.cgi?id=71 .
>
> So, I suppose I have two questions. 1) Is the bit I quoted part of the
> JSF 1.2 specification for h:commandLink? 2) If so, does MyFaces plan
> to implement that portion of the specification at some point?
>
> (And if that's not part of the spec but only part of the JSF 1.2 spec
> - does someone know whether it's documented anywhere what the effect
> of an "onclick" attribute with an h:commandLink does, or whether every
> implementation is free to pick its own behaviour?)
>
> I've seen a couple of workarounds (including an explicit onclick="if
> (! myfunc()) return false" rather than an unconditional
> onclick="return myfunc()", and using onsubmit instead of onclick), but
> after having read that portion of the documentation of h:commandLink,
> I thought I could rely on the behaviour I had read there.
>
> Cheers,
> --
> Philip Newton <ph...@gmail.com>
>