2012-09-13 43 views
0

我有这个类:得到相应的本地化消息

@Getter 
@Setter 
public class Notification implements Serializable{ 

    private String color; 
    private String message; //contains an error code 
    private Boolean active; 

} 

然后,我有那些2个文件:

properties files

借助声明:

<?xml version="1.0" encoding="UTF-8"?> 
<faces-config 
    xmlns="http://java.sun.com/xml/ns/javaee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
    http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd" 
    version="2.0"> 
    <application> 
      <locale-config> 
       <default-locale>fr</default-locale> 
       <supported-locale>fr</supported-locale> 
       <supported-locale>en</supported-locale> 
      </locale-config> 
     <resource-bundle> 
     <base-name>com.cogepat.template</base-name> 
     <var>msg</var> 
     </resource-bundle> 
    </application> 
</faces-config> 

这里是我的问题:现在我有一个包含“red”,“ERRdon”,true的通知对象。 我如何在JSF代码中打印对应于“ERRdon”的字符串?

Usualy我会做

<h:outputText value="#{msg.ERRdon}:" /> 

但在这里我不能这样做。

编辑

<h:outputText class="rt" value="#{msg[BeanName.n.message]}" /> 

工作

回答

0

我有这样的片段从一个包发送JSF的消息,我希望它的工作原理:

public static void addNewFacesMessageFromBundle(FacesContext facesContext, 
      FacesMessage.Severity severity, String clientId, String key, Object[] summaryArgs, 
      Object[] detailArgs) { 

     String bundleName = facesContext.getApplication().getMessageBundle(); 
     Locale locale = facesContext.getViewRoot().getLocale(); 

     if (bundleName == null) { 
      bundleName = Constantes.DEFAULT_CUSTOM_FACES_MESSAGE_BUNDLE_NAME; 
     } 

     ResourceBundle bundle = ResourceBundle.getBundle(bundleName, locale); 

     String summary = bundle.getString(key); 
     String detail = bundle.getString(key + "_detail"); 

     summary = MessageFormat.format(summary, summaryArgs); 
     detail = MessageFormat.format(detail, detailArgs); 

     JsfUtils.addNewFacesMessage(facesContext, clientId, severity, summary, detail); 

    } 
+0

这是行不通的,因为它我想JSF框架检索相应的消息,而不是我在java中。 因为我希望文本能够更改,如果区域设置正在更改而不重新生成页面。 – Eildosa