Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7507837
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:33:56+00:00 2026-05-29T22:33:56+00:00

BalusC provided a good answer to a question about how to set messages per

  • 0

BalusC provided a good answer to a question about how to set messages per composite component. Specifying different error messages for different composite components
The answer involved using per component resource bundles.

Ive applied this approach but when I use {0} in the message to specify the current component label as part of the message, the {0} is rendered as is in my error, rather than being resolved. Is this resolution of labels available when I use this approach? Or do I have to manually build up the error message in the composite component? e.g.

requiredMessage="#{cc.resourceBundleMap.requiredMessage} #{cc.attrs.prefix} #{cc.attrs.label}"

I guess the deeper question is how can I have parameterised message strings in my resource bundle? Will I need to build some kind of custom message resolver?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T22:33:57+00:00Added an answer on May 29, 2026 at 10:33 pm

    Unfortunately, the requiredMessage (and validatorMessage and converterMessage) attribues are not parameterizable by default. I think it would make little sense anyway as they are tied to a specific component in particular. A composite component does usually not contain a multiple of the same components. You would need to specify separate messages for every individual component.

    It’s in theory however possible to create a custom EL function which does the message formatting job. The method would look something like this:

    public static String format(String message, Object argument1, Object argument2) {
        return MessageFormat.format(message, argument1, argument2);
    }
    

    which is to be used something like this:

    requiredMessage="#{util:format(cc.resourceBundleMap.requiredMessage, cc.attrs.prefix, cc.attrs.label)}"
    

    The only disadvantage is that you can’t create EL functions which can take varargs. This is a limitation of the EL specification. So if you intend to be able to pass variable arguments, you’d need to create a separate EL function and a Java method for every possible amount of arguments needed.

    As a completely different alternative, you could create a custom Validator and attach it to the particular input component. You can even put the validator method straight in the “backing component” which is associated with the composite component by <cc:interface componentType>. If you remove the required attribute, then this validator will immediately be invoked where you’ve the freedom to compose messages the way you want.

    E.g.

    <h:inputText id="foo" validator="#{cc.validateFoo}" requiredMessage="#{cc.resourceBundleMap.requiredMessage}" />
    

    with

    public void validateFoo(FacesContext context, UIComponent component, Object value) {
        if (value == null || value.toString().trim().isEmpty()) {
            String requiredMessage = (String) component.getAttributes().get("requiredMessage");
            String prefix = (String) getAttributes().get("prefix");
            String label = (String) getAttributes().get("label");
            throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR,
                MessageFormat.format(requiredMessage, prefix, label), null));
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As suggested by BalusC as an answer to this question , I wanto to
Im new to JSF 2. My question is related to BalusC's answer to this
I have a JSF 2 composite component that employs some Ajax behavior. I want
I want someone to explain some points in BlausC's amazing answer in this question
I have this composite component: <cc:interface> <cc:attribute name=image_1 /> <cc:attribute name=image_2 /> <cc:attribute name=image_3
I followed the steps in BalusC's answer at JSF 2.0 File upload . The
Two days ago I wrote this question: How can I retrieve an object on
I am creating a custom component that is an image viewer for a given
I have a requirement to update the properties file based upon the input provided
two days ago i started using tomahawk ExtensionsFilter components im my jsf application. i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.