Search from Struts2 Library

Monday, September 22, 2008

If Else Tag

Not many languages, of any sort, fail to provide the familiar if and else control logic.The if and else tags provide these familiar friends for the Struts 2 developer. Using them is as easy as you might suspect. As you can see in table below, there’s just one attribute, a Boolean test.


Here’s an example of using them. You can put any OGNL expression you like in the test.

<s:if test="user.age > 35">This user is too old.</s:if> <s:elseif test="user.age < 35">This user is too young</s:elseif> <s:else>This user is just right</s:else>

Here we conduct a couple of tests on a user object exposed by our action and, ultimately,found on the ValueStack. The tests are simple Boolean expressions; you can
chain as many of the tests as you like.That was easy enough. Indeed, the if and else tags are as simple as they seem, and remain that way in use. We still have a few useful tags to cover, and we’ll hit them in the next section, which covers miscellaneous tags.

1 comment:

Asim said...

Multiple annotations found at this line:
- Start tag () not
closed.
- No end tag ().