0

我有这门课:

@Getter
@Setter
public class Notification implements Serializable{
    
    private String color;
    private String message; //contains an error code
    private Boolean active;

}

然后我有这两个文件:

属性文件

声明者:

<?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”对应的字符串?

通常我会做

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

但在这里我不能这样做。

编辑

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

正在工作中

4

1 回答 1

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);

    }
于 2012-09-13T14:37:44.760 回答