on ‎2018 Dec 20 8:06 AM
Hi All,
Please help me to write the Spring EL for if else condition, specially for nested if.
I am trying to understand the following code. @priceService.getPriceInformationsForProduct(#item).![priceValue].?[currencyIso == #currency.isocode].![value]
But not really helping me. At least explain this expression conditions. This will be very helpful for me.
Request clarification before answering.
Probably the causes of your confusion are ! and ? in this expression. Please note that ! is not the logical operator in this expression; rather it has been used for Collection Projection. Please refer to the following example of Collection Projection at https://docs.spring.io/spring/docs/3.0.x/reference/expressions.html
Projection allows a collection to drive the evaluation of a sub-expression and the result is a new collection. The syntax for projection is ![projectionExpression]. Most easily understood by example, suppose we have a list of inventors but want the list of cities where they were born. Effectively we want to evaluate 'placeOfBirth.city' for every entry in the inventor list. Using projection:
// returns [ 'Smiljan', 'Idvor' ]
List placesOfBirth = (List)parser.parseExpression("Members.![placeOfBirth.city]");
Also, in your expression, ? has been used for Collection Selection and not as a part of the ternary operator. Please refer to the following example of Collection Selection at https://docs.spring.io/spring/docs/3.0.x/reference/expressions.html
Selection is a powerful expression language feature that allows you to transform some source collection into another by selecting from its entries.
Selection uses the syntax ?[selectionExpression]. This will filter the collection and return a new collection containing a subset of the original elements. For example, selection would allow us to easily get a list of Serbian inventors:
List<Inventor> list = (List<Inventor>)
parser.parseExpression("Members.?[Nationality == 'Serbian']").getValue(societyContext);
Feel free to let me know if you still have any problem understanding the expression you have mentioned in your question and I will be happy to explain it further.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you very much for the explanation.
Can you please help me for the following situation: Scenario: I have 3 custom Boolean attribute(Suppose isOne,isTwo,isThree) in my Product. So, I want the value provider using springELValueProvider for 3rd attribute , which will give the result depending on the first two attribute value. OR How can I write the springELValueProvider, If I want the result of isThree depending on the isOne value. OR How can I assign value of isOne attribute directly to the isThird attribute using springELValueProvider.
This will really help me to move further.
Thank you.
Hi Arvind,
Can you please help me for the following situation:
Scenario:
Product: attributes are , - 1)nameOne of type CustomType(code(string),Name(String))
-2)nameTwo of type Boolean
Now I want to compare the string value of code using springELValueProvider.
Example:if product.getNameOne.getCode == "Compare" then nameTwo value set to true.
Please guide me on the same.
| User | Count |
|---|---|
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.