Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to create dynamic JSF form fields
    primarykey
    data
    text
    <p>I have found some similar questions like <a href="https://stackoverflow.com/questions/2370489/creating-dynamic-controls-in-jsf-managed-bean">this</a> one, however there are so many ways this can be done that it made me more confused.</p> <p>We are getting an <code>XML</code> file that we are reading. This <code>XML</code> contains information on some form fields that needs to be presented. </p> <p>So I created this custom <code>DynamicField.java</code> that has all the information we need:</p> <pre><code>public class DynamicField { private String label; // label of the field private String fieldKey; // some key to identify the field private String fieldValue; // the value of field private String type; // can be input,radio,selectbox etc // Getters + setters. } </code></pre> <p>So we have a <code>List&lt;DynamicField&gt;</code>.</p> <p>I want to iterate through this list and populate the form fields so it looks something like this:</p> <pre><code>&lt;h:dataTable value="#{dynamicFields}" var="field"&gt; &lt;my:someCustomComponent value="#{field}" /&gt; &lt;/h:dataTable&gt; </code></pre> <p>The <code>&lt;my:someCustomComponent&gt;</code> would then return the appropriate JSF form components (i.e. label, inputText)</p> <p>Another approach would be to just display the <code>&lt;my:someCustomComponent&gt;</code> and then that would return an <code>HtmlDataTable</code> with form elements. (I think this is maybe easier to do).</p> <p>Which approach is best? Can someone show me to some links or code where it shows how I can create this? I prefer complete code examples, and not answers like "You need a subclass of <code>javax.faces.component.UIComponent</code>".</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload