java.util.MissingResourceException

Help
joe joseph
2011-09-07
2012-10-10
  • joe joseph
    joe joseph
    2011-09-07

    Hi,
    I use jasper report plugin for jsf beta 1.3 version and want to integrate a
    properties file for the internationalisation of the report. Everything is set
    normally but yet I still receive the java.util.MissingResourceException. Here
    is my java code and my xhtml file.

    xhtml:

    <rich:panel style="width: 780px; height: 700px;">
    
                                        <jr:dataSource 
                                            type="bean" 
                                            id="dataSource" 
                                            value="#{commandListPanel.reportViewer.principalDataSource}"/>
    
                                        <jr:report  
                                            title="Bon de Commande"
                                            format="pdf" 
                                            name="BondeCommande" 
                                            dataSource="dataSource" 
                                            path="#{commandListPanel.reportViewer.reportFileName}"
                                            style="width: 750px; height: 650px;"
                                            subreportDir="#{commandListPanel.reportViewer.subReportFileName}">
    
                                            <f:param name="REPORT_PARAMETERS_MAP" value="#{commandListPanel.reportViewer.parameters}"/>
    
                                        </jr:report>
    
                                </rich:panel>
    

    java code:

    public static ResourceBundle getMultilangueResourceBundle(){
    
            ResourceBundle resourceBundle = null;
    
            // Le FacesContext
            FacesContext context = FacesContext.getCurrentInstance();
    
            // Obtention du nom du Bundle de Message
            String messageBundleName = context.getApplication().getMessageBundle();
    
            // Locale à utiliser
            Locale locale = getLocale(context);
    
            // Obtention du ClassLoader
            ClassLoader loader = getClassLoader();
    
            // S'il n'ya pas de Bundle
            //if(messageBundleName == null || messageBundleName.trim().length() == 0)  ;
    
            resourceBundle = ResourceBundle.getBundle(messageBundleName, locale, loader);
    
            return resourceBundle;
        }
    
    /**
         * Methode d'obtention de la locale du Contexte d'un Utilisateur
         * @param context   Contexte JSf
         * @return  Locale
         */
        public static Locale getLocale(FacesContext context) {
    
            // Locale a retourner
            Locale locale = null;
    
            // Racine de l'arbre des composants
            UIViewRoot viewRoot = context.getViewRoot();
    
            // Si l'arbre n'est pas null
            if (viewRoot != null) {
    
                // On obtient la locale
                locale = viewRoot.getLocale();
    
                // Si la locale est nulle
                if(locale == null) return DEFAULTLOCALE;
    
                // Sinon
                else return locale;
            }
    
            // Sinon
            else {
    
                // Obtention de la MAP de session
                Map<String, Object> sessionMap = context.getExternalContext().getSessionMap();
    
                // Si la MAP est nulle
                if(sessionMap == null || sessionMap.size() == 0) return DEFAULTLOCALE;
    
                // Recherche de la locale dans la MAP
                locale = (Locale) sessionMap.get(EStockViewHelper.SESSIONLOCALE_PARAMETER_NAME);
    
                // Si la locale est nulle
                if(locale == null) return DEFAULTLOCALE;
    
                // Sinon
                else return locale;
            }
        }
    
    /**
         * Methode d'obtention du ClassLoader
         * @return  le ClassLoader
         */
        public static ClassLoader getClassLoader() {
    
            // Recherche du ClassLoader du Thread Courant
            ClassLoader loader = Thread.currentThread().getContextClassLoader();
    
            // Si ce ClassLoader est null (On Charge le ClassLoader Systeme)
            if (loader == null) loader = ClassLoader.getSystemClassLoader();
    
            // On retourne la ClassLoader
            return loader;
        }
    

    I then pass the resource bundle as a parameter :

      //Paramètre de la session
            //Locale courante
            rParams.put("REPORT_LOCALE", EStockMultilangue.getLocale(FacesContext.getCurrentInstance()));
    
            //fichier de ressource
            rParams.put("REPORT_RESOURCE_BUNDLE", EStockMultilangue.getMultilangueResourceBundle() );
    

    Please can some one help? Or is the problem solved with the new version?

     
  • Well, even though your code seems perfectly correct, you may get a
    "java.util.MissingResourceException" when trying to obtain a value from the
    resource bundle which hasn't been configured. If you take a look at the code
    for the "java.util.ResourceBundle" class you may find at method
    "getObject(String)" that exception being thrown when no value can't be found
    for a given key...

    Sorry, but with that information can't give more help, check your strings
    inside ResourceBundle and report... Also, in JSF 1.2 the preferred way to
    configure resource bundles is using the "resource-bundle" tag in faces-
    config.xml while the "MessagesBundle" should just be used to specify Faces'
    Messages (those regarding validation, for example). Using the former you can
    obtain "java.util.ResourceBundle" instances with current view locale by means
    of the method "Application.getResourceBundle(FacesContext, name)"

    Alonso

     
  • joe joseph
    joe joseph
    2011-09-07

    Hi Alonsoft,

    This issue has been solved. The problem was that I rather used the ireport
    REPORT_PARAMETERS_MAP to send the map of parameters, which did not work. I
    instead sent parameters one by one and then, the report could see the
    resourcebundle. Thank you.

     
  • Glad you had found a way to solve it.

    I'm thinking about adding a "resourceBundle" attribute to the report related
    tags in order to address this in the future and prevent any missunderstanding.

    Regards,
    Alonso

     
  • joe joseph
    joe joseph
    2011-09-08

    yes it will be good.