Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I add/remove Primefaces components dynamically?

How can I add/ remove the primefaces inputText dynamically?

like image 584
Nidheesh Avatar asked Dec 20 '25 07:12

Nidheesh


1 Answers

To add/remove textboxes, try the following snippets.

 <h:panelGrid columns="1" cellpadding="10">
        <h:commandButton value="+" action="#{contactBean.addPhone}"
            image="../images/addbtn.png" />
        <p:dataTable border="0" value="#{contactBean.phoneNos}" var="p"
            rowIndexVar="rowIndex" emptyMessage="No phone numbers entered">
            <p:column>
                <h:selectOneMenu id="extraTask1" value="#{p.phoneType}">
                    <f:selectItem itemLabel="Select" itemValue="" />
                    <f:selectItem itemLabel="Mobile" itemValue="Mobile" />
                    <f:selectItem itemLabel="Work" itemValue="Work" />
                    <f:selectItem itemLabel="Others" itemValue="Others" />
                </h:selectOneMenu>
            </p:column>
            <p:column>
                <p:inputText value="#{p.phoneNo}" />
            </p:column>
            <p:column>
                <h:commandButton value="remove" image="../images/button_remove.gif"
                    actionListener="#{contactBean.removePhone}">
                    <f:param name="columnToRemove" value="#{rowIndex}" />
                </h:commandButton>
            </p:column>
        </p:dataTable>


    </h:panelGrid>
like image 189
Nidheesh Avatar answered Dec 22 '25 22:12

Nidheesh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!