JSF 2.2 interprets empty strings represented by null, does not work

I switched from Java EE 6 to Java EE 7, and now with JSF 2.2 the param context INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL does not seem to work. In JSF 2.1, I set it to β€œtrue” and it works fine, but now I get always empty lines.

 <context-param> <param-name>javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL</param-name> <param-value>true</param-value> </context-param> 

Can anyone say something about this?

+6
source share
6 answers

The same thing happens with glassfish 4 with the latest mojarra-2.2.5 as well as Wildfly 8 Final., I saw several bug reports, Manfried Riem says: β€œIt was determined that this is an EL problem, and it was fixed to implement this fix EL implementation ", but not sure if this means that the Mojarra update fixes it because it is not in glassfish 4. I also updated el, and that didn't work either.

+6
source

Unfortunately, there is a bug in Glassfish 4.

Cm:

* INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL does not work at all * https://java.net/jira/browse/JAVASERVERFACES-3071

and

An empty string as Null does not work in 2.2.0 https://java.net/jira/browse/JAVASERVERFACES_SPEC_PUBLIC-1203

+3
source

The implementation of Apache el executes an empty string (or a value of 0 int). You can find it in the class org.apache.el.parser.AstValue:

 public void setValue(EvaluationContext ctx, Object value) throws ELException { Target t = getTarget(ctx); ctx.setPropertyResolved(false); ELResolver resolver = ctx.getELResolver(); // coerce to the expected type Class<?> targetClass = resolver.getType(ctx, t.base, t.property); if (COERCE_TO_ZERO == true || !isAssignable(value, targetClass)) { resolver.setValue(ctx, t.base, t.property, ELSupport.coerceToType(value, targetClass)); } else { resolver.setValue(ctx, t.base, t.property, value); } if (!ctx.isPropertyResolved()) { throw new PropertyNotFoundException(MessageFactory.get( "error.resolver.unhandled", t.base, t.property)); } } 

You can set COERCE_TO_ZERO to false (-Dorg.apache.el.parser.COERCE_TO_ZERO = false).

Or use other el impl:

  <dependency> <groupId>org.glassfish.web</groupId> <artifactId>el-impl</artifactId> <version>2.2</version> </dependency> 

And set context-param:

  servletContext.setInitParameter("com.sun.faces.expressionFactory", "com.sun.el.ExpressionFactoryImpl"); 

That was the el-api side.

The other side is JSF. You must set this parameter parameter for JSF:

 servletContext.setInitParameter("javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL", "true"); 

Sorry for my English!

+1
source

Things are even more confusing. I am using JSF 2.2.8-SNAPSHOT, and although the value during the JSF bean check is interpreted as null, the actual set value is an empty string. This means that other components performing the check, for example, Checking the length of the JPA error, because the String value is "".

Because it seems, requires spec change , I would not expect this in the near future. jira also contains a workaround described in this post.

Ps. This may be the correct behavior, as the documentation claims that null is passed to the w810 check structure, but it is completely unintuitive.

0
source

There is a JVM property for the application server, which helped me in a similar case. See Handle INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL Errors in Mojarra JSF 2.1

0
source

I tried below and got the job. we need to add this entry to web.xml

 <context-param> <param-name>javax.faces.VALIDATE_EMPTY_FIELDS</param-name> <param-value>true</param-value> </context-param> 
-1
source

Source: https://habr.com/ru/post/956672/


All Articles