...
- To review basic concepts, refer to OGNL Basics
- #Collections
- Lambda Expressions
Collections (Maps, Lists, Sets)
...
...
Dealing with collections(maps, lists, and sets) in webwork comes often, so here are a few examples using the select tag:
Syntax for list: {e1,e2}. This creates a List containing the String "name1" and "name2".
Code Block | ||||
---|---|---|---|---|
| ||||
<webwork:select label="'lebal'" name="'nmae'" list="{'name1','name2'}" /> |
Syntax for map: #{key1:value1,key2:value2}. This creates a map that maps the string "foo" to the string "foovalue" and "bar" to the string "barvalue":
Code Block | ||||
---|---|---|---|---|
| ||||
<webwork:select label="'lebal'" name="'nmae'" list="#{'foo':'foovalue', 'bar':'barvalue'}" /> |
You may need to determine if an element exists in a collection. You can accomplish this with the operations in
and not in
Code Block | ||||
---|---|---|---|---|
| ||||
<ui:if test="'foo' in {'foo','bar'}"> muhahaha </ui:if> <ui:else> boo </ui:else> <ui:if test="'foo' not in {'foo','bar'}"> muhahaha </ui:if> <ui:else> boo </ui:else> |
...
To obtain a subset of just male relatives from the object person:
Code Block | ||||
---|---|---|---|---|
| ||||
person.relatives.{? #this.gender == 'male'} |
Lambda Expressions
...
...
OGNL supports basic lamba expression syntax enabling you to write simple functions.
...
The lambda expression is everything inside the brackets. The #this variable holds the argument to the expression, which is initially starts at 11.
Code Block | ||||
---|---|---|---|---|
| ||||
<ww:property value="#fib =:[#this==0 ? 0 : #this==1 ? 1 : #fib(#this-2)+#fib(#this-1)], #fib(11)" /> |