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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:30:53+00:00 2026-05-26T12:30:53+00:00

I want to use simplified select one tag, which would generate select items list

  • 0

I want to use simplified select one tag, which would generate select items list for enums automatically. So, the result would be:

<s:enumSelectOneMenu value="#{myBean.enumValue}"/>

So, inside the component I can get the enum type and get all enum values using reflection. So, basically I need to override the only one method validateValue(..) from UiSelectOne and put the UiSelectItems list as the child there (in the same manner as it is done in Tomahawk, see SelectOneLanguage component).

But what else should be done? I need to describe tag attributes in my own taglib.xml but jsf-impl.jar does not contain facelets xml – only taglib file, so I cannot simply copy everything from there. Also, if I statically describe tag in my taglib.xml – I will have to update it manually on each new version of JSF, which is not good at all. So, which is the best way to extend the component in JSF and avoid lots of manual copy-paste work?

P.s. I’m using JSF 2.0, but composite-facelets way is not suitable for me as it produces lots of problems as composite element is wrapped by NamingContainer component. So I need only “oldschool” way to create custom components.

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-05-26T12:30:53+00:00Added an answer on May 26, 2026 at 12:30 pm

    One of best (but not the easiest) way to extend some JSF components and add the behaviour while not loosing attributes is using PrimeFaces JSF plugin. Some information about it is here: http://code.google.com/p/primefaces/wiki/BuildingFromSource. Though it has some hardcoded values (name of facelets taglib and way to output directory, where generated taglib is put) and can be changed and rebuilt locally
    Here is the example of PF jsf plugin

       <!-- Primefaces maven plugin -->
                <plugin>
                    <groupId>org.primefaces</groupId>
                    <artifactId>maven-jsf-plugin</artifactId>
                    <version>1.2.1-SNAPSHOT</version>
                    <executions>
                        <execution>
                            <id>generate-ui</id>
                            <phase>generate-sources</phase>
                            <configuration>
                                <uri>http://www.mycompany.com/tags</uri>
                                <name>rstk-tag</name>
                                <jsfVersion>2</jsfVersion>
                                <templatesDir>src/main/java-templates</templatesDir>
                                <componentConfigsDir>src/main/resources-maven-jsf/ui</componentConfigsDir>
                                <!-- <standardFacesConfig>src/main/resources-maven-jsf/standard-faces-config.xml</standardFacesConfig> -->
    <!-- These are new attributes added manually to plugin source code! -->
                                <standardFaceletsTaglib>src/main/resources-maven-jsf/standard-facelets-taglib.xml</standardFaceletsTaglib>
                                <faceletsOutputDirectory>target/generated-sources/maven-jsf-plugin/META-INF</faceletsOutputDirectory>
                            </configuration>
                            <goals>
                                <goal>generate-components</goal>
                                <goal>generate-facelets-taglib</goal>
                            </goals>
                        </execution>                    
                    </executions>
                </plugin>
    

    After this the following metadata xml can be used for generation:

     <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE component SYSTEM "../misc/component.dtd" [
    <!ENTITY standard_uicomponent_attributes        SYSTEM "../entities/standard_uicomponent_attributes.xml">
    <!ENTITY output_component_attributes            SYSTEM "../entities/output_component_attributes.xml">
    <!ENTITY input_component_attributes             SYSTEM "../entities/input_component_attributes.xml">
    ]>
    <component>
        <tag>enumSelectOneMenu</tag>
        <tagClass>com.rstk.kasko.component.EnumSelectOneMenuTag</tagClass>
        <componentClass>com.rstk.kasko.component.EnumSelectOneMenu</componentClass>
        <componentType>com.rstk.kasko.component.EnumSelectOneMenu</componentType>
        <componentFamily>javax.faces.SelectOne</componentFamily>
        <rendererType>javax.faces.Menu</rendererType>
        <parent>javax.faces.component.html.HtmlSelectOneMenu</parent>
        <description>The tag for select one menu, which renders the enumerations list. No children necessary for this</description>
        <attributes>
            &input_component_attributes;
        </attributes>
    
    </component>
    

    This together with EnumSelectOneMenuTemplate.java (the template, which is inserted into generated component code) allows to generate:

    1. taglib.xml with ALL standard html select one menu attributes
    2. The component class, which contains custom logics for rendering clidhren:
    
        public class EnumSelectOneMenu extends HtmlSelectOneMenu {
        ... // Generated staff here
        public boolean getRendersChildren() {
                return true;
            }
    
            /**
             * @see javax.faces.component.UIComponentBase#encodeBegin(javax.faces.context.FacesContext)
             */
            @Override
            public void encodeBegin(FacesContext context) throws IOException {
                super.encodeBegin(context);
    
                if (context.isPostback()) {
                    return;
                }
    
                UISelectItems selectItems = new UISelectItems();
                try {
                    selectItems.setValue(getEnumValuesList());
                } catch (Exception e) {
                    log.error("Failed to create enum list", e);
                }
                getChildren().add(selectItems);
    
            }
    
            /**
             * Creates the list of select items of format [ENUM, enum.getDisplay()] 
             * @return
             */
            private List getEnumValuesList() {
                List result = new ArrayList();
                ValueExpression ve = getValueExpression("value");
                Class enumClass = ve.getType(getFacesContext().getELContext());
                Method method = ReflectionUtils.findMethod(enumClass, "getDisplay", null);
                for (Object e : ve.getType(getFacesContext().getELContext()).getEnumConstants()) {
                    result.add(new SelectItem(e, (String) ReflectionUtils.invokeMethod(method, e)));
                }
                return result;
            }
        }
    

    Then this component can be used as simple JSF select one component (with ALL standard attributes), but does not require select items to be added each time and allows any other childre be placed there:

    <s:enumSelectOneMenu value="#{polis.osMatrixType}" id="registryType">
            <p:ajax listener="#{osagoPolisBean.rollOsagoEndDate}" update="osagoUsagePeriod" process="osagoTable" event="change"/>                               
    </s:enumSelectOneMenu>  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Below is my stored procedure. I want use stored procedure select all row of
I have a Stored Procedure which executes some dynamic SQL. I want to use
I want to add Pagination to one of my views using MvcPager3. This would
I have a MySQL query in which I want to include a list of
Simplified Question: I want to use the following to build an html table dynamically.
I want use groovy findAll with my param to filtering closure filterClosure = {
i want use some data from a website with web service. i have a
I have a transaction log file in CSV format that I want use to
I want to use the mouse scrollwheel in my OpenGL GLUT program to zoom
I want to use Powershell to write some utilities, leveraging our own .NET components

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.