This page last changed on Dec 14, 2004 by plightbo.


These are tags that interact with the value stack, and control the logic of the page.

Tag Name Description
Common Tags
<ww:param /> Add parameters to tags that support it
<ww:property /> Fetches a value and prints it
<ww:push /> Add an object of your choice to the top of the value stack
<ww:set /> Create your own named variables
URL tag (<ww:url />) Builds an encoded URL
Componentisation Tags
<ww:action /> Provides another method to call Actions
<ww:bean /> Instantiate a bean that can be used to access functionality
<ww:include /> Used to include another page or action
Flow-Control Tags
<ww:if /> Used to determine if a statement is true or false
<ww:elseif /> Used to determine if a statement is true or false after a previous test.
<ww:else /> Used to determine if the preceding statement was false
Iteration Tags
<ww:iterator /> Iterate over a value
<ww:generator /> Create Iterator
<ww:append /> Append a list of iterators
<ww:subset /> Iterate over a portion of an iterable object
<ww:merge /> Merge several iterators into one
<ww:sort /> Sort an iterator

Common Tags

<ww:param />

Allows you to add parameters to tags that support adding parametric tags.
attribute requireddescription
valuenoThis attribute is used to pass data to the tag.
namenoThe name of the action to invoke.

You can place param tags within the body of parametric supporting tags and param will add its parameter to its parent. It evaluates the body as the value if no value is given.

In this example, each param will add its parameter to Counter. This means param will call Counter's appropriate setter method.

<ww:bean name="'webwork.util.Counter'" id="year">
  <ww:param name="'first'" value="text('firstBirthYear')"/>
  <ww:param name="'last'" value="2000"/>

  <ui:combobox label="'Birth year'" size="6" maxlength="4" name="'birthYear'" list="#year"/>
</ww:bean>


return to top

<ww:property />

The property tag fetches a value and prints it
attributerequireddescription
idnoThis attribute assigns a unique name to an element (note).
valuenoThis attribute is used to pass data to the tag.
escapenoDetermines if the contents should be escaped appropriately for valid HTML characters

Some examples will illustrate these different uses:
Print getX().getY() 
<ww:property value="x.y"/>

HTML characters will be escaped by default, whereas the contents of property tags with bodies will not be escaped. This behavior can be overridden by explicitly setting the escape attribute. Quoted text that is escaped will have its outer quotes stripped.

Note also that if the property tag has an empty body, it behaves the same as having no body and prints the value, though both spaces and carriage returns constitute nonempty content.


return to top

<ww:push />

Using ww:push, you can add an object of your choice to the top of the value stack.
attribute requireddescription
valueyesThis attribute is used to pass data to the tag.

This is similar to what you can do with ww:set (see below), so read both before deciding which to use.

<ww:push value="counter">
  <ww:property value="count"/>
</ww:push>

To make an action available on the stack:

<ww:action name="'SomeAction'" id="sa"/>
<ww:push value="#sa">
 foo = <ww:property value="foo"/>
</ww:push>


return to top

<ww:set />

You can create your own named variables from within a JSP using the ww:set tag. Reference your variable later using the # variableName notation.
attribute requireddescription
name yesUnique name for the variable, accessed as "#name".
valuenoThis attribute is used to pass data to the tag.
scopenoScope of the variable: page, request, session, application

Sets the value of an object in the VS to a scope. If the value is not given, the top of the stack is used. If the scope is not given, the default scope is the action context which is only available in the PageContext if no action has been executed on the same request.

Componentisation Tags

return to top

<ww:action />

Action tag provides another method to call Actions. This is an alternative way to invoke an action besides calling an url; i.e. - *.action that would be sent to the ServletDispatcher.

attribute requireddescription
idnoThis attribute assigns a unique name to an element (note).
nameyesThe name of the action to invoke.
namespace no Namespace of this action
executeResult no Whether to execute result

If the id attribute is given, the executed action is assigned a name reference that can be later retrieved from the context "#id".

In this example, the ClientInfo action will be executed and its methods will be used to retrieve information and perform a conditional test.
<ww:action name="'ClientInfo'" id="cinfo">
  <ww:param name="detailedMode" value="false"/>
</ww:action>
Browser:<ww:property value="#cinfo.browser"/><br>
Version:<ww:property value="#cinfo.version"/><br>
Supports GIF:<ww:if test="#cinfo.supportsType('image/gif') == true">Yes</ww:if>
<ww:else>No</ww:else><br>
 

