简体   繁体   中英

Setting the value of a label in Primefaces

I have following label in my web application

<h:outputLabel id="yearLabel" value="?" style="font-weight:bold"/>

In the controller of that page I want to set the text of this label to some value (in Java).

How can I do this?

Just bind it to a bean property the usual way.

@ManagedBean
@RequestScoped
public class Bean {

    private String label;

    @PostConstruct
    public void init() {
        label = "Year"; 
    }

    // ...
}

with

<h:outputLabel ... value="#{bean.label}" />

Unrelated to the concrete question, I'm not sure what the functional requirement for this all is, so I can't tell if you're going in the right direction or not as to solving the requirement, but have you considered using resource bundles?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM