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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T11:35:24+00:00 2026-06-07T11:35:24+00:00

I am trying to write a renderer which would process the placeholder attribute on

  • 0

I am trying to write a renderer which would process the placeholder attribute on an <h:inputText> component.
I headed to this path after reading JSF 2.0 strips out needed HTML5 attributes and it seems correct. Here’s my custom renderer

public class InputRenderer extends com.sun.faces.renderkit.html_basic.TextRenderer{

    @Override
    public void encodeBegin(FacesContext context, UIComponent component) 
    throws IOException {
        System.out.println("Rendering :"+component.getClientId());

        String placeholder = (String)component.getAttributes().get("placeholder");
        if(placeholder != null) { 
            ResponseWriter writer = context.getResponseWriter();
            writer.writeAttribute("placeholder", placeholder, "placeholder");
        }

        super.encodeBegin(context, component);

    }


    @Override
    public void decode(FacesContext context, UIComponent component) {
        super.decode(context, component);
    }

    @Override
    public void encodeEnd(FacesContext context, UIComponent component) 
    throws IOException {
        super.encodeEnd(context, component);
    }
}

And this renderer is registered in faces config as

 <render-kit>
    <renderer>
        <component-family>javax.faces.Input</component-family>
        <renderer-type>javax.faces.Text</renderer-type>
        <renderer-class>com.example.renderer.InputRenderer</renderer-class>
    </renderer>
</render-kit>

This gets registered fine, no issues there.

My intention is to process the placeholder attribute, insert it, and then delegate the processing to super. My above code doesn’t work because I’m inserting the attribute at a wrong place. It must be inserted after writer.startElement('input') has executed. However, the startElement must be happening somewhere in the super’s encodeBegin() method. So how do I insert a custom attribute (‘placeholder’ in this case) and then continue the execution flow?

NB: The above code does add a placeholder attribute but not to the input component that I intend to, It writes it to the parent of the Input (since I’m trying to write an attribute before the component itself is actually written in the stream, it applies the attribute to the current component)

  • 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-07T11:35:26+00:00Added an answer on June 7, 2026 at 11:35 am

    This is my way. I added placeholder and data-theme attributes. If you want to add more attributes, you should just add its name to attributes array.

    import javax.faces.component.UIComponent;
    import javax.faces.context.FacesContext;
    import javax.faces.context.ResponseWriter;
    
    import com.sun.faces.renderkit.html_basic.TextRenderer;
    
    public class InputRender extends TextRenderer {
    
        @Override
        protected void getEndTextToRender(FacesContext context,
                UIComponent component,
                String currentValue)
         throws java.io.IOException{
    
            String [] attributes = {"placeholder","data-theme"};
    
            ResponseWriter writer = context.getResponseWriter();
    
            for(String attribute : attributes)
            {
                String value = (String)component.getAttributes().get(attribute);
                if(value != null) {                             
                    writer.writeAttribute(attribute, value, attribute);
                }
            }
    
            super.getEndTextToRender(context, component, currentValue);
    
        }
    
    }
    

    You should add this to faces-config.xml file.

     <render-kit>
        <renderer>
            <component-family>javax.faces.Input</component-family>
            <renderer-type>javax.faces.Text</renderer-type>
            <renderer-class>your.package.InputRenderer</renderer-class>
        </renderer>
    </render-kit>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write a basic volume renderer which uses opengl, and cg
I m trying write code that after reset set up rrpmax as 3000. It
I'm trying to write the dagger '†' symbol to a HTML page which gets
Can i somehow add JSF tags to my JSF component renderer class? I'm trying
I'm trying to write an item renderer (in Flash Builder 4.6) purely in action
I'm trying to write a controller method that returns an ActionResult. In this method,
I am trying write a script where when a user clicks on a link,
I am trying write a function that generates simulated data but if the simulated
Trying to write app for service technicians that will display open service calls within
Trying to write a couple of functions that will encrypt or decrypt a file

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.