return to top

<ww:bean />

Create a JavaBean and instantiate its properties. It is then placed in the ActionContext for later use.
attribute requireddescription
idnoThis attribute assigns a unique name to an element (note).
nameyesThe name of the action to invoke.

In this example, Counter is used as a bean. We can now call the methods we desire. In this case, we setFirst() to first birth year which is 1975 and we setLast() to 2000. We then display a combo box using Counter as an Iterator.
<ww:bean name="'webwork.util.Counter'" id="year">
  <ww:param name="'first'" value="text('firstBirthYear')"/>
  <ww:param name="'last'" value="2000"/>

  <ui:combobox label="'Birth year'" size="6" maxlength="4" name="'birthYear'" list="#year"/>
</ww:bean>

return to top

<ww:include />

Used to include another page or action.
attribute requireddescription
page noName of page or action.
valuenoThis attribute is used to pass data to the tag.

In this example, beaninfo.jsp will introspec on people[0] which is a Person. Take a look at beaninfo.jsp example and notice how it retrieves the parent value off the ValueStack with "..".

<ww:property value="people[0]">
  <ww:include value="'beaninfo.jsp'"/>
</ww:property>

In this example, an Action is invoked.
<h1>RSS viewer</h1>
<ww:include value="'rss.viewer.action'"/>

Flow Control Tags

return to top

<ww:if />

Used to determine if a statement is true or false.
attribute requireddescription
idnoThis attribute assigns a unique name to an element (note).
testyesThis attribute is the conditional expression evaluated by WW's parser. It returns boolean true or false.

In this example, if will evaluate its body since the test condition is true. elseIf and else will not evaluate.
<ww:if test="true == true">
   <b>if: Success</b>
</ww:if>

<ww:elseIf test="true == true">
   <b>elseIf: Failure</b>
</ww:elseIf>

<ww:else>
   <b>else: Failure</b>
</ww:else>

return to top

<ww:elseif />

Used to determine if a statement is true or false after a previous test.
attribute requireddescription
idnoThis attribute assigns a unique name to an element (note).
testyesThis attribute is the conditional expression evaluated by WW's parser. It returns boolean true or false.

In this example, elseIf will evaluate its body since its test condition is true and if is false.

<ww:if test="true == false">
   <b>if: Failures</b>
</ww:if>

<ww:elseIf test="true == true">
   <b>elseIf: Success</b>
</ww:elseIf>

<ww:else>
   <b>else: Failure</b>
</ww:else>

return to top

<ww:else />

Used to determine if the preceding statement was false.
attribute requireddescription
idnoThis attribute assigns a unique name to an element (note).

In this exmaple, else will evaluate its body since both if and elseIf conditions are false.
<ww:if test="true == false">
   <b>if: Failures</b>
</ww:if>

<ww:elseIf test="true == false">
   <b>elseIf: Failure</b>
</ww:elseIf>

<ww:else>
   <b>else: Success</b>
</ww:else>

Iteration Tags

return to top

<ww:iterator />

Iterator will iterate over a value. An iterable value can be either of: java.util.Collection, java.util.Iterator, java.util.Enumeration, java.util.Map, array, XML Node, or XML NodeList.

attribute requireddescription
idnoThis attribute assigns a unique name to an element (note).
statusnoThis attribute indicates the name of the IteratorStatus object to be exposed. An IteratorStatus allows one to get information about the status of the iteration: getCount(), getIndex(), isFirst(), isLast(), isEven(), isOdd().
valuenoThis attribute is used to pass data to the tag.

In this example, iterator will iterate over Counter. property will output the current value which is 1 through 10.
<ww:bean name="'webwork.util.Counter'">
  <ww:param name="'last'" value="10"/>

  <ww:iterator>
    <ww:property/><br />
  </ww:iterator>
</ww:bean>

In this example, we use a couple of IteratorStatus to see where we are within iterations.

<h1>Testing iterator status</h1>

<ww:bean name="'webwork.util.Counter'" id="rowcounter">
  <ww:param name="'first'" value="0"/>
  <ww:param name="'last'" value="5"/>
</ww:bean>

