#* * Copyright 2003-2004 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * $Id$ *# Struts App2: Struts View Tools Demo

Struts App2: Struts View Tools Demo

A demonstration of the Velocity view tools provided for Struts support. Where available, the Velocity shorthand notation to method calls is shown as well.

MessageTool

\$text.get("title")
\$text.title
$text.get("title")
\$text.get("test", ["bear", "dog", "cat"]) $text.get("test", ["bear", "dog", "cat"])
\$text.exists("tutle") $text.exists("tutle")

ErrorsTool

\$errors.exist() $errors.exist()
\$errors.exist("language") $errors.exist("language")
\$errors.getSize()
\$errors.size
$errors.getSize()
\$errors.getSize("language") $errors.getSize("language")
\$errors.getAll()
\$errors.all
[This is a String representation of the ArrayList that is returned]
$errors.getAll()
\$errors.get("language")
\$errors.language
[This is a String representation of the ArrayList that is returned]
$errors.get("language")
\$errors.getMsgs()
\$errors.texts
$errors.getMsgs()
\$errors.getMsgs("language") $errors.getMsgs("language")
A Velocity macro to render all error messages:
#macro (errorMarkup)
  #if ($errors.exist() )
    <ul>
    #foreach ($e in $errors.all )
      $e
    #end
    </ul>
  #end
#end
#errorMarkup()
A Velocity macro to render error messages specific
to a property:
#macro (errorMarkup $property)
  #if ($errors.exist($property))
    <ul>
    #foreach ($er in $errors.get($property))
      $er
    #end
    </ul>
  #end
#end
#errorMarkupForProperty("language")

FormTool

\$form.getBean()
\$form.bean
$form.getBean()
\$form.getCancelName()
\$form.cancelName
$form.getCancelName()
\$form.getTokenName()
\$form.tokenName
$form.getTokenName()
\$form.getToken()
\$form.token
$form.getToken()

StrutsLinkTool

\$link.setURI("template/login.vm") $link.setURI("template/login.vm")
\$link.setAction("demo") $link.setAction("demo")  
\$link.setForward("src") $link.setForward("src")  
\$link.setRelative("examples/index.html") $link.setRelative("examples/index.html")
\$link.setURI("index.html").addQueryData("key1", "val 1") $link.setURI("index.html").addQueryData("key1", "val 1")
\$link.setURI("index.html").addQueryData("key1", "val 1").getURI()
\$link.setURI("index.html").addQueryData("key1", "val 1").URI
$link.setURI("index.html").addQueryData("key1", "val 1").getURI()
\$link.setURI("/index.html").addQueryData("key1", "val 1").getQueryData()
\$link.setURI("/index.html").addQueryData("key1", "val 1").queryData
$link.setURI("/index.html").addQueryData("key1", "val 1").getQueryData()
\$link.getContextURL()
\$link.contextURL
$link.getContextURL()
\$link.getContextPath()
\$link.contextPath
$link.getContextPath()
\$link.getBaseRef()
\$link.baseRef
$link.getBaseRef()
\$link.setURI("index.vm").toString() $link.setURI("index.vm").toString()

ActionMessagesTool

\$messages.exist() $messages.exist()
\$messages.exist("foobar") $messages.exist("foobar")
\$messages.getSize()
\$messages.size
$messages.getSize()
\$messages.getSize("foobar") $messages.getSize("foobar")
\$messages.getAll()
\$messages.all
[This is a String representation of the ArrayList that is returned]
$messages.getAll()
\$messages.get("foobar")
\$messages.language
[This is a String representation of the ArrayList that is returned]
$messages.get("foobar")
A Velocity macro to render all actiontext messages:
#macro (messageMarkup)
  #if ($messages.exist() )
    <ul>
    #foreach ($m in $messages.all )
      $m
    #end
    </ul>
  #end
#end
#messageMarkup()
A Velocity macro to render actiontext messages specific
to a property:
#macro (messageMarkup $property)
  #if ($messages.exist($property))
    <ul>
    #foreach ($m in $messages.get($property))
      $m
    #end
    </ul>
  #end
#end
#messageMarkupForProperty("foobar")