Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* The MIT License
*
* Copyright (c) 2009-2023 PrimeTek Informatics
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.primefaces.component.datatable.feature;
import java.lang.reflect.Array;
import java.util.*;
import javax.el.ValueExpression;
import javax.faces.FacesException;
import javax.faces.context.FacesContext;
import org.primefaces.component.datatable.DataTable;
import org.primefaces.component.datatable.DataTableBase;
import org.primefaces.component.datatable.DataTableState;
import org.primefaces.util.LangUtils;
public class SelectionFeature implements DataTableFeature {
private static final String ALL_SELECTOR = "@all";
@Override
public void decode(FacesContext context, DataTable table) {
String clientId = table.getClientId(context);
Map params = context.getExternalContext().getRequestParameterMap();
Object originalValue = table.getValue();
boolean allEligibleToSelection = table.isFilteringCurrentlyActive() && !table.isSelectAllFilteredOnly();
String selection = params.get(clientId + "_selection");
Set rowKeys = Collections.emptySet();
if (LangUtils.isNotBlank(selection)) {
rowKeys = LangUtils.newLinkedHashSet(selection.split(","));
table.setSelectAll(ALL_SELECTOR.equals(selection));
}
else {
table.setSelectAll(false);
}
if (allEligibleToSelection) {
table.setValue(null);
}
decodeSelection(context, table, rowKeys);
if (allEligibleToSelection) {
table.setValue(originalValue);
}
if (table.isMultiViewState()) {
DataTableState ts = table.getMultiViewState(true);
ts.setSelectedRowKeys(table.getSelectedRowKeys());
}
}
public void decodeSelection(FacesContext context, DataTable table, Set rowKeys) {
table.setSelection(null);
table.setSelectedRowKeys(null);
if (table.isSingleSelectionMode()) {
decodeSingleSelection(context, table, rowKeys);
}
else {
decodeMultipleSelection(context, table, rowKeys);
}
}
public void decodeSelectionRowKeys(FacesContext context, DataTable table) {
Set rowKeys = null;
ValueExpression selectionVE = table.getValueExpression(DataTableBase.PropertyKeys.selection.name());
if (selectionVE != null) {
Object selection = selectionVE.getValue(context.getELContext());
if (selection != null) {
rowKeys = new HashSet<>();
if (table.isSingleSelectionMode()) {
rowKeys.add(table.getRowKey(selection));
}
else {
Class clazz = selection.getClass();
boolean isArray = clazz != null && clazz.isArray();
if (clazz != null && !isArray && !List.class.isAssignableFrom(clazz)) {
throw new FacesException("Multiple selection reference must be an Array or a List for datatable " + table.getClientId());
}
List