<table border="1">
  <ww:iterator value="#rowcounter" status="rowstatus">
  <tr>
    <ww:bean name="'webwork.util.Counter'" id="colcounter">
    	<ww:param name="'first'" value="0"/>
    	<ww:param name="'last'" value="5"/>
    </ww:bean>
    
    <ww:iterator value="#colcounter" status="colstatus">
     <!--
        if it is (first row) or (first column) or (last row) then
        output the column number.
      -->
      <ww:if test="#rowstatus.first==true || #colstatus.first==true || #rowstatus.last==true">
        <th><ww:property value="#colstatus.count"/></th>
      </ww:if>
      
      <ww:else>
        <td><ww:property/></td>
      </ww:else>
      
    </ww:iterator>

  </tr>
  </ww:iterator>
</table>

Here we use the IteratorStatus determine every other row to insert an extra line break. This is very useful for shading alternate rows in an HTML table. Both even and odd attributes are available.

<ww:iterator status="status">
   <ww:if test="#status.odd == true"> <br /> </ww:if>
   <br />
</ww:iterator> 

Here we use the IteratorStatus determine every fourth row to insert an extra line break. 
<ww:iterator status="status">
  <ww:if test="#status.modulus(4) == 0"> <br /> </ww:if>
  <br />
</ww:iterator>

Following are the list of operations available on the status object:

  • even : boolean - returns true if the current iteration is even
  • odd : boolean - returns true if the current iteration is odd
  • count : int - returns the count (1 based) of the current iteration
  • index : int - returns the index (0 based) of the current iteration
  • first : boolean - returns true if the iterator is on the first iteration
  • last : boolean - returns true if the iteration is on the last iteration
  • modulus(operand : int) : int - returns the current count (1 based) modulo the given operand

return to top

<ww:generator />

Generate will create Iterators from val.

attribute requireddescription
idnoThis attribute assigns a unique name to an element (note).
countnoThis attribute indicates how many items there are.
separatornoThis attribute is the character the StringTokenizer will use to create tokens.
valyesThis attribute is the list of values the generator should use to create tokens.

In this example, two Iterators are created. One for val="'foo,bar,xyzzy'" and the other for val="' '".

<h1>Testing append, subset, and value generators</h1>

<table border="1">
  <ww:bean name="'webwork.util.Counter'">
    <ww:param name="'last'" value="5"/>
    <ww:iterator id="colcount">
      <tr>

        <!--
           Generator will create an Iterator that has 5 items.
           The first 3 are "foo,bar,xyzzy". Item 4 and 5 will be
           foo and bar respectively. If the count is more than
           the items, you start over.
        -->
        
        <ww:generator val="'foo,bar,xyzzy'" separator="','" count="#colcount" id="values"/>

       <!--
           Generator will create an Iterator that has infinite
            . Count=-1 means indefinite.
        -->
        <ww:generator val="' '" count="-1" id="space"/>
        <ww:append>
          <ww:param name="'source'" value="#values"/>
          <ww:param name="'source'" value="#space"/>

          <ww:subset count="6">
            <ww:iterator>
              <td width="40"><ww:property/></td>
            </ww:iterator>
          </iterator:subset>
        </iterator:append>
      </tr>
    </ww:iterator>
  </ww:bean>
</table>

This tag is mostly superfluous, now that we can do this in OGNL:

<ww:iterator value="{1, 2, 3, 4}">
</ww:iterator>

return to top

<ww:append />

Append will append a list of iterators. The values of the iterators will be appended and treated as one iterator. The outputs from the iterator will be in the sequence the sources were added.

attribute requireddescription
idnoThis attribute assigns a unique name to an element (note).

In this example, the two iterators #values and #spaces are appended. This means #spaces values are after #values.

<h1>Testing append, subset, and value generators</h1>

<table border="1">
  <ww:bean name="'webwork.util.Counter'">
    <ww:param name="'last'" value="5"/>
    <ww:iterator id="colcount">
      <tr>
        <ww:generator val="'foo,bar,xyzzy'" separator="','" count="#colcount" id="values"/>
        <ww:generator val="' '" count="-1" id="space"/>
        <ww:append>
          <ww:param name="'source'" value="#values"/>
          <ww:param name="'source'" value="#space"/>

          <ww:subset count="6">
            <ww:iterator>
              <td width="40"><ww:property/></td>
            </ww:iterator>
          </iterator:subset>
        </iterator:append>
      </tr>
    </ww:iterator>
  </ww:bean>
</table>

return to top

<ww:subset />

Subset will iterate over a portion of its source. It will start at start and continue for count. You can set count to -1 if you want to iterate until the end of source. If you do not supply a source, the current object on the ValueStack- "." will be used.
attribute requireddescription
idnoThis attribute assigns a unique name to an element (note).
countnoThis attribute indicates how many items there are.
sourcenoThis attribute is the source the tag will use to perform work on. It may be Enumeration, Iterator, or a Collection.
startnoThis attribute indicates the index to start reading.

