• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to disable a h:commandlink when it is clicked once

 
Ashwini Rai
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am a student. I need to implement h:commandlink in my project. I need to change the value "Follow" to "Following" in the commandlink once the user clicks it. How do i do that?

If i could not do that , I am thinking that i should disable the link to prevent the user from clicking on the same link. how do i disable the link once it is clicked. Can someone help me with this? Thanks for your time and help in advance.

<h:commandlink id="followdoc" action = "Usermanger.followdoctor" value = "Follow"/>
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please be sure to ask JSF questions in the JSF forum. I have moved this post there for you.
 
Ashwini Rai
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Bear: Thanks for posting my question in right place.
I would really appreciate if anyone can help me with this question. Thanks
 
Karanjit Singh
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Suha

You have both the options open for you, i.e you can change the text of link on click and also disable it too. I assume Usermanger is your Bean Name.

To change Text on the link when clicked:

you need to declare a String variable in your backing bean, let it be "linkValue" and initialize it to "Follow". Make getter & setter for the same. Now, you just need to place this in the value attribute of your h:commandlink as follows:

<h:commandlink id="followdoc" action = "Usermanger.followdoctor" value = "Usermanger.linkValue"/>

This will print "Follow". Now you just need to change the value of linkValue varaible to "Following". And the changes will get reflected.

To disable the link on First Click

Here you need to declare a boolean variable in your backing bean which will have its value "false" by default. When the function "followdoctor" will be invoked, you need to change the value of that variable from "false" to "true". Also your h:commandlink will look like as follows:

<h:commandlink id="followdoc" action = "Usermanger.followdoctor" value = "Follow" disabled="#{Usermanger.booleanVariable}"/>

Hope this helps.

Regards

Karanjeet Singh
 
Ashwini Rai
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Karanjit,
Thanks a lot for your reply. It is working perfectly fine.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!