Skip to content

Commit

Permalink
4.1.2 release
Browse files Browse the repository at this point in the history
Signed-off-by: pizzi80 <[email protected]>
  • Loading branch information
pizzi80 committed Jun 26, 2023
1 parent 812106b commit 74fc42f
Show file tree
Hide file tree
Showing 3 changed files with 237 additions and 101 deletions.
2 changes: 1 addition & 1 deletion impl/src/main/java/com/sun/faces/context/RequestMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void clear() {

// Supported by maps if overridden
@Override
public void putAll(Map<? extends String, ?> t) {
public void putAll(Map t) {
for (Iterator i = t.entrySet().iterator(); i.hasNext();) {
Map.Entry entry = (Map.Entry) i.next();
request.setAttribute((String) entry.getKey(), entry.getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,31 @@

package com.sun.faces.el;

import java.beans.FeatureDescriptor;
import java.util.Iterator;

import jakarta.el.ELContext;
import jakarta.el.ELResolver;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

// if ( String.class == targetType && context instanceof org.apache.el.lang.EvaluationContext ) // && context instanceof com.sun.faces.el.ELContextImpl
// System.out.println("value:["+value+"] - targetType:["+targetType+"]" + " {"+context+"}");

// NOTA: la soluzione proposta da BalusC ad oggi crea dei malfunzionamenti a JSF durante la valutazione di espressioni EL
// ad esempio se faccio #{'hello'.concat(null)} darebbe errore perché null verrebbe trattato appunto come null e String.concat(null)
// lancia un NullPointer, invece EL fa una conversione null -> '' e ti salva la vita

// Invece per ottenere il comportamento desiderato in fase di input
// sembra che EL-context in questione sia EvaluationContext
public class EmptyStringToNullELResolver extends ELResolver {

static final String EVALUATION_CONTEXT_CLASS_NAME = "EvaluationContext";

static final Map<Class<? extends ELContext>,Boolean> isEvaluationContextCache = new ConcurrentHashMap<>();

static boolean isEvaluationContext( ELContext context ) {
return isEvaluationContextCache.computeIfAbsent( context.getClass() , clazz -> clazz.getName().endsWith(EVALUATION_CONTEXT_CLASS_NAME) );
}

@Override
public Class<?> getCommonPropertyType(ELContext context, Object base) {
return String.class;
Expand All @@ -32,18 +49,18 @@ public Class<?> getCommonPropertyType(ELContext context, Object base) {
@Override
@SuppressWarnings("unchecked")
public <T> T convertToType(ELContext context, Object value, Class<T> targetType) {
if (value == null && targetType == String.class) {

if ( value == null &&
targetType == String.class &&
isEvaluationContext(context) ) {

context.setPropertyResolved(true);
//return (T) null;
}

return (T) value;
}

@Override
public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context, Object base) {
return null;
}

@Override
public Class<?> getType(ELContext context, Object base, Object property) {
return null;
Expand Down
Loading

0 comments on commit 74fc42f

Please sign in to comment.