类 BreadcrumbTool
- 所有已实现的接口:
Iterable<BreadcrumbTool.NavigationElement>
Helper tool to display a navigation breadcrumb to the end user.
It relies on the asumption that your URI hierarchy corresponds to the navigation hierarchy you want to present to your users, each level having its landing index page. Please note that this asumption is considered a *good practice*.
Each intermediate path element becomes a navigation element, and there is an additional ending navigation element when the page is not an index page.
For instance, if the URI is `/colors/red/nuances.html`, the provided path elements will be:
- 'colors', pointing towards '/colors/index.html'
- 'red', pointing towards '/colors/red/index.html'
- 'nuances', pointing towards '/colors/red/nuances.html'
The filename extension (`html` in the above example) is inferred from found URIs.
By default, the displayed name of a navigation element is the name of its corresponding path element with all
'_' replaced by spaces, transformed to lowercase.
You can customize this displayed name and the URL of every path element using tools properties:
tool key="breadcrumb" colors.name="My Colors" colors.url="/colors/all.vhtml"
where 'colors' refers to the /colors/ path element. The name and destination of the
root path element can be changed with 'home.name' and 'home.url'.
If you provide a name property prefixed with '?', the breadcrumb tool will use the value of the corresponding query parameter as navigation element name, and will keep this query parameter in the navigation element URL.
You can also define your own rules programmatically by subclassing BreadcrumbTool and override the
boolean customize(NavigationElement, HttpServletRequest) method, which will be called for every
navigation element. Returning false will skip this navigation element from the breadcrumb.
Inside a template, you would either render directly the default resulting HTML fragment with:
$breadcrumb
which would produce simething like:
<a href="/index.vhtml">home</a> > <a href="/colors/all.vhtml">My Colors</a> > nuances
or you would iterate through navigation elements for a better control of the output with:
div id="breadcrumb"
#foreach($element in $breadcrumb)
#if(!$foreach.first)
>
#end
#if(!$foreach.last)#end
$element.name
#if(!$foreach.last)#end
#end
div
And of course, you would supply the necessary CSS, for instance:
#breadcrumb { font-size: smaller; }
#breadcrumb a { color: #4183c4; text-decoration: none; }
#breadcrumb .divider { color: rgba(0, 0, 0, 0.4); vertical-align: baseline; margin: 0 0.2rem; }
- 从以下版本开始:
- 3.1
- 版本:
- $$
- 作者:
- Claude Brisson
-
嵌套类概要
嵌套类 -
字段概要
字段修饰符和类型字段说明protected List<BreadcrumbTool.NavigationElement>Navigation elements for the current URIprotected jakarta.servlet.http.HttpServletRequestCurrent request从类继承的字段 org.apache.velocity.tools.generic.LocaleConfig
DEFAULT_LOCALE从类继承的字段 org.apache.velocity.tools.generic.SafeConfig
LOCK_CONFIG_KEY, log, LOGGER_NAME_KEY, SAFE_MODE_KEY, USE_CLASS_LOGGER_KEY -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明protected voidconfigure(ValueParser config) Configurationprotected booleancustomize(BreadcrumbTool.NavigationElement navElem, jakarta.servlet.http.HttpServletRequest request) Let the user customize programmatically the name and URL of a specific element.protected StringformatElementName(String elem) Automatic default formatting of URI elementsprotected static StringgetExtension(String filename) Utility method to return URI file extensioniterator()Navigation elements iterationvoidsetRequest(jakarta.servlet.http.HttpServletRequest request) Current request settertoString()Default concatenation of navigation elements, separated by '>'从类继承的方法 org.apache.velocity.tools.generic.LocaleConfig
getLocale, setLocale, toLocale从类继承的方法 org.apache.velocity.tools.generic.SafeConfig
configure, getLog, initLogger, isConfigLocked, isSafeMode, setLockConfig, setSafeMode从类继承的方法 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait从接口继承的方法 java.lang.Iterable
forEach, spliterator
-
字段详细资料
-
request
protected jakarta.servlet.http.HttpServletRequest requestCurrent request
-
构造器详细资料
-
BreadcrumbTool
public BreadcrumbTool()
-
-
方法详细资料
-
setRequest
public void setRequest(jakarta.servlet.http.HttpServletRequest request) Current request setter- 参数:
request-
-
formatElementName
Automatic default formatting of URI elements -
configure
Configuration- 覆盖:
configure在类中LocaleConfig
-
iterator
Navigation elements iteration- 指定者:
iterator在接口中Iterable<BreadcrumbTool.NavigationElement>- 返回:
- Iterator over navigation elements
-
getExtension
Utility method to return URI file extension- 参数:
filename-- 返回:
-
toString
Default concatenation of navigation elements, separated by '>'
-