List Info

Thread: commandLink and onclick event




commandLink and onclick event
user name
2006-07-31 17:08:06
Hi Noah and Damon, thank you for your replies 

I actually tried to remove the "return false"
statement from my javascript expression before posting this
question, because my first guess was also that this caused
the action (or form) to not submit. Unfortunately, removing
it didn't help me much, no changes to the behavior. But
every example I've seen of using commandLink with action
and javascript onclick event have used the return false, so
that's why I posted it here as well, even if I don't think
it's correct (and you seem to agree to that). 

I've also seen examples of writing it like this:
onclick="return openPopupWindow(this);"

But same result for me, nothing.. 

If I remove the script the action works properly, so it's
not a problem with the action itself. And I don't
understand that different javascripts can cause the action
to behave differently, script should be script, no matter
what it contains? 

Eivind Ronnevik

 



-----Original Message-----
From: Damon Weyant [mailtoWeyantnesl.com]
Sent: Mon 7/31/2006 4:40 PM
To: MyFaces Discussion
Subject: RE: commandLink and onclick event
 
Hello list,
 
Noah is correct...the code you provide in the onclick
attribute of the commandLink is inserted before the
generated JavaScript of the commandLink.  Eivind, if you
remove the "return false" code from the onclick
of your commandLink, you should get the behavior you
expected.
 
The Wiki explains how the commandLink works very well:
 
http://wiki.apache.org/myfaces/JavascriptWithJavaSer
verFaces
 
========================================= 
Damon Weyant - Web Application Developer 
Information Technology Department 
New Enterprise Stone & Lime Co., Inc. 
http://www.nesl.com <http://www.nesl.com/>
 
========================================= 

 

-----Original Message-----
From: Sloan, Noah M [mailto:Noah_Sloanbaylor.edu]
Sent: Monday, July 31, 2006 10:34 AM
To: MyFaces Discussion
Subject: RE: commandLink and onclick event


I think return false aborts the form submission.

  _____  

From: Rønnevik, Eivind [mailto:eivindkadme.com]
Sent: Mon 31-Jul-06 9:28 AM
To: usersmyfaces.apache.org
Subject: commandLink and onclick event


Hi!
 
Can anyone tell me why something like this would work:
<t:commandLink value="#{messages.deleteRow}"
action="#{selectRowHandler.deleteRow}"
onclick="if (!confirm('Are you sure you want to
delete this record?')) return" />

But that a similar approach (firing the java script AND the
action) doesn't?
 <t:commandLink value="#{messages.viewInfo}"
action="#{selectRowHandler.setSelectedItem}"
onclick="openPopupWindow(this); return false;"
>
        <t:updateActionListener
property="#{selectRowHandler.selectedItem}"
value="#" />
</t:commandLink>

Basically, the first link fires BOTH the javascript and the
action, but the second one fires only the javascript. Why
should the contents of the script have something to say for
if the action is triggered or not?

I thought that the commandLink was capable of triggering
both, anybody have some experiences with this?

Regards, 

Eivind

 

 

 

 




[1]

about | contact  Other archives ( Real Estate discussion Medical topics )