As a follow up to this question. It appears the components in a p:dashboard
are only draggable if their parent panel has a header set (which contains the title). How do I make it so the panels can be dragged even if the header isn't set? So the whole panel will be the handle to drag it around, not just the header.
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>
<div style="height: 500px">
<h:form id="dashboardForm">
<p:dashboard id="dashboardPanel" model="#{dashboardView.model}"
binding="#{dashboardView.dashboardPanel }">
<p:ajax event="reorder" />
</p:dashboard>
<div style="clear: both" />
</h:form>
</div>
</h:body>
</html>
And the bean
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.event.ActionEvent;
import org.primefaces.component.inputtext.InputText;
import org.primefaces.component.panel.Panel;
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;
private UIComponent dashboardPanel;
public void addTextWidget(ActionEvent event)
{
Panel panel = new Panel();
InputText textWidget = new InputText();
int childCount = dashboardPanel.getChildCount();
String widgetId = "widget" + String.valueOf(childCount);
panel.setHeader(widgetId); //I don't want to have to do this
panel.setId(widgetId);
panel.getChildren().add(textWidget);
addWidget(widgetId);
dashboardPanel.getChildren().add(panel);
}
public void addWidget(String widgetId)
{
DashboardColumn column1 = model.getColumn(0);
column1.addWidget(widgetId);
}
public UIComponent getDashboardPanel()
{
return dashboardPanel;
}
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 setDashboardPanel(UIComponent dashboardPanel)
{
this.dashboardPanel = dashboardPanel;
}
}