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

  • Home
  • SEARCH
  • 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 8138159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T11:24:21+00:00 2026-06-06T11:24:21+00:00

I’m trying to create a custom component to extend PrimeFaces. I have a simple

  • 0

I’m trying to create a custom component to extend PrimeFaces.

I have a simple component called textInput under the test namespace that simply calls the PrimeFaces textInput component and prints out the value passed to an attribute named fieldClass and the names of any attributes passed

if I pass fieldClass as a string:

<test:textInput id="foo" fieldClass="field-foo" />

this is the result

fieldClass = field-foo

[com.sun.faces.facelets.MARK_ID, fieldClass]

If I pass fieldClass as an expression

<ui:param name="bar" value="field-foo"/>
<test:textInput id="foo" fieldClass="#{bar}" />

fieldClass vanishes

fieldClass = NONE

[com.sun.faces.facelets.MARK_ID]

How do I actually get hold of the attributes passed to the component?

Classes used by the custom component follows:

test.components.ExtendInputTextRenderer

package test.components;

import java.util.Map;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
import javax.faces.render.FacesRenderer;
import org.primefaces.component.inputtext.*;

@FacesRenderer( 
     componentFamily=ExtendInputText.COMPONENT_FAMILY, 
     rendererType=ExtendInputTextRenderer.RENDERER_TYPE 
) 

public class ExtendInputTextRenderer extends InputTextRenderer {
     public static final String RENDERER_TYPE = "com.example.ExtendInputTextRenderer";

     @Override
     public void encodeEnd(FacesContext context, UIComponent component)
                throws java.io.IOException {
          ResponseWriter writer = context.getResponseWriter();
          Map attrs = component.getAttributes();
          String fieldClass = attrs.containsKey("fieldClass") ? (String) attrs.get("fieldClass").toString() : "NONE";
          writer.write("fieldClass = " + fieldClass + "<br/>");
          writer.write(attrs.keySet().toString() + "<br/>");
          super.encodeEnd(context, component);
     }
}

test.components.ExtendInputText

package test.components;

import javax.faces.component.FacesComponent;
import org.primefaces.component.inputtext.InputText;



@FacesComponent(ExtendInputText.COMPONENT_TYPE) 
public class ExtendInputText extends InputText { 
 
     public static final String COMPONENT_FAMILY = "com.example"; 
     public static final String COMPONENT_TYPE = "com.example.ExtendInputText"; 
 
     @Override 
     public String getFamily() { 
          return COMPONENT_FAMILY; 
     } 
 
     @Override 
     public String getRendererType() { 
          return ExtendInputTextRenderer.RENDERER_TYPE; 
     } 
}
  • 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-06T11:24:23+00:00Added an answer on June 6, 2026 at 11:24 am
    String fieldClass = attrs.containsKey("fieldClass") ? (String) attrs.get("fieldClass").toString() : "NONE";
    

    Your mistake is that you’re using containsKey() to check if the property has been specified.

    Here’s an extract from UIComponent#getAttributes() javadoc:

    getAttributes

    public abstract java.util.Map<java.lang.String,java.lang.Object> getAttributes()

    Return a mutable Map representing the attributes (and properties, see below) associated wth this UIComponent, keyed by attribute name (which must be a String). The returned implementation must support all of the standard and optional Map methods, plus support the following additional requirements:

    • The Map implementation must implement the java.io.Serializable interface.
    • Any attempt to add a null key or value must throw a NullPointerException.
    • Any attempt to add a key that is not a String must throw a ClassCastException.
    • If the attribute name specified as a key matches a property of this UIComponent‘s implementation class, the following methods will have special behavior:
      • containsKey() – Return false.
      • get() – If the property is readable, call the getter method and return the returned value (wrapping primitive values in their corresponding wrapper classes); otherwise throw IllegalArgumentException.
      • put() – If the property is writeable, call the setter method to set the corresponding value (unwrapping primitive values in their corresponding wrapper classes). If the property is not writeable, or an attempt is made to set a property of primitive type to null, throw IllegalArgumentException.
      • remove() – Throw IllegalArgumentException.

    Note that it thus always returns false for containsKey for component’s properties. That’s because dynamic properties are not stored in the attribute map, but instead in the component instance itself. They’re only resolved when calling get().

    You need to change the wrong line as follows:

    String fieldClass = (String) attrs.get("fieldClass");
    if (fieldClass == null) fieldClass = "NONE";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create an if statement in PHP that prevents a single post
Basically, what I'm trying to create is a page of div tags, each has
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am doing a simple coin flipping experiment for class that involves flipping a
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am trying to loop through a bunch of documents I have to put
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am trying to understand how to use SyndicationItem to display feed which is

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.