Having a Spring ternary expression "Did he win the race? ${['win'] ? 'Yes.' : "No.'}"
, PlaceholderParser will break it into two parts.
1. TextPart - { text : "Did he win the race?" }
2. SimplePlaceholderPart - { key : "['win'] ? 'Yes.'", fallback : "'No.'", text : "['win'] ? "'Yes.' : 'No.'" }
But while resolving the SimplePlaceholderPart context, it returns the key
value of it which misses the fallback
part (PlaceholderParser.class : L376
).
Now, if try SpelExpression.doParseExpression("['win'] ? 'Yes.'")
, this.eatToken(TokenKind.COLON);(InternalSpelExpressionParser.class : L155)
will throw the exception.
Comment From: sbrannen
The ${...}
syntax is for a property placeholder, and the result you are getting seems to be appropriate.
If you intend for that be evaluated as a SpEL expression, you need to use the #{['win'] ? 'Yes.' : "No.'}
syntax.
Does switching to the #{...}
syntax solve your problem?
If not, what is it you are trying to achieve?
Comment From: Mitsuki0710
Unfortunately, #{...}
doesn't work.
We are using SpEL expression to parse the expression and replace placeholders with property values.
['win']
this will be replaced by a true
value from properties, and should return 'Yes.'
.
So the final result we are expecting is "Did he win the race? Yes.
Comment From: sbrannen
Does the following work for you?
"Did he win the race? #{${win} ? 'Yes.' : "No.'}"
Comment From: Mitsuki0710
"Did he win the race? #{${win} ? 'Yes.' : "No.'}"
has the following error
ERROR [main] [SpelPropertyResolver] EL1008E: Property or field 'win' cannot be found on object of type 'java.util.Properties' - maybe not public or not valid?ERROR [main] [SpelPropertyResolver] EL1008E: Property or field 'win' cannot be found on object of type 'java.util.Properties' - maybe not public or not valid?
If I wrap up with []
make it replaceable with property value
"Did he win the race? #{${[win]} ? 'Yes.' : "No.'}"
gets the following result:
Expected :Did he win the race? Yes.
Actual :Did he win the race? #{true ? 'Yes.' : 'No.'}
And I am constructing the property placeholder helper via PropertyPlaceholderHelper("${", "}", ":", null, true)
Comment From: sbrannen
Please provide a minimal sample application that demonstrates what you are trying to achieve, one that we can download and run ourselves, such as a public Git repository or a ZIP file.
Without that, I'm afraid we cannot determine if what you are trying to accomplish is supported.
Comment From: spring-projects-issues
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.
Comment From: spring-projects-issues
Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.