Setting commandLink value through ManagedBean

317 Views Asked by At

I have been using primefaces in JSF and trying to set commandLink value through managedbean class.

<p:commandLink value="#{loginBean.userClass}" id="userclass" action="{user.userClassAction}" />

ManagedBean:

 public String getUserClass()
 {
        return "userClass";
 }

I am asking that, is this correct way to that process from server side

Any suggestion for this .. Is this format correct , if so how can i use it appropriate way.

1

There are 1 best solutions below

2
On

What do you want to achieve? The value is the text of the link. It would be "userClass" in this case and I'm not sure this makes sense here.

If you want to change the css class you may do that via the styleClass attribute.

If you really want to have some kind of dynamic text for the link. Then yes, using a managed bean is probably the only (non-hacky) way to do so.

If you only want to care about internationalization, then you better use the standard java-way for that. Using .properties files, referencing them via #{msg['key']} and declaring them for JSF via:

<resource-bundle>
    <base-name>your.pkg.MessageBundle</base-name>
    <var>msg</var>
</resource-bundle>