/* * ICESOFT COMMERCIAL SOURCE CODE LICENSE V 1.0 * * The contents of this file are subject to the ICEsoft Commercial Source * Code License Agreement V1.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of the * License at * http://www.icesoft.com/license/commercial-source-v1.0.html * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the * License for the specific language governing rights and limitations under * the License. * * Copyright 2009-2010 ICEsoft Technologies Canada, Corp. All Rights Reserved. * */ package com.iceface.collapasabledatatable; import java.util.ArrayList; import java.util.Date; import java.util.HashSet; import java.util.List; import java.util.Set; import javax.faces.FacesException; import javax.faces.component.UIComponent; import javax.faces.context.FacesContext; import javax.faces.model.SelectItem; import com.iceface.collapasabledatatable.Employee; import com.iceface.collapasabledatatable.EmployeeService; import com.iceface.collapasabledatatable.DataTableBase; import com.icesoft.faces.facelets.component.table.editable.EditableTableBean; import com.icesoft.faces.facelets.component.table.editable.EditableTableException; import com.icesoft.faces.facelets.component.table.editable.IEditableTableEventListener; public class EditableTableExampleBean extends DataTableBase{ private EditableTableBean editableTableBean; private List departments; public EditableTableExampleBean(){ } public EditableTableBean getEditableTableBean() { super.setEmployeeService(employeeService); editableTableBean = new EditableTableBean(getEmployees(), new EditableTableEventListener()); return editableTableBean; } public void setEmployeeService(EmployeeService employeeService) { System.out.println("Set Employee Service is getting called"); super.setEmployeeService(employeeService); editableTableBean = new EditableTableBean(getEmployees(), new EditableTableEventListener()); } public void validateLastName(FacesContext fc, UIComponent comp, Object obj){ String str = (String)obj; if( str != null && !Character.isUpperCase(str.charAt(0)) ){ throw new FacesException("The Last Name must start with the capital letter"); } } class EditableTableEventListener implements IEditableTableEventListener{ public Object createNewRow() { System.out.println("one row is created"); Employee emp = new Employee(); emp.setFirstName("sk"); return emp; } public void rowDeleted(Object row) { System.out.println("row deleted ---> " + row); } public void rowSelected(Object row) { System.out.println("row selected ---> " + row); } public void rowUpdated(Object oldBean, Object newBean) { System.out.println("row updated: " + oldBean + " ---> " + newBean); } public void rowEditCanceled(Object oldBean, Object newBean) throws EditableTableException { System.out.println("row edit canceled"); } } }