Application message bundle

I'm setting up an application level message bundle to handle error messages as described in other threads. I have a question about validator messages and the insertion of maximum and minimum field values. I've seen these examples and I have the following assumptions:
{0} and {1}, these are for numeric range values
'{0}', this is for numbers
"{0}", this is for Strings
So, If I put these in my messages (listed below) am I safe to assume that jsf will replace them with the appropriate values?
Thanks!
javax.faces.component.UIInput.REQUIRED=Please enter a value
javax.faces.validator.NOT_IN_RANGE=Please enter a value between {0} and {1}
javax.faces.validator.DoubleRangeValidator.MAXIMUM=Please enter a value less than '{0}'
javax.faces.validator.LongRangeValidator.MAXIMUM=Please enter a value less than '{0}'
javax.faces.validator.DoubleRangeValidator.MINIMUM=Please enter a value greater than '{0}'
javax.faces.validator.LongRangeValidator.MINIMUM=Please enter a value greater than '{0}'
javax.faces.validator.LengthValidator.MAXIMUM=Please enter a value less than "{0}" characters
javax.faces.validator.LengthValidator.MINIMUM=Please enter a value greater than "{0}" characters

I don't know about the quotation marks and all, seems to print strings just fine for me when I leave the quotes out.
{0}, {1}, {2}, ..., {n} represent array indexes. You'll need a message factory to properly create messages that input the appropriate array elements in the right message spots.
If you don't use the message factory, you'll simply get the message character for character. i.e. "Please enter a value between {0} and {1}"
To create a MessageFactory, just copy the one JSF uses internally. You can find it in the javax.faces.component package (in the jsf-api.jar file).
To get a proper message out of the factory, call it using the getMessage() method. Something like this:
     FacesMessage msg = MessageFactory.getMessage(context,
          "javax.faces.validator.NOT_IN_RANGE", new Object[] {new Integer(1), new Integer(5)});This will return a FacesMessage that contains this message:
"Please enter a value between 1 and 5"
Hope this helps,
CowKing

