Can I add/remove Primefaces components dynamically?

最后都变了- 提交于 2020-01-13 13:13:45

问题


How can I add/ remove the primefaces inputText dynamically?


回答1:


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>



回答2:


This is the easy mode:

<h:inputText rendered="#{object.visibile}" /> 

if object.visibile == true the inputText is visible.



来源:https://stackoverflow.com/questions/8046116/can-i-add-remove-primefaces-components-dynamically

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!