【问题标题】:Dynamically add Primefaces components to JSF Page将 Primefaces 组件动态添加到 JSF 页面
【发布时间】:2014-07-01 14:13:56
【问题描述】:

我正在尝试将面板添加到我的 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;

}

【问题讨论】:

    标签: jsf jsf-2 primefaces


    【解决方案1】:

    为什么你不喜欢只使用 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>
    

    【讨论】:

      猜你喜欢
      • 2014-07-22
      • 1970-01-01
      • 2012-01-03
      • 1970-01-01
      • 2013-03-23
      • 1970-01-01
      • 2011-04-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多