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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:28:05+00:00 2026-05-23T05:28:05+00:00

I asked this question and although the answer directly satisfied my needs I am

  • 0

I asked this question and although the answer directly satisfied my needs I am left with a feeling that there has to a simpler solution for this specific problem.

I would like to have a composite component that accepts a list of items (The type of the items agreed upon so the members can be used freely within the composite component)

The CC (composite component) display the list of items and allows for addition and subtraction of items.

I would like to do this in the most simple and efficient manner.

To illustrate the problem, an example:

enter image description here

The definition should be rather simple (unless of course, its not 🙂 ):

<special:dynamicFieldList value="#{bean.fieldList} />

The most abstract form of a Field object would be:

public class Field{
 String uuid;
 String value;
}

I guess that’s it.
How would you implement this in a simple manner?

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-23T05:28:05+00:00Added an answer on May 23, 2026 at 5:28 am

    I’d use a <h:dataTable> in a composite component with a backing UIComponent which you can bind by componentType attribute of the <composite:interface>. In the backing UIComponent you can then maintain the DataModel and define the actions.

    dynamicFieldList.xhtml

    <ui:composition
        xmlns:f="http://java.sun.com/jsf/core"
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:ui="http://java.sun.com/jsf/facelets"
        xmlns:cc="http://java.sun.com/jsf/composite"
    >
        <cc:interface componentType="dynamicFieldList">
            <cc:attribute name="value" type="java.util.List" required="true" />
        </cc:interface>
        <cc:implementation>
            <h:dataTable id="table" binding="#{cc.table}" value="#{cc.attrs.value}" var="field">
                <h:column><h:outputLabel value="#{field.label}" /></h:column>
                <h:column><h:inputText value="#{field.value}" /></h:column>
                <h:column><h:commandButton value="remove" action="#{cc.remove}" /></h:column>
            </h:dataTable>
            <h:commandButton value="add" action="#{cc.add}" />
        </cc:implementation>
    </ui:composition>
    

    (the <h:inputText> can if necessary be your composite field component)

    com.example.DynamicFieldList

    @FacesComponent(value="dynamicFieldList") // To be specified in componentType attribute.
    @SuppressWarnings({"rawtypes", "unchecked"}) // We don't care about the actual model item type anyway.
    public class DynamicFieldList extends UINamingContainer {
    
        private UIData table;
    
        public void add() {
            ((List) getAttributes().get("value")).add(new Field("somelabel"));
        }
    
        public void remove() {
            ((List) getAttributes().get("value")).remove(table.getRowData());
        }
    
        public UIData getTable() {
            return table;
        }
    
        public void setTable(UIData table) {
            this.table = table;
        }
    
    }
    

    Use it as follows:

    <h:form>
        <my:dynamicFieldList value="#{bean.fields}" />
    </h:form>
    

    with just this

    @ManagedBean
    @ViewScoped
    public class Bean implements Serializable {
    
        private List<Field> fields;
    
        public Bean() {
            fields = new ArrayList<>();
        }
    
        public List<Field> getFields() {
            return fields;
        }
    
    }
    

    and

    public class Field implements Serializable {
    
        private String label;
        private String value;
    
        public Field() {
            //
        }
    
        public Field(String label) {
            this.label = label;
        }
    
        public String getLabel() {
            return label;
        }
    
        public void setLabel(String label) {
            this.label = label;
        }
    
        public String getValue() {
            return value;
        }
    
        public void setValue(String value) {
            this.value = value;
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can't find any useful answer for this question, although it has been asked
I know that different versions of this question has been asked in the past,
I asked this question before and got a great working answer. what is the
This is a question that I was asked on a job interview some time
This is related to an earlier question I asked, where the answer was: If
This user asked a similar question but had no viable solution in the answers,
Although this question have been asked and answered before, including on this website, I
It looks like this question has been asked before, here and in other places
I don't think this question has asked yet (most similar questions are about extracting
I've asked this question before with no real answer. Can anybody help? I'm profiling

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.