All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jboss.seam.databinding.DataModelIndexSelector Maven / Gradle / Ivy

There is a newer version: 3.2.26.ayg
Show newest version
package org.jboss.seam.databinding;

import java.util.Map;

import javax.faces.model.DataModel;

import org.jboss.seam.annotations.datamodel.DataModelSelectionIndex;

/**
 * Extracts the selected "index" (the row index, or the key of a map) from a JSF DataModel.
 * 
 * @author Gavin King
 */
public class DataModelIndexSelector implements DataSelector {
	
	public DataModelIndexSelector() {
		super();
	}

	@Override
	public String getVariableName(DataModelSelectionIndex in) {
		return in.value();
	}

	@Override
	public Object getSelection(DataModelSelectionIndex in, DataModel wrapper) {
		if (wrapper.getRowCount() == 0 || wrapper.getRowIndex() < 0) {
			return null;
		} else {
			Object rowData = wrapper.getRowData();
			if (rowData instanceof Map.Entry) {
				return ((Map.Entry) rowData).getKey();
			} else {
				return wrapper.getRowIndex();
			}
		}
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy