Jodd comes with powerful JSP tag and JSP functions library. Here is the overview of most important tags.
Sets or unsets variable value in some scope. Scope can be one of: page (default), request, session and application. Example:
<j:set name="foo" value="173" scope="request"/>
${foo}
<j:set name="foo" scope="request"/>
Outputs parameter and attribute values from all scopes.
Tag for creating full URLs, context independent and with parameters encoded. Since Url tag uses dynamic attributes that represents url parameters, base path is set by tag parameter '_'. Additionally, it is possible to set page variable, instead to render url to the page. Example:
<j:url _="index.html" foo="something" id="173" /> may render as: /app/index.html?foo=something&id=173
<j:url _="hello.html" _var="u" boo="3" />
${u} may render as: /hello.html?boo=3
Renders the body if test condition is true. Example:
<j:if test="${foo > 10}">
greater then 10!
</j:if>Similar as If tag, except this one offers complete then and else blocks, that will be rendered if condition is true or false, respectivly. Example:
<j:ifelse test="${foo == 'hello'}">
<j:then>
Hello to you, too!
</j:then>
<j:else>
Please say hello:)
</j:else>
</j:ifelse>Offers switch/case/default functionality. Example:
<j:switch vale="${foo}">
<j:case value="One">
You are the first!
</j:case>
<j:case value="Two">
Second place for you!
</j:case>
<j:case value="Three">
And you are third,
</j:case>
<j:default>
Sorry, try again.
</j:default>
</j:switch>
Generic loop, like in Java. Supports looping in both directions. Like all looping tags, For tag has optional attribute status that defines status variable name. If specified, status is available inside looping tag body and provide various information about the current iteration:
start and end - first and last value;step - looping step, default 1;count - total count;even, odd and modulus - detects even and odd iterations; and value of modulus;index and value - 0-based and 1-based item of current iteration;first and last - flag for first and/or last iteration;Status object has custom toString() that gives complete status for iteration, what is useful for development.
For tag supports steps during looping. Moreover, setting step to 0 will notify Form tag to choose the correct direction, based on start and end values.
Example:
<j:for start="1" end="5" status="s" modulus="3">${s} | </j:for>
1:1:F:_:1 | 2:2:_:_:2 | 3:3:_:_:0 | 4:4:_:_:1 | 5:5:_:L:2 |
<j:for start="1" end="5" step="2" status="s">${s} | </j:for>
1:1:F:_:1 | 3:2:_:_:0 | 5:3:_:L:1 |
<j:for start="3" end="1" step="-1" status="s">${s} | </j:for>
3:1:F:_:1 | 2:2:_:_:0 | 1:3:_:L:1 |
<j:for start="1" end="3" step="0" status="s">${s} | </j:for>
1:1:F:_:1 | 2:2:_:_:0 | 3:3:_:L:1 |
<j:for start="3" end="1" step="0" status="s">${s} | </j:for>
3:1:F:_:1 | 2:2:_:_:0 | 1:3:_:L:1 |
Loop tag offers more enhanced looping then For tag. For example, it contains both end and to variables to defined loop end value, inclusive and not-inclusive. Moreover, instead of setting the end value (using end or to), it is possible to specify the count. Example:
<j:loop start="1" end="5" status="s">${s} | </j:loop>
1:1:F:_:1 | 2:2:_:_:0 | 3:3:_:_:1 | 4:4:_:_:0 | 5:5:_:L:1 |
<j:loop start="1" to="5" status="s">${s} | </j:loop>
1:1:F:_:1 | 2:2:_:_:0 | 3:3:_:_:1 | 4:4:_:L:0 |
<j:loop start="1" to="-1" step="-1" status="s">${s} | </j:loop>
1:1:F:_:1 | 0:2:_:L:0 |
<j:loop start="1" count="3" status="s">${s} | </j:loop>
1:1:F:_:1 | 2:2:_:_:0 | 3:3:_:L:1 |
<j:loop start="1" end="5" autoDirection="true" step="3" status="s">${s} | </j:loop>
1:1:F:_:1 | 4:2:_:L:0 |
<j:loop start="5" end="1" autoDirection="true" step="3" status="s">${s} | </j:loop>
5:1:F:_:1 | 2:2:_:L:0 |
Iterator iterates some collection or array. Iterator also can iterate a string that represents comma-separated array.
There are two optional attributes: from and count that determine starting index and total number of items to iterate. Example:
<j:iter items="1,2,3" var="i" status="s">${i} ${s} | </j:iter>
1 1:F:_:1 | 2 2:_:_:0 | 3 3:_:L:1 |
<j:iter items="1,2,3" var="i" from="2" status="s">${i} ${s} | </j:iter>
3 1:F:L:1 |
Form tag populates form automatically. Read more here.