【问题标题】:Jasper Reports can't use resourceBundleJasper Reports 无法使用 resourceBundle
【发布时间】:2018-12-13 13:52:11
【问题描述】:

我想在我的 jasper 报告中应用国际化。谁能告诉我我做错了什么?

我有两个资源包:

balance_de.properties

balance_en.properties

我的资源包如下所示:

mainTitle = 标题

secondaryTitle = 次要标题

我正在加载资源包:

HashMap<String, Object> parameters = new HashMap<>();
ResourceBundle resourceBundle = ResourceBundle.getBundle("balance", new Locale("de", "DE"));
parameters.put("REPORT_RESOURCE_BUNDLE", resourceBundle);

jrxml 报告中,我试图从资源包中获取 mainTitle 值:

             <textField>
                <reportElement x="0" y="0" width="798" height="20" uuid="0b25b17c-b0f4-4d46-975d-ffea5c518f28"/>
                <box>
                    <topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
                    <leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
                    <bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
                    <rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
                </box>
                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                <textFieldExpression class="java.lang.String">
                    <![CDATA[$R{mainTitle}]]>
                </textFieldExpression>
            </textField>

但是它不起作用,我不知道为什么。

【问题讨论】:

    标签: internationalization jasper-reports resourcebundle


    【解决方案1】:

    试试这个。看来我们正在将附加信息放入Map&lt;Locale, Properties&gt;。您似乎将类型 ResourceBundle 改为。

    我提前道歉,我只有这个例子,对我们来说这是有效的,但我无法准确解释如何。不过,你可以试一试:

        //Load bundle
        ResourceBundle bundle = null;
        try{
            bundle = ResourceBundle.getBundle(PROPERTY_BASE_NAME, locale);
        } catch (java.util.MissingResourceException e){
            //Not found, not avalable.
            globalProperties.put(locale, null);
            return;
        }
    
        Properties additionalProperties = new Properties();
        for(String key : bundle.keySet()){
            additionalProperties.put(key, bundle.getString(key));
        }
    
        //Store properties
        globalProperties.put(locale, additionalProperties);
    

    【讨论】:

      【解决方案2】:

      试试这个。

      HashMap<String, Object> parameterMap = new HashMap<String, Object>();
      
      parameterMap.put(JRParameter.REPORT_LOCALE, new Locale("en")); // for English
      
      parameterMap.put(JRParameter.REPORT_LOCALE, new Locale("de")); // for German
      

      【讨论】:

        猜你喜欢
        • 2011-04-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-12-13
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多