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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T12:41:31+00:00 2026-05-16T12:41:31+00:00

I am interested in creating a dynamic component in JSF. By that I mean

  • 0

I am interested in creating a dynamic component in JSF. By that I mean a component that looks and acts differently dependent on the variables it is passed.

Let’s take an easy example that actually works. A composite component (facelet) that hides/shows different parts of itself dependent on the data. In this case, it takes an attribute named “myBean”, which you may imagine having a “value” field and “type” field. The “type” field determines what component should be rendered.

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:jsp="http://java.sun.com/JSP/Page"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:c="http://java.sun.com/jsp/jstl/core"
      xmlns:cc="http://java.sun.com/jsf/composite">

    <cc:interface>
        <cc:attribute name="myBean" />
    </cc:interface>

    <cc:implementation>

        <!-- Small input field if type is "shorttext"  -->
        <h:inputText value="#{myBean.value}" rendered="#{myBean.type == 'shorttext'}" />

        <!-- Text area input field if type is "longtext"  -->
        <h:inputTextArea value="#{myBean.value}" rendered="#{myBean.type == 'longtext'}" />

    </cc:implementation>
</html>

While this works, it quickly becomes unwieldy. If I have twenty different types, I have them all specified in the same document and that clearly violates good design.

Instead, I would like to be able to replace the implementation with something like:

    <ui:include value="#{myBean.type}"/>

Which I understand is not possible, since ui:include occurs when building the component tree, and the the component is processed during the rendering phase.

Yet this must be a common problem. What is the best approach to achieve dynamic components? I am using JSF 2.0, if that makes a difference.

  • 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-16T12:41:31+00:00Added an answer on May 16, 2026 at 12:41 pm

    I don’t see better ways. XML is not an OO language. This is the best what you can get with XML. If you want to do it the OO way, then you should create a real component with a renderer.

    By the way, composite components was introduced in JSF 2.0 and are thus not available in JSF 1.x. So it doesn’t make much difference 😉

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

Sidebar

Related Questions

I am interested in creating a simple web application that will take in user
I'm interested in creating a plugin that does this simple task: Steps 1. User
I am interested in creating a web app that uses JSP , Servlets and
I am interested in creating my own mobile OS. I read that the existing
I'm interested in creating an iPhone app that can stream video from a central
I'm interested in creating a service that will receive a text message and based
I am interested in creating URL with ASP.Net MVC 3 that has a QuerySting
I'm interested in creating some web apps that simulate results based on data. For
I'm interested in creating a horizontal scroll view that snaps to the viewed item,
I'm interested in creating commands that are available from anywhere in my WPF application.

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.