jsf-sheet primefaces
Jsf-sheet es un componente que se integra con JSF y primefaces para que funcione la librería hansontable desarrollada en javascript.
Descargamos la librería jsf-sheet-1.5.jar, slf4j-api-1.6.1.jar, slf4j-simple-1.6.4.jar, commons-lang3-3.4.jar y lo
adjuntamos al proyecto.
Para hacer una primera prueba creamos dos clases una tipo POJO y la otra managedbean:
public class Asset implements Serializable {
private static final long serialVersionUID = 1L;
private int assetId;
private String hostName;
private String description;
private double valor1;
private double valor2;
getters- setteres
@ManagedBean
@ViewScoped
//@RequestScoped
//@SessionScoped
//@ApplicationScoped
public class AssetController implements Serializable {
private List<Asset> assets = new ArrayList<>();
/**
* Creates a new instance of AssetController
*/
public AssetController() {
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | import com.lassitercg.faces.components.sheet.Sheet; import java.io.Serializable; import java.util.ArrayList; import java.util.List; import javax.annotation.PostConstruct; import javax.faces.bean.ManagedBean; import javax.faces.bean.ViewScoped; import javax.faces.context.FacesContext; import javax.faces.event.AjaxBehaviorEvent; /** * * @author washington.sinchigua */ @ManagedBean @ViewScoped //@RequestScoped //@SessionScoped //@ApplicationScoped public class AssetController implements Serializable { private List assets = new ArrayList<>(); /** * Creates a new instance of AssetController */ public AssetController() { } @PostConstruct public void init() { assets.add(new Asset(1, "GUAMAN VASQUEZ ROSA IVONE", "", 0, 0)); assets.add(new Asset(2, "LARREA ACOSTA ELIZABETH MARTINA", "", 0, 0)); assets.add(new Asset(3, "MOREIRA BARBECHO CARMEN CECILIA", "", 0, 0)); assets.add(new Asset(4, "JIMENES NELLIS", "", 0, 0)); assets.add(new Asset(5, "DIAZ SALAZAR TANYI ROXANNA", "", 0, 0)); assets.add(new Asset(6, "MENDOZA GARCIA WASHINGTON JAVIER", "", 0, 0)); assets.add(new Asset(7, "DELGADO YEPEZ LUIGGI JOSE", "", 0, 0)); assets.add(new Asset(8, "DIAZ SALAZAR KAREN SOLANGE", "", 0, 0)); } public void cellEditEvent(AjaxBehaviorEvent event) { Sheet sheet = (Sheet) event.getComponent(); // List updates = sheet.getUpdates(); int row = sheet.getSelectedRow(); //String rowCalss = sheet.getCurrentRowClass(); //Object obj = sheet.getValue(); //Asset asset = (Asset) obj; System.out.println("fila: "); // HashSet processed = new HashSet(); // int rowUpdates = 0; // for (SheetUpdate update : updates) { // // System.out.println(update.toString()); // Asset asset = (Asset) update.getRowData(); // if (processed.contains(asset)) { // continue; // } // // // // // //manager.update(asset); // System.out.println("Asset: " + asset.getHostName()); // rowUpdates++; // int index = update.getColIndex(); // // // // //updateEvent.fire(asset); // // // } //refresh(); //listarElementos(); // sheet.commitUpdates(); } private void refresh(){ FacesContext context = FacesContext.getCurrentInstance(); if (context.getPartialViewContext().isPartialRequest()) { StringBuilder eval = new StringBuilder(); // //String jQueryId = this.getClientId().replace(":", "\\\\:"); // //String jsDeltaVar = this.getClientId().replace(":", "_") + "_delta"; // eval.append("$('#"); // //eval.append(jQueryId); eval.append("_input').val('');"); // //eval.append(jsDeltaVar); eval.append("={};"); //RequestContext.getCurrentInstance().getScriptsToExecute().add(eval.toString()); } } private void listarElementos() { for (Asset asset : assets) { System.out.println("Asset: " + asset.getValor1() + " " + asset.getValor2() + " " + asset.getTotal()); } } /** * @return the assets */ public List getAssets() { // listarElementos(); // System.out.println("getAssets"); return assets; } /** * @param assets the assets to set */ public void setAssets(List assets) { //System.out.println("setAssets"); this.assets = assets; } } |
1 |