h:commandLink uses javascript to do some behind the scenes trickery.
Here is an example of JSF and then the HTML you get.
<h:commandLink id="link" action="goto">
<h:outputText value="#{msg.linkName}"/>
</h:commandLink>
yields something like ...
<a id="_id0:link" href="#"
onclick="document.forms['_id0']['_id0:link'].value= '_id0:link';
document.forms['_id0'].submit();return false;">Next Page</a>
So the javascript is submitting the form for you. (BTW you may not
have realized it but h:commandLink requires javascript - no big deal
but you should know.)
I believe your problem is because the onsubmit() method is not fired
if you submit the form via javascript. Unfortunately, the onclick
event is where you would normally but your desired logic and that
attribute is not available (in the standard <h:commandLink>).
I just quickly checked <x:commandLink> for you (the myfaces "extended"
version) and it has an onclick attribute. I am willing to bet that
whatever code you supply there will be called before the regular
onclick stuff you can expect from commandLink.
HTH,
sean
On Wed, 16 Feb 2005 09:25:45 +0100, Michael Wiedmann
<[EMAIL PROTECTED]> wrote:
> The following seems not to work:
>
> <h:form onsubmit="return someJScriptFunction();">
> <h:commandLink action="#{bean.method}"
> <h:graphicImage url="/images/image.gif" />
> </h:commandLink>
> </h:form>
>
> The "someJScriptFunction()" is in general a simple "confirm(...)" function
> which
> asks the user for submission of the form data (and should cancel submission if
> the user presses the Cancel button).
>
> If I use a commandButton (without the image) instead this works like expected!
>
> 1) Is there something wrong with my code above?
>
> 2) As a workaround I could live with a commandButton _if_ I could use a
> graphicImage instead of the standard button. Unfortunately I couldn't find
> a way to do this.
>
> Michael
> --
>