eclipse-ee4j / mojarra

Mojarra, a Jakarta Faces implementation
Other
166 stars 112 forks source link

EL: Empty values converted to null in version >= 4.0.7? #5486

Closed Toru47 closed 2 months ago

Toru47 commented 3 months ago

In version <= 4.0.1 empty values from Facelets eg. an empty parameter are converted to an empty string but not to null:

<f:viewAction action="#{fooBean.onload(param['test'])}" /> <!-- Parameter "test" not set! -->
public string onload(String test) { // test is an empty string but not null
}

In version >= 4.0.7 this is not the case:

public string onload(String test) { // test is null!!!
}

Is there a change? Is there an issue (number)? Tested with Wildfly 28 (4.0.1) and WildFly 33.0.1 (4.0.7). Thx.

BalusC commented 3 months ago

This is not Mojarra related. HttpServletRequest#getParameter() must return null when param is unspecified, so the behavior observed in WildFly 33.0.1 is correct. Most probably there was a change/fix in WildFly between 28 and 33. cc: @jasondlee

In Tomcat and GlassFish it also retrieves null.

BalusC commented 2 months ago

For more consistent and predictable behavior I recommend to use to set the request param as a bean property instead of using EL method argument passing. This way you're not dependent on potential bugs in the EL implementation.

<f:viewParam name="test" value="#{fooBean.test}" />
<f:viewAction action="#{fooBean.onload}" />
Toru47 commented 2 months ago

@BalusC: Many thanks for that advice.

BalusC commented 2 months ago

Closing off as not a Mojarra-caused problem.