tags:

views:

23

answers:

1

Hi, 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? Can someone help me with this? Thanks for your time and help in advance.

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

Usermanager is my jsf managed bean class and followdoctor is a method in bean class

+1  A: 

If you want to do this at the client side, just grab JavaScript. After all, JSF ends up as plain HTML in webbrowser (rightclick page in browser and choose View Source, you'll understand what I mean).

<h:commandLink value="Follow" action="#{bean.followDoctor}" onclick="this.innerHTML='Following'" />

But if you want to change (and if necessary memorize/persist) this in the server side, then just make it a bean property so that you can change it in the action method.

<h:commandLink value="#{bean.linkValue}" action="#{bean.followDoctor}" />

with

private String linkValue;

public Bean() {
    this.linkValue = "Follow"; // Preinitialize it somehow.
}

public String followDoctor() {
    this.linkValue = "Following";
    // ...
}
BalusC
Thanks a lot BalusC. It worked for me.
cmpestudent
You're welcome.
BalusC