title: JSF PrimeFaces add multiple empty inputs that are required only when main form submitted
body: <p>Assume we have a form. One <code>p:inputText</code> visible but user can add many more using <code>p:commandButton</code>. All this values have to be provided when submitting with another <code>p:commandButton</code>. Issue arises when user tries to add more than one empty input fields. All of them are marked <code>required="true"</code> so validation error appears when one field is empty and user try to add another.</p>
  
  <p>The best would be to allow to add as many fields as user needs, then fill them in and submit.</p>
  
  <p>JSF:</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;h:form id="myForm"&gt;
      &lt;p:commandButton value="add" actionListener="#{testBean.addNewItem()}" update="@form"/&gt;
      &lt;p:commandButton value="done" update="@form,:p"/&gt;
      &lt;br/&gt;
      &lt;ui:repeat value="#{testBean.list}" var="l"&gt;
          &lt;p:inputText value="#{l.name}" required="true"/&gt;
          &lt;br/&gt;
      &lt;/ui:repeat&gt;
  &lt;/h:form&gt;
  &lt;p:messages autoUpdate="true"/&gt;
  &lt;p:panel id="p"&gt;
      #{testBean.list}
  &lt;/p:panel&gt;
  </code></pre>
  
  <p>Backing bean does nothing fancy. Only provides getter and setter for list. It also adds empty string to the list.</p>
  
  <pre class="lang-java prettyprint-override"><code>@ManagedBean
  @ViewScoped
  public class TestBean implements Serializable {
      private List&lt;Item&gt; list = new ArrayList&lt;Item&gt;();
  
      public List&lt;Item&gt; getList() { return list; }
  
      public void setList(List&lt;Item&gt; list) { this.list = list; }
  
      public void addNewItem() { list.add(new Item()); }
  }
  </code></pre>
  
  <p>I could:</p>
  
  <ol>
  <li>Remove requirement for field - not an option.</li>
  <li>Add <code>immediate="true"</code> for adding button. Validation is not a problem now but it causes all values that was filled in but not submitted to disappear. And I need to update <code>@form</code> because only then newly added fields will be rendered by <code>ui:repeat</code>.</li>
  <li>I tried to add <code>process="@this"</code> for adding button. Unfortunately that didn't change a thing. Input field values are not processed, but form needs to be updated. I am loosing not submitted values as above.</li>
  </ol>
  
  <p>What am I missing? Is there any workaround?</p>