package various;

import java.io.Serializable;
import javax.faces.context.FacesContext;
import javax.faces.model.ArrayDataModel;
import javax.faces.model.DataModel;
import javax.faces.model.DataModelEvent;
import javax.faces.model.DataModelListener;

/**
 * Przykład obsługi zdarzenia iterowania w modelu danych (patrz rozdzial 3.2)
 *
 */
public class TestingDataModels implements Serializable {	

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	DataModel model;
	public TestingDataModels() {
		String numberStrings[] = new String[] { "one", "two",
		"three" };
		model = new ArrayDataModel(numberStrings);
		model.addDataModelListener(new DataModelListener() {
			public void rowSelected(DataModelEvent e) {
				FacesContext.getCurrentInstance().getExternalContext().log(
						"value: " + e.getRowData() + "; row selected:"
								+ e.getRowIndex());

			}
		});
	}

	public DataModel getModel() {

		return model;
	}

	public void setModel(DataModel model) {
		this.model = model;
	}

}
