Jsf 2 我可以动态添加/删除Primefaces组件吗?
如何动态添加/删除primefaces inputText?这是简单的模式:Jsf 2 我可以动态添加/删除Primefaces组件吗?,jsf-2,primefaces,Jsf 2,Primefaces,如何动态添加/删除primefaces inputText?这是简单的模式: <h:inputText rendered="#{object.visibile}" /> 如果object.visible==true则输入文本可见。要添加/删除文本框,请尝试以下代码段 <h:panelGrid columns="1" cellpadding="10"> <h:commandButton value="+" action="#{contactB
<h:inputText rendered="#{object.visibile}" />
如果
object.visible==true
则输入文本可见。要添加/删除文本框,请尝试以下代码段
<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>
你接受了Michel的答案,这让我很惊讶,我心里有一个完全不同的功能需求。Michel的解决方案需要在视图中准备固定数量的输入,而您似乎希望让用户动态添加/删除未确定数量。同意您的意见。因为我是新手,所以我认为它会起作用。但它只有在我们有固定数量的准备输入时才会起作用,正如你所说。但我做了一些变通,准备工作时没有使用渲染。然后你应该详细地重新发布它作为答案,并接受自己。我使用p:dataGrid
来解决类似的问题,但其中的组件具有相同的ID。你也有同样的问题吗?使用p:dataTable
的原因是什么?提前谢谢我没有这个问题。目前,所有值都已发布到列表中。无论如何,我还没有尝试使用p:dataGrid
。使用dataTable时,所有数据都由列表处理。而且因为更容易更新primeFaces的dataTable组件,这提供了一些动态组件的可能性。