p:dashboard添加的面板不可拖动 [英] p:dashboard added panels aren't draggable
本文介绍了p:dashboard添加的面板不可拖动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直在尝试遵循以下展示案例示例.我想做的是通过单击p:splitButton
上的按钮动态地将组件添加到仪表板,将组件添加到仪表板是可行的,但是由于某些原因,面板不可拖动.为什么?
I have been trying to follow this showcase example. What I want to do is dynamically add components to a dashboard by clicking buttons on a p:splitButton
, the adding of components to the dashboard works, but the panels aren't draggable for some reason. Why?
XHTML
<!DOCTYPE html>
<html xmlns="http://www.w3c.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>Example</title>
</h:head>
<h:body>
<h:form id="splitButtonForm">
<p:splitButton value="Action" icon="ui-icon-circle-triangle-s">
<p:menuitem value="New text entry" icon="ui-icon-newwin"
actionListener="#{dashboardView.addTextWidget}"
update="dashboardForm:dashboardPanel" />
</p:splitButton>
</h:form>
<h:form id="dashboardForm">
<p:dashboard id="dashboardPanel" model="#{dashboardView.model}">
<p:ajax event="reorder" listener="#{dashboardView.handleReorder}"/>
</p:dashboard>
</h:form>
</h:body>
</html>
这是豆子
import java.io.Serializable;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import org.primefaces.component.inputtext.InputText;
import org.primefaces.component.panel.Panel;
import org.primefaces.event.DashboardReorderEvent;
import org.primefaces.model.DashboardColumn;
import org.primefaces.model.DashboardModel;
import org.primefaces.model.DefaultDashboardColumn;
import org.primefaces.model.DefaultDashboardModel;
@SuppressWarnings("serial")
@ManagedBean
@ViewScoped
public class DashboardView implements Serializable
{
private DashboardModel model;
public DashboardModel getModel()
{
return model;
}
@PostConstruct
public void init()
{
model = new DefaultDashboardModel();
DashboardColumn column1 = new DefaultDashboardColumn();
DashboardColumn column2 = new DefaultDashboardColumn();
model.addColumn(column1);
model.addColumn(column2);
}
public void addWidget(String widgetId)
{
DashboardColumn column1 = model.getColumn(0);
column1.addWidget(widgetId);
}
public void addTextWidget(ActionEvent event)
{
UIComponent dashboardPanel = FacesContext.getCurrentInstance().getViewRoot().findComponent("dashboardForm:dashboardPanel");
Panel panel = new Panel();
InputText textWidget = new InputText();
int childCount = dashboardPanel.getChildCount();
String widgetId = "widget" + String.valueOf(childCount);
panel.setId(widgetId);
panel.getChildren().add(textWidget);
addWidget(widgetId);
dashboardPanel.getChildren().add(panel);
}
public void handleReorder(DashboardReorderEvent event)
{
}
}
推荐答案
确定,然后使面板可拖动,需要设置面板标题,因此在addTextWidget
方法中,我必须做类似的事情
OK then to make the panels draggable the panels header needs to be set, so in the addTextWidget
method I had to do something like
panel.setHeader(widgetId);
这篇关于p:dashboard添加的面板不可拖动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文