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>