
org.primefaces.el.ValueExpressionStateHelper Maven / Gradle / Ivy
/*
* The MIT License
*
* Copyright (c) 2009-2025 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.el;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.function.Supplier;
import javax.el.ValueExpression;
import javax.faces.component.StateHelper;
import javax.faces.context.FacesContext;
public class ValueExpressionStateHelper implements StateHelper {
private static final Object UNKNOWN_VALUE = new Object();
protected Map literals;
protected Map bindings;
private boolean transientFlag;
@Override
public Object put(Serializable key, Object value) {
if (literals == null) {
literals = new HashMap<>(3);
}
return literals.put(String.valueOf(key), value);
}
@Override
public Object remove(Serializable key) {
Object previous = eval(key);
if (literals != null) {
literals.remove(String.valueOf(key));
}
if (bindings != null) {
bindings.remove(String.valueOf(key));
}
return previous;
}
@Override
public Object put(Serializable key, String mapKey, Object value) {
Map internalMap = (Map) get(key);
if (internalMap == null) {
internalMap = new HashMap<>(3);
put(key, internalMap);
}
return internalMap.put(mapKey, value);
}
@Override
public Object get(Serializable key) {
if (literals == null) {
return null;
}
return literals.get(String.valueOf(key));
}
@Override
public Object eval(Serializable key) {
return eval(key, null);
}
@Override
public Object eval(Serializable key, Object defaultValue) {
Object literal = get(String.valueOf(key));
if (literal != null) {
return literal;
}
if (bindings == null) {
return defaultValue;
}
ValueExpression ve = bindings.get(String.valueOf(key));
if (ve == null) {
return defaultValue;
}
return ve.getValue(FacesContext.getCurrentInstance().getELContext());
}
// @Override (we can't actually override right now because this is a new method in Faces 4.0)
public Object eval(Serializable key, Supplier
© 2015 - 2025 Weber Informatics LLC | Privacy Policy