Similar Messages

  • How to specify multiple message bundles in faces-config.xml

    Hi
    I have different properties file which I want to use as message bundle.
    Message.properties
    Help.properties
    When I specify this in faces-config.xml
    <application>
    <message-bundle>/Message</message-bundle>
    <message-bundle>/Help</message-bundle>
    </application>
    and now when I try to use that in my jsp page like this
    <f:loadBundle basename="/Message" var="message"/>
    <f:loadBundle basename="/Help" var="help"/>
    and access any messagestring from those files I can not excess either of them. But when I use only one of them it works fine.
    Am I doing something wrong or I can not do this thing at all??
    Thanks in advance.

    I only specify one properties file in the <application> tag. That one is used for system messages. I have other properties files for labels, and another for just standard app text, so in my faces-config.xml I have something like this:
    <application>
    <message-bundle>message</message-bundle>
    <locale-config>
    <default-locale>en</default-locale>
    </locale-config>
    </application>
    where my message.properties is used for system messages (validation, etc).
    I don't list the other property files there. I have two more that I use, labels_en.properties, and standard_en.properties. Labels are words that have a : at the end or a *: for required fields. Standard are just other words that I use in my application. So on every page that I have, I start out with the following header:
    <html>
    <f:view locale="en_US">
    <head>
    <f:loadBundle basename="label" var="label"/>
    <f:loadBundle basename="standard" var="standard"/>
    <title>
    .....

  • Message bundle Please help !

    Hey Im trying to make the message bundle
      <application>
            <message-bundle>webadmin.MyErrors</message-bundle>
        </application>I would like to make another file "MyErrors2 and have it switch based on a variable in the controller.. is that possible?

    You might be able to do it using the fact that ResourceBundles may be actual classes; i.e. they do not have to be properties files.
    But, I am inclined to ask what is the problem you are trying to solve? I suspect you may be down the wrong path. Be broad in your description of the problem.

  • Showing application message with different languages...

    Hi guys,
    i've a question for you.
    I'm trying to add to my jsf application a new language.
    I've added a resource bundle and everythings it's ok.
    My question is:
    if in my bean i've
    if (rs.next()) {
                             FacesContext facesContext = FacesContext
                                       .getCurrentInstance();
                             facesContext.addMessage(null, new FacesMessage(
                                       FacesMessage.SEVERITY_ERROR,
                                       "Il laboratorio risulta essere gi� inserito",
                                       "Laboratorio esistente"));
                        }that print a message in a language,how can i this message in the other language(english,for example)?
    I have to put also application message into resource bundle?
    How can i retrieve them?
    Please help me...

    thanks very much,
    i've changed english as default in th locale but nothing!!!
    i retrieve only italian messages...
    can you help me to find the error?
    When i pass to english mode all outputText messages of application became in english,but application message of bean are in italian,i try to print locale and it is
    it
    Here is my code of my visit object,it is of session type
    package giu;
    import java.io.Serializable;
    import java.sql.Connection;
    import java.sql.Statement;
    import java.util.*;
    import javax.faces.application.Application;
    import javax.faces.context.FacesContext;
    import javax.faces.model.SelectItem;
    import javax.servlet.http.HttpSessionBindingEvent;
    import javax.servlet.http.HttpSessionBindingListener;
    import javax.sql.DataSource;
    public class Visit implements HttpSessionBindingListener {
         private static final long serialVersionUID = 1L;
          * @uml.property name="user"
          * @uml.associationEnd
         private User user;
          * @uml.property name="localeItems"
         private boolean loggedIn;
         private List localeItems;
         public static Connection conn;
          * @uml.property name="authenticationBean"
          * @uml.associationEnd
         private AuthenticationBean authenticationBean;
         public Visit() {
          * @return Returns the user.
          * @uml.property name="user"
         public User getUser() {
              return user;
          * @param user
          *            The user to set.
          * @uml.property name="user"
         public void setUser(User user) {
              this.user = user;
         public boolean getLoggedIn() {
              return loggedIn;
          * @param user
          *            The user to set.
          * @uml.property name="user"
         public void setLoggedIn(boolean loggedIn) {
              this.loggedIn = loggedIn;
          * @return Returns the authenticationBean.
          * @uml.property name="authenticationBean"
         public AuthenticationBean getAuthenticationBean() {
              return authenticationBean;
          * @param authenticationBean
          *            The authenticationBean to set.
          * @uml.property name="authenticationBean"
         public void setAuthenticationBean(AuthenticationBean authenticationBean) {
              this.authenticationBean = authenticationBean;
         public List getSupportedtLocaleItems()
             if (localeItems == null)
               localeItems = new ArrayList();
               Application app = FacesContext.getCurrentInstance().getApplication();
               for (Iterator i = app.getSupportedLocales(); i.hasNext(); )
                 Locale locale = (Locale)i.next();
                 SelectItem item = new SelectItem(locale.toString(), locale.getDisplayName());
                 localeItems.add(item);
               if (localeItems.size() == 0)
                 Locale defaultLocale = app.getDefaultLocale();
                 localeItems.add(new SelectItem(defaultLocale.toString(), defaultLocale.getDisplayName()));
             return localeItems;
         public String getLocale()
             return FacesContext.getCurrentInstance().getViewRoot().getLocale().toString();
           public void setLocale(String locale)
             FacesContext.getCurrentInstance().getViewRoot().setLocale(new Locale(locale));
           }and this is the header of my jsf pages
    <h:selectOneListbox id="languageSelect" size="1" styleClass="language-select" value="#{visit.locale}">
              <f:selectItems value="#{visit.supportedtLocaleItems}"/>
            </h:selectOneListbox>
            <h:commandButton value="Go!" styleClass="language-select-button"/>and this is my web.xml
    <application>
      <message-bundle>microarray.bundle.messageResource</message-bundle>
      <locale-config>
       <default-locale>it</default-locale>
       <supported-locale>it</supported-locale>
       <supported-locale>en</supported-locale>
      </locale-config>
    </application>can someone help me?
    Thanks

  • F:loadBundle and message-bundle difference

    Hello I have one question:
    I have those lines in my faces-cofig:
    <locale-config>
    <default-locale>pl_PL</default-locale>
    <supported-locale>en_US</supported-locale>
    </locale-config>
    <message-bundle>pl.myCompany.crm.localization.application</message-bundle>           
    and this line is in every jsp file that use messages properties:
    <f:loadBundle basename="pl.myCompany.crm.localization.application" var="messages" />
    my questin is:
    Is there a possiblity to define only <message-bundle> in faces-config.xml and use properties in jsp files without defining f:loadBundle.
    I know that I can remove the message-bundle from faces-config .xml and everything works fine but in that case I have path to my resources file in almost evry jsp file in my app and this path could be changed in the future.
    Regards
    Tom

    Another question : how can I get the current Locale
    of the session context ?UIViewRoot#getLocale()
    Resource bundle is stored as a request scope variable of Map type.

  • Locale. Can't get it to load Message Bundle

    Have specified two properties files
    default en, supported es in faces.config.xml.
       <application>
         <locale-config>
           <default-locale>en</default-locale>
           <supported-locale>es</supported-locale>
         </locale-config>
       </application>Using IE7. Added es-ES as supported language (at top of list). Tools>IE Options>Languages.
    No luck
    Tried to force issue by setting locale in <f:view locale="es">
    Still not picking up the properies.messages.es file.
    Stays at default properties.messages
    I have used the following tag
    <f:loadBundle basename="com.apress.jsf.messages" var="msgs">
    Tags appear in this sequence in page:
    <f:view locale="es">
    <f:loadBundle basename="com.apress.jsf.messages" var="msgs" />
    Is this the problem?
    Or is this broken in JSF

    Have also tried removing loadbundle and modifying faces.config.xml
       <application>
         <resource-bundle>
           <base-name>com.apress.jsf.messages</base-name>
           <var>msgs</var>
         </resource-bundle>
       </application>Even when view specified es, still not working..
    Once thing I've noticed about IE language support is it shows as es-ES.
    Does my properties.messages file have to have a .es-ES suffix instead of just es?

  • Message bundles accessed from JSF and JSP pages

    Hello, everybody!
    I'm developing a localized JSF application. It is working pretty well until now.
    These are my message files:
    mensagens.properties
    mensagens_en_US.propertiesThis is how they're configured in faces-config.xml:
    <application>
        <resource-bundle>
            <base-name>br.urca.www.biblioteca.web.mensagens</base-name>
            <var>msg</var>
        </resource-bundle>
    </application>And this is how I access the messages in a page:
    <h:outputText value="#{msg.titulo}" />Nothing new until now. But now there was a need for me to have a raw jsp page in
    my web application. This page is displaying ok but I also need to access the
    message bundles as I'm able to access in the normal jsp with the JSF components.
    As you should know I can't use something like the above code with an +<h:outputText>+
    to access the messages because this is a JSF component and I'll not be able to use
    JSF components with this raw jsp page.
    So, my question is: how do I access my localized messages from a raw jsp page? I
    suppose there should be a way to do this, but unfortunately I started programming
    to the web world in Java with JSF, not JSP, so I don't know how to do this with
    JSP.
    Thank you very much.
    Marcos

    BalusC wrote:
    Just include [jstl-1.2.jar|https://maven-repository.dev.java.net/repository/jstl/jars/] in your classpath and define the fmt taglib in your JSP. Nothing more is needed.
    Hello, BalusC. Thank you for your help. We're almost there. After I have included the jstl-1.2.jar you provided me I can use the fmt tag and access message bundles from my raw jsp page (even though I had to provide other message bundles instead of the ones that I use in the other jsf pages, but it's better than nothing).
    Now there just on problem to be fixed. The jsp page is not aware when I change the locale of my application. I change this locale in a jsf page.
    I have this component:
    <h:selectOneMenu value="#{pesquisaAcervo.idiomaAplicacao}"
        valueChangeListener="# {pesquisaAcervo.idiomaAplicacaoMudado}" onchange="submit();">
        <f:selectItems value="#{pesquisaAcervo.idiomasAplicacao}" />
    </h:selectOneMenu>that calls this event in my backing bean class:
    public void idiomaAplicacaoMudado(ValueChangeEvent e)
        fIdiomaAplicacao.liberarItens();
        Idioma idioma = Idioma.deString(e.getNewValue().toString());
        // This line is for JSF
        FacesContext.getCurrentInstance().getViewRoot().setLocale(idioma.localidade());
        // This line is for Tiles
        FacesContext.getCurrentInstance().getExternalContext().getSessionMap().
            put(org.apache.tiles.locale.impl.DefaultLocaleResolver.LOCALE_KEY, idioma.localidade());
    }So, do I have to include another line in the idiomaAplicacaoMudado event above in order for the jsp page load the correct resource bundle? Or what else do I have to do?
    Thank you.
    Marcos

  • Message Bundle class not found

    Hello,
    i'm using JDev 10.1.3.3, and creating ADF BC application. When i've created the jspx page, went to it's Page Definition, and in Structure editor tried to add the Message Bundle file to this page - selected the "Generate Resource Bundle" from the context menu - i'm getting error "Class ...app_XXXPageDefMsgBundle not found" .
    Other pages in application got the same error.
    How can i solve this problem?

    And in the same time, Message Bundle classes for Entity Objects (XXXRowImplMsgBundle.java) are generating well, without any errors.

  • Localized Data Model Message Bundle

    When you use the Validations in the Entity Objects of a data model and you place text for the text, errors, etc...it creates a MsgBundle for that class. Then for other languages you can create additional message bundle (e.g. MsgBundle_it, for italian) files for additional languages.
    My question is how does the data model layer find the locale for the user? So when it issues a data model validation error, how does it know to use the italian version instead of the default, english one?
    Also, I should add that I don't have access to the FacesContext and my Data Model project cannot be dependant on the ViewController object. So I cannot get the locale in the same fashion that I'm doing for my applications (i.e. get translated text for adf faces messages).
    Message was edited by:
    Kerri

    Hi Heri,
    the system behavior is correct. The account in company code consists of three entity types:
    1) COA - Chart of Accounts (Type 3)
    2) ACCOUNT - Account (A-Segment, related to ECC table SKA1, Type 1)
    3) ACCCCDET - Account in Company Code (B-Segment, releated to ECC table SKB1, Type 1).
    3) includes 1) and 2) whereas 2) includes 1). If you grant authorization only for 3) but not for 1) and 2), you cannot do anything.
    Best regards
    Michael

  • Message-bundle

    Hello,
    I have declared a message-bundle in my faces-config.xml :
    <message-bundle>resource.messages</message-bundle>But if I want to use this one in my JSP file, I have to declare the following tag :
    <f:loadbundle basename="resource.messages" var="bundle" />Isn't it possible to use the bundle declared in the faces-config.xml file without declaring a f:loadbundle tag in my JSP file ?
    So, is it possible to declare the message-bundle in the faces-config.xml as :
    <message-bundle id="bundle">resource.messages</message-bundle>...and use the #{bundle.key} in the JSP file ?
    Could someone help me please ?
    Thanks in advance.
    bgOnline

    I don't think you can automatically load message bundles into a JSP page without defining it with loadBundle.
    As for localization, JSF allows you to specify a resource bundle in your faces-config.xml file. This will allow JSF to load the appropriate message bundles defined by the users browser. You still have to include it with loadBundle if you want to access it via JSP. JSF also allows you to mess with these resource bundles programatically.
    Here's an example of the entry in your faces-config.xml file.
    <faces-config>
         <application>
              <locale-config>
                   <default-locale>en</default-locale>
                   <supported-locale>de</supported-locale>
              </locale-config>
              <message-bundle>
                   com.facesite.resource.MessageResources
              </message-bundle>
         </application>
    </faces-config>This will tell JSF that MessageResources.properties is the en (English) locale and to load this by default but it also tells JSF that you have a MessageResources_de.properties file that supports the German language which would be specified by the browser.
    Loading it into your JSP.
    <f:loadBundle basename="com.facesite.resource.MessageResources"  var="msg"/>The MessageResources.properties file is in the standard java.util.Properties format.

  • Message bundle always loading default bundle???

    I have propertly created message bundle properties file. But I have problem in situation when I use example:
    <h:commandLink value="#{bundle.sLogout}" styleClass="HeaderLoginText"
    action="#{page.logout}" rendered="#{page.logged}"/>
    in this case my application always first show values from default properties file, example from messages.properties. But this was happend only then I start page for first time, then I change language, example click on button which set viewRoot on some other language, application shows correct values.
    What can be problem?
    Thanks for any sugestion!

    I found a solution,
    I hope there is a better one,
    What i did is a got the source for ADF faces found the XML file where all the msgs are located (MessageBundle.xrts). Then using a tool that comes with the source files XRTSMakeBundle, I compiled the XML file, and it created java files with all the msgs. So I compiled them and replaced the classes in the ADF faces api jar.
    this seems like a long work around, in JSF RI, all you have to do is extend the key in the resource bundle and poof it works, I couldn't get that working here.
    This works, seems like a lot of work for a simple task!!!
    any other solutions out there????
    I am considering not to use ADF faces, i think i will use my faces with jsf-comp client java script, as that was one of the reason i wanted to use ADF faces.

  • Put several message-bundle in faces-config.xml

    Hello,
    I want to put several message bundle in faces-config.xml.
    How can I do that?
    I tried the following but it didn't worked
    <application>
         <locale-config>     
              <default-locale>fr</default-locale>
         </locale-config>
         <message-bundle>
              messages.Messages_fr
         </message-bundle>
         <message-bundle>
              messages.Messages_en
         </message-bundle>
    </application>

    the system will get automatically the right file depending on the Locale object , so you do not have to mention each file in the faces-config.xml
    <locale-config>
    <default-locale>fr</default-locale>
    <supported-locale>en</supported-locale>
    the supported locale is used by JSF when readind the HTTP header and depending on the language, it will choose the right mesages bundle
    The best way to process is to bind the locale property of the tag <f:view locale=#{Bean.locale}> and to change it dynamically (see class Locale in the sun API)

  • Problem with Message bundle using more than one project

    Hi:
    I'm not sure about if i'm doing something wrong or maybe could be a bug in JDeveloper 9.0.2....
    I have three projects: A Project_A with BC4J packages (controlling BC4J entitties, views and AM's. In order words, only controlling the business rules side); a Project_B with a JClient programs using the AM's defined in Project_A and; a Project_C with a JSP_UIX using the AM's defined in Project_A.
    Everything works fine....until i note Message bundle is not working in Project_B and Project_C (not show my customizing message errors), only works fine in Project_A (using the AM tester because i don't control the client side here).
    How can i solve the problem?
    Regards.
    Marco

    I have the same project structure.
    My purpose is to have a different message bundle for JClient app and Struts/ADF app.
    When I register following customized message bundle in the common model project:
    public class CustomBC4JExceptionBundle extends ListResourceBundle {
    private static final Object[][] sMessageStrings = new String[][] {
    { CSMessageBundle.EXC_VAL_ATTR_MANDATORY, "This field is required" },
    protected Object[][] getContents() {
    return sMessageStrings;
    I get the message in both JClient and Struts app.
    But when I register that bundle in the 2 "client" projects and remove this custom bundle from my model project.
    I get the original message in my Struts app and not the message above.
    Question howto set up a different customized bundle for JClient project and Web project based on same model project in same application?
    Thanks
    Fred

  • Generator Locales and Entity Message Bundles

    I'm using 7 different languages within my application and have set the Internationalization entries within the JHeadstart Application Definition Editor to use a propertyFile and I have supplied all the relevant generator locales. That is all working fine. My confusion now lies with the generation of MsgBundles when creating validation rules on an entity attribute. On doing that a EntityImplMsgBundle java class is created but only for the default locale.
    1. Is there an easy way to generate the different localised entity MsgBundles
    2. better still, how can I change the entity validation to use my JHeadstart generarted property files rather than a MsgBundle java class ? I thought I may be able to copy the rule name and message over to my properties file and then delete the MsgBundle but I can't seem to delete the MsgBundle
    Many thanks for your help. Cheers,
    Brent

    Brent,
    1. No, you have to manually create those files
    2. Not possible either, even if you do not use declarative validation but do it in code and throw a JboException, the message bundle must be a java class.
    I believe that in JDev 11, you can have centralized resource bundles, like in JHeadstart.
    You might try the JDev forum for better alternatives though, since these are really ADF BC specific issues.
    Steven Davelaar,
    JHeadstart team,

  • When do you need to register the message bundle in the faces-config

    hello
    i have applied two examples to localize messages, label, title by creating message.properties file and utilizing the f:loadbundle component the EL expression. It works like a charm without having to register anything, I have only registered the locale, but not the bundle
    also , i have used a programmatic approach
    FacesContext fc = FacesContext.getCurrentInstance();
    ResourceBundle msg = ResourceBundle.getBundle("message",fc.getViewRoot().getLocale());
    fc.addMessage(FacesMessage.SEVERITY_FATAL.toString(),new FacesMessage(msg.getString("ok")));
    which also worked without registering the message bundle!!
    although many article i read ask to register the message bundle.
    Another thing is that in Oracle Jdeveloper 10g for FORMS and PL/SQL Developers states that the message file needs to be located in \resource subdirectory
    and using getBundle (resources.message) to get it. In fact i kept getting errors indicating that the base bundle cannot be read until i located the file in the ViewContoller directory itself (and that is why i reference it with getBundle("message") rather than resources.message as indicated in the book.
    appreciate your response
    ammar sajdi
    amman - jordan

    Hi,
    Your question is not very clear. But let get through some various guideline.
    <f:loadBundle/> is horribly buggy and was all but removed from the specification. As a tag, it gets only evaluated during the render view phase, meaning that if you have EL expression referring the loadBundle's var during another phase, it's going to fail. The most common case is during validation with overridden messages.
    About the programmatic access, the problem is that you're linking your application to a specific bundle at code level. Meaning that you're preventing it to be reused in a different context, while the following get the most application local bundle name (faces-config.xml's message-bundle property)
    Resourcebundle.getBundle(FacesContext.getApplication().getMessageBundle())Registration is also the only way to override the default conversion / validation messages.
    For JSF 1.1 (10g), those are your option. However, if you're using JSF 1.2 (11g), you can also register resource bundles in the faces-config file, you then register the bundle and the var associated to it, removing the need of f:loadBundle and fixing the non render phase issues. furthermore, the code version is also simplified to:
    FacesContext context = FacesContext.getCurrentInstance();
    ResourceBundle bundle = context.getApplication().getResourceBundle(context, "varName");
    bundle.getString("myKey");You other part about \resource I never heard of nor cared for. You can place the bundle where you like on the classpath.
    Regards,
    ~ Simon

Maybe you are looking for

  • How to have icons with a WM (without installing a whole DE)

    Hi! I was wondering if it was possible to have desktop icons with TWM/FluxBox/IceWM alone, without installing a desktop environment. As far as I know, file managers do this in DEs but then simply installing a file manager while running a WM doesn't p

  • With the new update, I can't figure out how to merge duplicate "Faces" files together, so I end up with one location per face.

    With the newest update, I can't figure out how to merge duplicate files in "Faces" (iPhoto).  I have more than one file going for a face, and use to be able to click and drag them into merging.  Can't seem to do it now.  Can anyone please help?  Than

  • Building Inbound IDoc

    I am creating an inbound IDoc using ABAP.  I have successfully created the IDoc, but I am getting errors, I believe because of the format of the Data Records in the IDoc.  Here are the fields for the Data Records: MANDT - using sy-mandt DOCNUM SEGNUM

  • Doubt in transfering integration scenario from IR

    Hi guys, I'm trying to transfer my IS from IR. I have created communication channel template in IR. I plan to follow the configuration wizard in ID. I have assigned business systems in the objects tab. I want to create my communication channel based

  • HELP Needed: ICS Updating

    I tried all I can to update my K1 to ICS. I was able to download the drivers and followed the directions but I still keep on getting this error message. Please help me. I know I am late in this game but appreciate any advice on how to get past this e