The tag syntax in WebWork is extremely easy to understand. To quickly get started, all you need to know is that all attributes are applied as Strings initially. They are then parsed for the syntax %{ ... }, and anything in between the braces is evaluated against the value stack. Finally, the resulting String is either applied directly
Note | ||
---|---|---|
| ||
The tag syntax was not always this easy – if you are upgrading from WebWork 2.1.7 or previous versions, you may wish to read about the altSyntax. |
Like most things in life, it turns out that this isn't quite that simple. Specifically, there are actually three rules to be aware of:
- All String attribute types are parsed for the %{ ... } characters.
- All non-String attribute types are not parsed, but instead evaluated directly as an OGNL expression
- The exception to rule #2 is that if the non-String attribute starts with %{ and ends with }, those characters are cut off before evaluating the expression.
The best way to understand these rules is by looking at some examples.
Note |
---|
We recognize that these rules can be confusing. Generally, you should not need to know them at all, as 99.9% of the time everything will "just work". However, as we see in the examples, there are some tricky situations that require understanding of these rules. In future versions of WebWork, will be trying to make the tag syntax even simpler |
Some Examples
The most basic example explaining how the tag syntax works is as follows. This example shows off rule #1 only:
Code Block | ||||
---|---|---|---|---|
| ||||
<ww:textfield label="%{getText("state.label")}" name="state"/>
|
In this example, the label is dynamically evaluated and set to the outcome of the OGNL expression getText("state.label"), which will in turn invoke the Internationalization system are retrieve the value of the i18n key state.label. The name, being a String attribute, is simply set to the string state.
The next example is a bit more complicated,