Jsf 动态添加和删除面板和面
如何在primefaces中动态添加面板 目标是有一个按钮来添加面板。使用以下代码中的closeable(可关闭)选项可轻松移除面板:Jsf 动态添加和删除面板和面,jsf,user-interface,primefaces,Jsf,User Interface,Primefaces,如何在primefaces中动态添加面板 目标是有一个按钮来添加面板。使用以下代码中的closeable(可关闭)选项可轻松移除面板: <p:panel id="panel1" header="Panel 1" style="width : 150px;" toggleable="true" closable="true" toggleSpeed="500" closeSpeed="500"> Move and Resize ME!</p:panel> 简单地说,我将嵌
<p:panel id="panel1" header="Panel 1" style="width : 150px;" toggleable="true" closable="true" toggleSpeed="500" closeSpeed="500"> Move and Resize ME!</p:panel>
简单地说,我将嵌套我的简单地说,我将嵌套我的假设您有一个panelgrid来容纳面板,一个简单的jsf片段将是
<p:panelGrid id="myPanelGrid" columns="1">
</p:panelGrid>
<h:form>
<p:commandButton value="Add Panel" actionListener="#{bean.addPanel}" update=":myPanelGrid" />
</h:form>
此方法将通过id查找holder panelgrid组件,添加一个新的org.primefaces.component.panel.panel并设置一些字段,然后将其添加到父组件
commandButton的update=:myPanelGrid属性将通知panelGrid使用新数据更新自身。假设您有一个panelGrid来保存面板,则可以使用一个简单的jsf片段
<p:panelGrid id="myPanelGrid" columns="1">
</p:panelGrid>
<h:form>
<p:commandButton value="Add Panel" actionListener="#{bean.addPanel}" update=":myPanelGrid" />
</h:form>
此方法将通过id查找holder panelgrid组件,添加一个新的org.primefaces.component.panel.panel并设置一些字段,然后将其添加到父组件
commandButton的update=:myPanelGrid属性将通知panelGrid使用新数据更新自身
<p:panelGrid id="myPanelGrid" columns="1">
</p:panelGrid>
<h:form>
<p:commandButton value="Add Panel" actionListener="#{bean.addPanel}" update=":myPanelGrid" />
</h:form>
public void addPanel(ActionEvent event) {
UIComponent component = FacesContext.getCurrentInstance().getViewRoot().findComponent("myPanelGrid");
if (component != null) {
Panel p = new Panel();
p.setClosable(true);
p.setHeader("Test");
p.setVisible(true);
component.getChildren().add(p);
}
}