aspose file tools*
The moose likes JSF and the fly likes confirm of h:commandLink Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "confirm of h:commandLink " Watch "confirm of h:commandLink " New topic
Author

confirm of h:commandLink

rosaria italia
Greenhorn

Joined: May 15, 2006
Posts: 28
Hello, is it possible to show a "alert confirm" on <h:commandLink as demand of confirm ? If yes, how do I do? Thanks.
Wendell Miranda
Greenhorn

Joined: May 30, 2006
Posts: 11


the space in on click is the fictitious! the name is together!

alright?

bye!
rosaria italia
Greenhorn

Joined: May 15, 2006
Posts: 28
I don't understand! Do you repeat, please?
rosaria italia
Greenhorn

Joined: May 15, 2006
Posts: 28
I have already used this method, but there is a error: "onclick is invalid for tag commandLink"... Why?
Rajeev Ravindran
Ranch Hand

Joined: Aug 27, 2002
Posts: 455
will onmouseup help ? i didnt test it though.

thanks,
Rick Beaver
Ranch Hand

Joined: Dec 14, 2004
Posts: 464
I believe that the onclick attribute is case sensitive, unlike it's HTML counterpart. My spidey sense suspects this is your problem.


ph34r my 133t j4v4 h4><0r1ng sk177z
Jamie Williams
Ranch Hand

Joined: Mar 31, 2006
Posts: 70
Are you sure you can't just use a commandButton for all this?
Wendell Miranda
Greenhorn

Joined: May 30, 2006
Posts: 11
the work 'on' and 'click' is together.

okays?

Test and tell me!
Wendell Miranda
Greenhorn

Joined: May 30, 2006
Posts: 11
not work, is words 'on' and 'click' is together!

sorry!
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
Wendell is right, h:commandLink does have an onclick attribute. But if you write:

<h:commandLink onclick="return confirm('Are you sure?');" ...>

The behaviour will not be right: the confirm dialog pops up, but pressing OK seems to have the same effect as pressing cancel! If you view the source code for the HTML page you will see why:

<a onclick="return confirm('Are you sure?'); ... more stuff ..."

JSF is also adding script to the link's onclick attribute. Zut! The simplest fix is to take that into consideration in your script:

<h:commandLink onclick="if (!confirm('Are you sure?')) return false;" ...>
[ June 01, 2006: Message edited by: Jeff Albertson ]

There is no emoticon for what I am feeling!
rosaria italia
Greenhorn

Joined: May 15, 2006
Posts: 28
"onclick" doesn't supported! I have tried "onmousedown", but also window confirm is shows, but if the answer is positive or negative remain of same page
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
Did you read my post? onclick is supported for me (I'm using MyFaces).
rosaria italia
Greenhorn

Joined: May 15, 2006
Posts: 28
In effect, 'onclick' is implicit in of h:commandLink ! But if I use an other attribute, as onmousedown, doesn't come execute nothing, not even the action. I don't know!
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
Yes, onclick is an attribute of commandLink: take a look at the API.

As for the problems you are still having, have you tried my suggestion:

<h:commandLink onclick="if (!confirm('Are you sure?')) return false;" ...>
rosaria italia
Greenhorn

Joined: May 15, 2006
Posts: 28
Thanks, I have tried 2-3 day ago, but error is:

"org.apache.jasper.JasperException: /listUsers.jsp(74,6) Attribute onclick invalid for tag commandLink according to TLD
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:39)
...."
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
What implementation of JSF are you using? As the link I posted *proves*, onclick is an attribute of commendLink.
rosaria italia
Greenhorn

Joined: May 15, 2006
Posts: 28
I use JSF 1.1.
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
Originally posted by rosaria italia:
I use JSF 1.1.


My above link was for 1.2, but here it is for 1.1:

http://java.sun.com/javaee/javaserverfaces/1.1/docs/tlddocs/h/commandButton.html

... as you can see, the onclick attribute was present back then, too.

I notice that you write that you "use JSF 1.1". That's the specification, not the implementation. You may want to reconsider the implementation you are using, whatever it is.
rosaria italia
Greenhorn

Joined: May 15, 2006
Posts: 28
Hi, my question is for h:commandLink ... as you can see in the title of topic and not for h:commandButton that you have indicated with link that you posted me...

This is my version:
Specification Version: 1.1_01 Final Release
Reference Implementation (RI) Version: 1.1_01 FCS

Thanks.
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
Sorry about my confusion. I now see that for h:commandLink, onclick is present on the JSF specs version 1.2, but not 1.1:

http://java.sun.com/javaee/javaserverfaces/1.1_01/docs/tlddocs/h/commandLink.html
http://java.sun.com/javaee/javaserverfaces/1.2/docs/tlddocs/h/commandLink.html
rosaria italia
Greenhorn

Joined: May 15, 2006
Posts: 28
Thanks 1000!

Now I'm sure that for my version it is impossible!
Bye.

P.S.
Could You have a look at my other topic(convertDateTime) for a little help?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: confirm of h:commandLink