簡體   English   中英

動態將Primefaces組件添加到JSF頁面

[英]Dynamically add Primefaces components to JSF Page

我試圖將面板添加到我的jsf頁面的正文中,並且它們顯示在頁面上,但是所有設置均無效,並且日歷僅顯示為常規inputText框。 我是錯誤地初始化我的組件還是錯誤地添加了它們? 我正在制作的頁面允許我單擊一個按鈕,並將預制面板添加到我的頁面。

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;

}

為什么您不喜歡僅使用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