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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:42:32+00:00 2026-05-16T06:42:32+00:00

Can I add JSF components dynamically? I need to have a form with a

  • 0

Can I add JSF components dynamically? I need to have a form with a button which should add one <h:inputText> to the form. Is this possible?

I know this should be possible in JavaScript somehow. Do anybody know how to do this in JSF? I think the major problem is how do I get or set values of new inputs via #{value}.

  • 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-16T06:42:32+00:00Added an answer on May 16, 2026 at 6:42 am

    Use an iterating component like <h:dataTable> or <ui:repeat> to display a dynamically sized List of entities. Make the bean @ViewScoped to ensure that the list is remembered across postbacks on the same view instead of recreated over and over.

    Kickoff example with <h:dataTable> (when using <ui:repeat> simply replace <h:dataTable> by <ui:repeat>, and <h:column> by e.g. <li> or <div>):

    <h:form>
        <h:dataTable value="#{bean.items}" var="item">
            <h:column><h:inputText value="#{item.value}" /></h:column>
            <h:column><h:commandButton value="remove" action="#{bean.remove(item)}" /></h:column>
        </h:dataTable>
        <h:commandButton value="add" action="#{bean.add}" />
        <h:commandButton value="save" action="#{bean.save}" />
    </h:form>
    

    Managed bean:

    @Named
    @ViewScoped
    public class Bean {
    
        private List<Item> items;
    
        @PostConstruct
        public void init() {
            items = new ArrayList<>();
        }
    
        public void add() {
            items.add(new Item());
        }
    
        public void remove(Item item) {
            items.remove(item);
        }
    
        public void save() {
            System.out.println("items: " + items);
        }
    
        public List<Item> getItems() {
            return items;
        }
    
    }
    

    Model:

    public class Item {
    
        private String value;
    
        public String getValue() {
            return value;
        }
    
        public void setValue(String value) {
            this.value = value;
        }
    
        public String toString() {
            return String.format("Item[value=%s]", value);
        }
    
    }
    

    See also:

    • Recommended JSF 2.0 CRUD frameworks
    • How to create dynamic JSF form fields
    • How to implement a dynamic list with a JSF 2.0 Composite Component?
    • How to choose the right bean scope?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say that I have an application which manages users. You can add new
Can we add multiple rows in the database table from one JSF page in
I am doing this in JSF 2.0. I have implemented add and view pages
I can add and remove the last line in my dynamic form and calculate
I wrote library which can add and update objects in salesforce. I use beatbox
I know one can add event listener for window.error. However when working with Iframes,
Can i somehow add JSF tags to my JSF component renderer class? I'm trying
I have a couple of probably common thoughts on JavaServer Faces (JSF) which I
I have a customer who created an Oracle ADF/JSF 1.1 application. On one of
Richfaces 3.3.3, Jsf 1.2: I have a a4j:form that uses some simple validation, mainly

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.