jeudi 7 mai 2015

JSF load String (in right language) from properties when value depends on bean

I have a Problem with jsf and multiple languages. So my strings are in WEB_INF/classes/texte_<lang>.properties files. And are accessed for example like that <h:outputLabel value="#{messages.err_text}"/> which works fine.

The problem is, i have <h:outputLabel... element where i want to show an error message depending on the error. I would like something that works like this:

<h:outputLabel value="#{someBean.errMsg}/>

With a Bean like that

@ManagedBean()
@SessionScoped
public class SomeBean{
  public String getErrMsg(){
     if(something){
      return "#{messages.err_text}" 
     }else if(somethingElse){
      return "#{messages.err_text2}" 
     }else{
      return "#{messages.err_text3}" 
     }
  }
}

Just to be clear it doesn't work that way. I'm looking for a similar solution (or any solution) that works.
Thanks for reading.

Aucun commentaire:

Enregistrer un commentaire