In this example, subset will iterate over 6 items for the current object in the ValueStack.

<h1>Testing append, subset, and value generators</h1>

<table border="1">
  <ww:bean name="'webwork.util.Counter'">
    <ww:param name="'last'" value="5"/>
    <ww:iterator id="colcount">
    <tr>
      <ww:generator val="'foo,bar,xyzzy'" separator="','" count="#colcount" id="values"/>
      <ww:generator val="' '" count="-1" id="space"/>
      <ww:append>
        <ww:param name="'source'" value="#values"/>
        <ww:param name="'source'" value="#space"/>

        <ww:subset count="6">
          <ww:iterator>
            <td width="40"><ww:property/></td>
          </ww:iterator>
        </iterator:subset>
      </iterator:append>
      </tr>
    </ww:iterator>
  </ww:bean>
</table>

return to top

<ww:merge />

Merge several iterators into one. It weaves them together. If one iterator runs out, it will drop off and the others will continue weaving until there are no more values.
attribute requireddescription
idnoThis attribute assigns a unique name to an element (note).

In this example, #foo, #bar, and #xyzzy iterators are merged together. So, the output will be foo, bar, xyzzy until #foo and #xyzzy iterators run out in which case #bar will finish.

Three value generators with merge and subset limits:<br>
<ww:generator val="'foo'" count="5" id="foo"/>
<ww:generator val="'bar'" count="10" id="bar"/>
<ww:generator val="'xyzzy'" count="5" id="xyzzy"/>
<ww:merge>
  <ww:param name="'source'" value="#foo"/>
  <ww:param name="'source'" value="#bar"/>
  <ww:param name="'source'" value="#xyzzy"/>

  <ww:subset count="30">
    <ww:iterator status="status">
      <ww:property value="#status.count"/>:<ww:property/><br>
    </ww:iterator>
  </iterator:subset>
</iterator:merge>

return to top

<ww:sort />

Sort allows you to sort an iterator. It uses Collections.sort() given the comparator you supply.
attribute requireddescription
idnoThis attribute assigns a unique name to an element (note).
comparatoryesThis attribute will be the Comparator used to sort the Collection.
sourcenoThis attribute is the source the tag will use to perform work on. It may be Enumeration, Iterator, or a Collection.

In this example, we sort ascending.

<ww:bean name="'webwork.util.Counter'" id="counter">
  <ww:param name="'first'" value="0"/>
  <ww:param name="'last'" value="5"/>
</ww:bean>

<ww:bean name="'webwork.util.Sorter'" id="sorter"/>

Ascending:<br />
<ww:sort source="#counter" comparator="#sorter.ascending">
  <ww:iterator>
    <ww:property/><br />
  </ww:iterator>
</iterator:sort>

In this example, we sort descending.

<ww:bean name="'webwork.util.Sorter'" id="sorter"/>

<ww:bean name="'webwork.util.Counter'" id="counter">
  <ww:param name="'first'" value="0"/>
  <ww:param name="'last'" value="5"/>
</ww:bean>

Descending:<br>
<ww:sort source="#counter" comparator="#sorter.descending">
  <ww:iterator>
    <ww:property/><br>
  </ww:iterator>
</iterator:sort>

In this example, we sort ascending over strings.

<ww:bean name="'webwork.util.Sorter'" id="sorter"/>

Sorting strings:<br>
<ww:generator val="'Rickard,Maurice,Hristo'" separator="','" id="names"/>
<ww:sort source="#names" comparator="#sorter.ascending">
  <ww:iterator>
    <ww:property/><br>
  </ww:iterator>
</iterator:sort>

Notes


 Id The "id" attribute assigns a name to an element. This name must be unique in a document. This attribute is the standard id supported by JSP TagSupport and is therefore always a string. You do not need to indicate a string literal as you would for the rest of WW attributes; i.e. - id="'age'". Instead you should use id="age".


It's very important to note that all tags that insert something into the valuestack (like i18n or bean tags) will remove those objects from the stack on its end tag.
So, if you instantiate a bean with the bean tag (<ww:bean name="'br.univap.fcc.sgpw.util.FormattersHelper'">) that bean will be avaliable on the valuestack only until the </ww:bean> tag.
Document generated by Confluence on Dec 14, 2004 16:36