按照http://www.wobblycogs.co.uk/index.php/computing/jee/49-dynamic-dashboard-with-primefaces尝试创建动态信息中心的示例。
复制代码可以100%完成,但我试图将它与我自己的实现一起使用。
当我加载我的索引页面时,它会显示任何面板或仪表板。当我导航到一个不同的页面,然后返回元素出现!
我不知道为什么在初始页面加载时没有显示仪表板。
我正在使用Jboss 5.1,EJB 3.0,JSF 2.0和Primefaces 3.4。
这是我的控制器类的顶层:
@Model
@ViewController(viewId = "/pages/index.xhtml")
public class MonitorController implements Serializable, ViewInitializer, ViewFinalizer {
@Inject
private transient MonitorService monitorService;
@Inject
private transient MonitorUserService monitorUserService;
@Inject
private transient MonitorView view;
@Inject
private transient Conversation conversation;
@Override
public void initializeView() {
if (conversation.isTransient()) {
conversation.setTimeout(1800000);
conversation.begin();
}
MonitorUser user = monitorUserService.findOrCreateUser();
view.setUser(user);
List<MonitorElement> elements = monitorService.findMonitorElementsByUser();
view.setElements(elements);
view.setUsersMonitorElements(elements);
createDashBoard();
}
这是我创建仪表板,添加面板和设置列小部件的方法:
public void createDashBoard() {
final int DEFAULT_COLUMN_COUNT = 3;
int columnCount = DEFAULT_COLUMN_COUNT;
Dashboard dashboard;
FacesContext fc = FacesContext.getCurrentInstance();
Application application = fc.getApplication();
dashboard = (Dashboard) application.createComponent(fc, "org.primefaces.component.Dashboard", "org.primefaces.component.DashboardRenderer");
dashboard.setId("dashboard");
DashboardModel model = new DefaultDashboardModel();
for( int i = 0; i < columnCount; i++ ) {
DashboardColumn column = new DefaultDashboardColumn();
model.addColumn(column);
}
dashboard.setModel(model);
view.setModel(dashboard.getModel());
view.setDashboard(dashboard);
int index = 0;
for( MonitorElement i : view.getUsersMonitorElements()) {
Panel panel = (Panel) application.createComponent(fc, "org.primefaces.component.Panel", "org.primefaces.component.PanelRenderer");
panel.setId("id" + i.getId());
panel.setHeader("Dashboard Component " + i.getApplicationName());
panel.setClosable(true);
panel.setToggleable(true);
dashboard.getChildren().add(panel);
DashboardColumn column2 = model.getColumn(index%columnCount);
column2.addWidget(panel.getId());
HtmlOutputText text = new HtmlOutputText();
text.setValue(i.getCount() + "" );
panel.getChildren().add(text);
index++;
}
view.setModel(dashboard.getModel());
view.setDashboard(dashboard);
}
我正在使用以下命令在我的索引页面上实现仪表板:
<p:dashboard id="dynamic_dashboard3"
binding="#{monitorView.dashboard}">
</p:dashboard>