SHOW:
|
|
- or go back to the newest paste.
| 1 | package com.calldesk.cqp.jsf; | |
| 2 | ||
| 3 | import javax.faces.bean.ManagedBean; | |
| 4 | - | import javax.faces.bean.SessionScoped; |
| 4 | + | |
| 5 | import javax.faces.component.html.HtmlOutputLabel; | |
| 6 | import javax.faces.component.html.HtmlPanelGrid; | |
| 7 | import javax.faces.context.FacesContext; | |
| 8 | import javax.faces.event.ActionEvent; | |
| 9 | import javax.faces.view.ViewScoped; | |
| 10 | ||
| 11 | import org.primefaces.component.dashboard.Dashboard; | |
| 12 | import org.primefaces.component.panel.Panel; | |
| 13 | import org.primefaces.event.CloseEvent; | |
| 14 | import org.primefaces.model.DashboardColumn; | |
| 15 | import org.primefaces.model.DashboardModel; | |
| 16 | import org.primefaces.model.DefaultDashboardColumn; | |
| 17 | import org.primefaces.model.DefaultDashboardModel; | |
| 18 | ||
| 19 | import com.calldesk.cqp.form.Form; | |
| 20 | import com.calldesk.cqp.form.FormItem; | |
| 21 | ||
| 22 | - | @SessionScoped |
| 22 | + | |
| 23 | @ViewScoped | |
| 24 | public class MonitoringFormDashboard {
| |
| 25 | ||
| 26 | private Dashboard dashboard; | |
| 27 | private Form form; | |
| 28 | ||
| 29 | private FormItem newField; | |
| 30 | ||
| 31 | public MonitoringFormDashboard() {
| |
| 32 | FacesContext fc = FacesContext.getCurrentInstance(); | |
| 33 | dashboard = (Dashboard) fc.getApplication().createComponent(fc, "org.primefaces.component.Dashboard", "org.primefaces.component.DashboardRenderer"); | |
| 34 | dashboard.setId("formDashboard");
| |
| 35 | ||
| 36 | this.newField = new FormItem("", 0);
| |
| 37 | ||
| 38 | /* TEST */ | |
| 39 | form = new Form("TestForm");
| |
| 40 | /* END TEST */ | |
| 41 | } | |
| 42 | ||
| 43 | private void buildModel() {
| |
| 44 | DashboardModel model = new DefaultDashboardModel(); | |
| 45 | ||
| 46 | DashboardColumn column = new DefaultDashboardColumn(); | |
| 47 | model.addColumn(column); | |
| 48 | ||
| 49 | FacesContext fc = FacesContext.getCurrentInstance(); | |
| 50 | ||
| 51 | for(FormItem item : form) {
| |
| 52 | Panel panel = (Panel) fc.getApplication().createComponent(fc, "org.primefaces.component.Panel", "org.primefaces.component.PanelRenderer"); | |
| 53 | panel.setId("panel_"+item.hashCode());
| |
| 54 | panel.setHeader(" * Clique e arraste para ordenar * ");
| |
| 55 | panel.setClosable(true); | |
| 56 | ||
| 57 | this.dashboard.getChildren().add(panel); | |
| 58 | this.dashboard.getModel().getColumn(0).addWidget(panel.getId()); | |
| 59 | ||
| 60 | HtmlPanelGrid grid = new HtmlPanelGrid(); | |
| 61 | grid.setCellspacing("5");
| |
| 62 | grid.setColumns(2); | |
| 63 | ||
| 64 | HtmlOutputLabel label = new HtmlOutputLabel(); | |
| 65 | label.setValue(item.getName()); | |
| 66 | label.setFor("inputText_" + item.hashCode());
| |
| 67 | ||
| 68 | HtmlInputText inputText = new HtmlInputText(); | |
| 69 | inputText.setId("inputText_" + item.hashCode());
| |
| 70 | ||
| 71 | grid.getChildren().add(label); | |
| 72 | grid.getChildren().add(inputText); | |
| 73 | ||
| 74 | panel.getChildren().add(grid); | |
| 75 | } | |
| 76 | ||
| 77 | dashboard.setModel(model); | |
| 78 | } | |
| 79 | ||
| 80 | public void handleClose(CloseEvent event) {
| |
| 81 | ||
| 82 | } | |
| 83 | ||
| 84 | - | this.form.addItem(newField); |
| 84 | + | |
| 85 | this.form.addItem(new FormItem(newField.getName(), newField.getType())); | |
| 86 | newField.setName("");
| |
| 87 | newField.setType(0); | |
| 88 | } | |
| 89 | ||
| 90 | public String getNewFieldName() {
| |
| 91 | return this.newField.getName(); | |
| 92 | } | |
| 93 | ||
| 94 | public String getNewFieldType() {
| |
| 95 | return ""+this.newField.getType(); | |
| 96 | } | |
| 97 | ||
| 98 | public void setNewFieldName(String name) {
| |
| 99 | this.newField.setName(name); | |
| 100 | } | |
| 101 | ||
| 102 | public void setNewFieldType(String type) {
| |
| 103 | this.newField.setType(Integer.parseInt(type)); | |
| 104 | } | |
| 105 | ||
| 106 | public Dashboard getDashboard() {
| |
| 107 | this.buildModel(); | |
| 108 | return this.dashboard; | |
| 109 | } | |
| 110 | ||
| 111 | public void setDashboard(Dashboard dashboard) {
| |
| 112 | this.dashboard = dashboard; | |
| 113 | } | |
| 114 | } |