开发者

How to change the value in h:commandlink onclick

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 f开发者_如何学运维ollowdoctor is a method in bean class


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";
    // ...
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