Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to add multiple rows in rich:datatable when by manually clicking add new Button?
    primarykey
    data
    text
    <p>I am designing a web page in which there is a rich:DataTable which I am using to add new customer information in the Database . </p> <p>So each time a click the "Add New" button, a new row should appear in the rich datatable with Blank Input Text Fields . </p> <p>Problem : Even how many times I am clicking the "Add New" Button, there remains only one row in table . </p> <p>Following is the code of my web page :</p> <pre class="lang-html prettyprint-override"><code>&lt;a4j:outputPanel id="rep" rendered="#{adminBean.currentItem == 'Participant' || adminBean.currentItem == 'Administrator'}"&gt; &lt;rich:panel rendered="#{not empty adminBean.currentItem}" header="Add Customer" id="out"&gt; &lt;h:panelGrid columns="2"&gt; &lt;h:commandButton value="Add New" type="button" style="width: 70px" actionListener="#{adminBean.addCustAction}"&gt; &lt;a4j:ajax render="out"/&gt; &lt;/h:commandButton&gt; &lt;a4j:commandButton value="Delete" style="margin-left: 10px; width: 70px"&gt;&lt;/a4j:commandButton&gt; &lt;/h:panelGrid&gt; &lt;rich:dataScroller for="setcust" style="margin-top: 17px"&gt;&lt;/rich:dataScroller&gt; &lt;rich:dataTable id="setcust" value="#{adminBean.customerList}" var="custl" rows="10" style="width: 900px;margin-top: 5px"&gt; &lt;rich:column id="col1"&gt; &lt;f:facet name="header"&gt; &lt;h:outputText value="Customer ID" style="font-size: smaller; font-weight: bolder; "/&gt; &lt;/f:facet&gt; &lt;h:inputText value="#{custl.Id}"&gt;&lt;/h:inputText&gt; &lt;/rich:column&gt; &lt;rich:column id="col2"&gt; &lt;f:facet name="header"&gt; &lt;h:outputText value="First Name" style="font-size: smaller; font-weight: bolder;"/&gt; &lt;/f:facet&gt; &lt;h:inputText value="#{custl.FirstName}"&gt;&lt;/h:inputText&gt; &lt;/rich:column&gt; &lt;rich:column id="col3"&gt; &lt;f:facet name="header"&gt; &lt;h:outputText value="Last Name" style="font-size: smaller; font-weight: bolder;"/&gt; &lt;/f:facet&gt; &lt;h:inputText value="#{custl.lastName}"&gt;&lt;/h:inputText&gt; &lt;/rich:column&gt; &lt;rich:column id="col4"&gt; &lt;f:facet name="header"&gt; &lt;h:outputText value="Phone" style="font-size: smaller; font-weight: bolder;"/&gt; &lt;/f:facet&gt; &lt;h:inputText value="#{custl.phoneNo}"&gt;&lt;/h:inputText&gt; &lt;/rich:column&gt; &lt;rich:column id="col5"&gt; &lt;f:facet name="header"&gt; &lt;h:outputText value="Address" style="font-size: smaller; font-weight: bolder;"/&gt; &lt;/f:facet&gt; &lt;h:inputText value="#{custl.address}"&gt;&lt;/h:inputText&gt; &lt;/rich:column&gt; &lt;rich:column id="col6"&gt; &lt;f:facet name="header"&gt; &lt;h:outputText value="City" style="font-size: smaller; font-weight: bolder;"/&gt; &lt;/f:facet&gt; &lt;h:inputText value="#{custl.city}"&gt;&lt;/h:inputText&gt; &lt;/rich:column&gt; &lt;rich:column id="col7"&gt; &lt;f:facet name="header"&gt; &lt;h:outputText value="Email" style="font-size: smaller; font-weight: bolder;"/&gt; &lt;/f:facet&gt; &lt;h:inputText value="#{custl.email}"&gt;&lt;/h:inputText&gt; &lt;/rich:column&gt; &lt;/rich:dataTable&gt; &lt;/rich:panel&gt; &lt;/a4j:outputPanel&gt; </code></pre> <p>Following is the code of the AdminBean:</p> <pre><code>@ManagedBean @ViewScoped public class AdminBean { private String currentType; private String currentItem; private List&lt;Customer&gt; customerList = new ArrayList&lt;Customer&gt;(); private List&lt;Account&gt; accountList; private List optionList; public List getOptionList() { optionList = new ArrayList&lt;String&gt;(); if (currentType.equals("Add New User")) { optionList.add("Participant"); optionList.add("Administrator"); } else if (currentType.equalsIgnoreCase("Manage Balance")) { optionList.add("Withdrawl"); optionList.add("Deposit"); } return optionList; } public void setOptionList(List optionList) { this.optionList = optionList; } public List&lt;Account&gt; getAccountList() { return accountList; } public void setAccountList(List&lt;Account&gt; accountList) { this.accountList = accountList; } public List&lt;Customer&gt; getCustomerList() { System.out.println("got list.................."); return customerList; } public void setCustomerList(List&lt;Customer&gt; customerList) { this.customerList = customerList; } public String getCurrentItem() { return currentItem; } public void setCurrentItem(String currentItem) { this.currentItem = currentItem; } public String getCurrentType() { return currentType; } public void setCurrentType(String currentType) { this.currentType = currentType; } public void addCustAction(){ System.out.println("kshitij jain.......actionListener"+customerList.size()); Customer cust = new Customer(); customerList.add(cust); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
    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