简体   繁体   English

动态将Primefaces组件添加到JSF页面

[英]Dynamically add Primefaces components to JSF Page

I am trying to add panels to the body of my jsf page and they appear on the page but none of the settings work and the calendars just appear as regular inputText boxes. 我试图将面板添加到我的jsf页面的正文中,并且它们显示在页面上,但是所有设置均无效,并且日历仅显示为常规inputText框。 Am I initializing my components incorrectly or adding them incorrectly? 我是错误地初始化我的组件还是错误地添加了它们? The page I am making allows me to click a button and add premade panels to my page. 我正在制作的页面允许我单击一个按钮,并将预制面板添加到我的页面。

private Date startDate;

private Date endDate;

private String Kpi;

private String baselineName;

private UIOutput body;

public void addPanel(ActionEvent event){
    //UIComponent component = FacesContext.getCurrentInstance().getViewRoot();
    if(body != null){
        body.getChildren().add(createCommandThroughputPanel());
        log.debug("Panel Added");
    }
}

public void removePanel(ActionEvent event){
    if(body != null){
        body.getChildren().remove(body.getChildren().size() - 1);
        log.debug("Panel Removed");
    }
}

public UIForm createCommandThroughputPanel(){

    UIForm form = new UIForm();

    //Create Panel
    Panel p = new Panel();
    p.setHeader("Command Throughput Data");
    p.setClosable(true);
    p.setToggleable(true);
    p.setToggleSpeed(500);
    p.setVisible(true);

    log.debug("p.getToggleSpeed() = " + p.getToggleSpeed());

    //Initialize startDate input calendar
    Calendar startCalendar = new Calendar();
    startCalendar.setValue(startDate);
    startCalendar.setShowButtonPanel(true);
    startCalendar.setNavigator(true);
    startCalendar.setPattern("MM/dd/yyyy HH:mm");
    startCalendar.setId("start");

    log.debug("startCalendar.getPattern() = " + startCalendar.getPattern());
    log.debug("startCalendar.getFamily() = " + startCalendar.getFamily());

    //Initialize endDate input Calendar
    Calendar endCalendar = new Calendar();
    endCalendar.setValue(endDate);
    endCalendar.setShowButtonPanel(true);
    endCalendar.setNavigator(true);
    endCalendar.setPattern("MM/dd/yyyy HH:mm");
    endCalendar.setId("end");

    log.debug("startCalendar.getPattern() = " + startCalendar.getPattern());
    log.debug("endCalendar.getFamily() = " + endCalendar.getFamily());

    //Initialize baseline selectOneMenu
   SelectOneMenu baseline = new SelectOneMenu();
   baseline.setId("baseline");
   baseline.setValue(baselineName);
   UISelectItems item = new UISelectItems();

    p.getChildren().add((Calendar)startCalendar);
    p.getChildren().add((Calendar)endCalendar);
    form.getChildren().add(p);

    for(UIComponent cal : p.getChildren()){
        log.debug("cal.getId() = " + cal.getId());
        log.debug("cal.getFamily() = " + cal.getFamily());
    }


    return form;

}

why you dont like just use a xhtml page and you need just to write this: 为什么您不喜欢仅使用xhtml页面,而只需编写以下代码:

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui">

<p:layoutUnit position="north" size="40">
                    <p:commandButton value="About"  onclick="PF(alert('Esprit Olap View')).show()" type="button" icon="ui-icon-power"/>

                 <p:commandButton align="right" value="Connect" type="button" onclick="PF('dlg3').show();" style="text-align:right" />

                </p:layoutUnit>
</html>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM