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.
/*
* Copyright (c) 2011-2023 PrimeFaces Extensions
*
* 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.extensions.component.tristatemanycheckbox;
import java.io.IOException;
import java.util.*;
import java.util.Map.Entry;
import javax.faces.FacesException;
import javax.faces.component.UIComponent;
import javax.faces.component.UIInput;
import javax.faces.component.UINamingContainer;
import javax.faces.component.UISelectMany;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
import javax.faces.convert.Converter;
import javax.faces.model.SelectItem;
import org.primefaces.component.selectmanycheckbox.SelectManyCheckbox;
import org.primefaces.extensions.util.Attrs;
import org.primefaces.renderkit.SelectManyRenderer;
import org.primefaces.util.Constants;
import org.primefaces.util.EscapeUtils;
import org.primefaces.util.HTML;
import org.primefaces.util.WidgetBuilder;
/**
* TriStateManyCheckboxRenderer
*
* @author Mauricio Fenoglio / last modified by $Author$
* @version $Revision$
* @since 0.3
*/
public class TriStateManyCheckboxRenderer extends SelectManyRenderer {
@Override
public Object getConvertedValue(final FacesContext context, final UIComponent component, final Object submittedValue) {
// only convert the values of the maps
if (submittedValue instanceof Map) {
final Map mapSub = (Map) submittedValue;
final List keyValues = new ArrayList<>(mapSub.keySet());
final Map mapSubConv = new LinkedHashMap<>();
final TriStateManyCheckbox checkbox = (TriStateManyCheckbox) component;
final Converter> converter = checkbox.getConverter();
if (converter != null) {
for (final String keyVal : keyValues) {
final Object mapVal = converter.getAsObject(context, checkbox, (String) mapSub.get(keyVal));
mapSubConv.put(keyVal, mapVal);
}
return mapSubConv;
}
else {
return mapSub;
}
}
else {
throw new FacesException("Value of '" + component.getClientId() + "'must be a Map instance");
}
}
@Override
public void decode(final FacesContext context, final UIComponent component) {
final TriStateManyCheckbox checkbox = (TriStateManyCheckbox) component;
if (!shouldDecode(checkbox)) {
return;
}
decodeBehaviors(context, checkbox);
final String submitParam = getSubmitParam(context, checkbox);
final Map params = context.getExternalContext().getRequestParameterValuesMap();
String[] valuesArray = null;
if (params.containsKey(submitParam)) {
valuesArray = params.get(submitParam);
}
checkbox.setSubmittedValue(getSubmitedMap(context, checkbox, valuesArray));
}
@Override
public void encodeEnd(final FacesContext context, final UIComponent component) throws IOException {
final TriStateManyCheckbox checkbox = (TriStateManyCheckbox) component;
encodeMarkup(context, checkbox);
encodeScript(context, checkbox);
}
protected void encodeMarkup(final FacesContext context, final TriStateManyCheckbox checkbox) throws IOException {
final ResponseWriter writer = context.getResponseWriter();
final String clientId = checkbox.getClientId(context);
final String style = checkbox.getStyle();
final String styleClass = getStyleClassBuilder(context)
.add(SelectManyCheckbox.STYLE_CLASS)
.add(checkbox.getStyleClass())
.build();
writer.startElement("table", checkbox);
writer.writeAttribute("id", clientId, "id");
writer.writeAttribute(Attrs.CLASS, styleClass, "styleClass");
if (style != null) {
writer.writeAttribute(Attrs.STYLE, style, Attrs.STYLE);
}
encodeSelectItems(context, checkbox);
writer.endElement("table");
}
protected void encodeSelectItems(final FacesContext context, final TriStateManyCheckbox checkbox) throws IOException {
final ResponseWriter writer = context.getResponseWriter();
final List selectItems = getSelectItems(context, checkbox);
final Converter