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 9223175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:00:49+00:00 2026-06-18T04:00:49+00:00

I’m writing a custom component to show validation messages in popups, it works well

  • 0

I’m writing a custom component to show validation messages in popups, it works well but I have still a problem: I would like to display component labels instead of cliendIds in validation messages.

I already looked at this question and similars:

Removing the component Id from validation message when using message bundle in JSF

but I’m using jsf 1.1 and I get a compilation error if I try to set a value for attribute label or requiredMessage.
So I tried assigning a label to the component using an <outputLabel />:

<h:outputLabel for="phone" value="Phone number" />
<h:inputText id="phone" required="true" value="#{backingBean.phoneNumber}" />

with no effect.

Is there a simple way in jsf 1.1 to make label appear in validation messages instead of client id?
If not, how could I, given a component, retrieve its related label component to do the work in Java code?

Thanks.

  • 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-06-18T04:00:50+00:00Added an answer on June 18, 2026 at 4:00 am

    I found a solution which does not require to modify existing JSF code.

    1. make my component renderer extend Tomahawk’s HtmlMessagesRenderer, which is capable of use a component label instead of its id
    2. use HtmlMessagesRenderer#findInputId to retrieve the Id of the component with messages
    3. use HtmlMessagesRenderer#findInputLabel to retrieve the Label of the component with messages
    4. replace component Id with component Label in the message.

    Below is an excerpt from the code of my component Render encodeBegin method, in which I made two separated loops, the first for component messages the other for global messages.

    Note that FacesContext#getClientIdsWithMessages returns also null, which is considered the clientId for global messages.

    Note that, because the component itself manages to retrieve and use the component label, if exists; this solution it only need to place a <myCustomMessages /> tag in JSF page code.

    public void encodeBegin(FacesContext context, UIComponent component) throws IOException {
    // ....
    
    // replace id with label in messages for components
            Iterator<String> clientIdsWithMessages=context.getClientIdsWithMessages();
            while(clientIdsWithMessages.hasNext()){
                String clientIdWithMessages=clientIdsWithMessages.next();
                if(clientIdWithMessages!=null){
                    Iterator<FacesMessage> componentMessages=context.getMessages(clientIdWithMessages);
                    while(componentMessages.hasNext()){
                        String stringMessage=componentMessages.next().getDetail();
                        try{
                            String inputId =findInputId(context, clientIdWithMessages);
                            String inputLabel = findInputLabel(context, clientIdWithMessages);
                            if(inputId!=null && inputLabel!=null)
                                stringMessage=stringMessage.replace(inputId, inputLabel);
                        } catch(Exception e){
                            // do nothing in this catch, just let the message be rendered with the componentId instead of a label                       }
                        msgBuilder.append(stringMessage);
                        msgBuilder.append("<br />");
                    }
                }
            }
    
    
            // process global messages
            Iterator<FacesMessage> globalMessages=context.getMessages(null);
            while(globalMessages.hasNext()){
                FacesMessage message=globalMessages.next();
                msgBuilder.append(message.getDetail());
                msgBuilder.append("<br />");
            }
    // ...
    

    Here is a reference to HtmlMessagesRenderer#findInputLabel source code, to take a look on how it works.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small JavaScript validation script that validates inputs based on Regex. I
I have a French site that I want to parse, but am running into
This could be a duplicate question, but I have no idea what search terms
I have been unable to fix a problem with Java Unicode and encoding. The
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
this is what i have right now Drawing an RSS feed into the php,

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.