spring.ftl

2023-10-31

<#ftl strip_whitespace=true>
<#--
 * spring.ftl
 *
 * This file consists of a collection of FreeMarker macros aimed at easing
 * some of the common requirements of web applications - in particular
 * handling of forms.
 *
 * Spring's FreeMarker support will automatically make this file and therefore
 * all macros within it available to any application using Spring's
 * FreeMarkerConfigurer.
 *
 * To take advantage of these macros, the "exposeSpringMacroHelpers" property
 * of the FreeMarker class needs to be set to "true". This will expose a
 * RequestContext under the name "springMacroRequestContext", as needed by
 * the macros in this library.
 *
 * @author Darren Davison
 * @author Juergen Hoeller
 * @since 1.1
 -->

<#--
 * message
 *
 * Macro to translate a message code into a message.
 -->
<#macro message code>${springMacroRequestContext.getMessage(code)}</#macro>

<#--
 * messageText
 *
 * Macro to translate a message code into a message,
 * using the given default text if no message found.
 -->
<#macro messageText code, text>${springMacroRequestContext.getMessage(code, text)}</#macro>

<#--
 * messageArgs
 *
 * Macro to translate a message code with arguments into a message.
 -->
<#macro messageArgs code, args>${springMacroRequestContext.getMessage(code, args)}</#macro>

<#--
 * messageArgsText
 *
 * Macro to translate a message code with arguments into a message,
 * using the given default text if no message found.
 -->
<#macro messageArgsText code, args, text>${springMacroRequestContext.getMessage(code, args, text)}</#macro>

<#--
 * theme
 *
 * Macro to translate a theme message code into a message.
 -->
<#macro theme code>${springMacroRequestContext.getThemeMessage(code)}</#macro>

<#--
 * themeText
 *
 * Macro to translate a theme message code into a message,
 * using the given default text if no message found.
 -->
<#macro themeText code, text>${springMacroRequestContext.getThemeMessage(code, text)}</#macro>

<#--
 * themeArgs
 *
 * Macro to translate a theme message code with arguments into a message.
 -->
<#macro themeArgs code, args>${springMacroRequestContext.getThemeMessage(code, args)}</#macro>

<#--
 * themeArgsText
 *
 * Macro to translate a theme message code with arguments into a message,
 * using the given default text if no message found.
 -->
<#macro themeArgsText code, args, text>${springMacroRequestContext.getThemeMessage(code, args, text)}</#macro>

<#--
 * url
 *
 * Takes a relative URL and makes it absolute from the server root by
 * adding the context root for the web application.
 -->
<#macro url relativeUrl>${springMacroRequestContext.getContextPath()}${relativeUrl}</#macro>

<#--
 * bind
 *
 * Exposes a BindStatus object for the given bind path, which can be
 * a bean (e.g. "person") to get global errors, or a bean property
 * (e.g. "person.name") to get field errors. Can be called multiple times
 * within a form to bind to multiple command objects and/or field names.
 *
 * This macro will participate in the default HTML escape setting for the given
 * RequestContext. This can be customized by calling "setDefaultHtmlEscape"
 * on the "springMacroRequestContext" context variable, or via the
 * "defaultHtmlEscape" context-param in web.xml (same as for the JSP bind tag).
 * Also regards a "htmlEscape" variable in the namespace of this library.
 *
 * Producing no output, the following context variable will be available
 * each time this macro is referenced (assuming you import this library in
 * your templates with the namespace 'spring'):
 *
 *   spring.status : a BindStatus instance holding the command object name,
 *   expression, value, and error messages and codes for the path supplied
 *
 * @param path : the path (string value) of the value required to bind to.
 *   Spring defaults to a command name of "command" but this can be overridden
 *   by user config.
 -->
<#macro bind path>
    <#if htmlEscape?exists>
        <#assign status = springMacroRequestContext.getBindStatus(path, htmlEscape)>
    <#else>
        <#assign status = springMacroRequestContext.getBindStatus(path)>
    </#if>
    <#-- assign a temporary value, forcing a string representation for any
    kind of variable. This temp value is only used in this macro lib -->
    <#if status.value?exists && status.value?is_boolean>
        <#assign stringStatusValue=status.value?string>
    <#else>
        <#assign stringStatusValue=status.value?default("")>
    </#if>
</#macro>

<#--
 * bindEscaped
 *
 * Similar to spring:bind, but takes an explicit HTML escape flag rather
 * than relying on the default HTML escape setting.
 -->
<#macro bindEscaped path, htmlEscape>
    <#assign status = springMacroRequestContext.getBindStatus(path, htmlEscape)>
    <#-- assign a temporary value, forcing a string representation for any
    kind of variable. This temp value is only used in this macro lib -->
    <#if status.value?exists && status.value?is_boolean>
        <#assign stringStatusValue=status.value?string>
    <#else>
        <#assign stringStatusValue=status.value?default("")>
    </#if>
</#macro>

<#--
 * formInput
 *
 * Display a form input field of type 'text' and bind it to an attribute
 * of a command or bean.
 *
 * @param path the name of the field to bind to
 * @param attributes any additional attributes for the element (such as class
 *    or CSS styles or size
 -->
<#macro formInput path attributes="" fieldType="text">
    <@bind path/>
    <input type="${fieldType}" id="${status.expression}" name="${status.expression}" value="<#if fieldType!="password">${stringStatusValue}</#if>" ${attributes}<@closeTag/>
</#macro>

<#--
 * formPasswordInput
 *
 * Display a form input field of type 'password' and bind it to an attribute
 * of a command or bean. No value will ever be displayed. This functionality
 * can also be obtained by calling the formInput macro with a 'type' parameter
 * of 'password'.
 *
 * @param path the name of the field to bind to
 * @param attributes any additional attributes for the element (such as class
 *    or CSS styles or size
 -->
<#macro formPasswordInput path attributes="">
    <@formInput path, attributes, "password"/>
</#macro>

<#--
 * formHiddenInput
 *
 * Generate a form input field of type 'hidden' and bind it to an attribute
 * of a command or bean. This functionality can also be obtained by calling
 * the formInput macro with a 'type' parameter of 'hidden'.
 *
 * @param path the name of the field to bind to
 * @param attributes any additional attributes for the element (such as class
 *    or CSS styles or size
 -->
<#macro formHiddenInput path attributes="">
    <@formInput path, attributes, "hidden"/>
</#macro>

<#--
 * formTextarea
 *
 * Display a text area and bind it to an attribute of a command or bean.
 *
 * @param path the name of the field to bind to
 * @param attributes any additional attributes for the element (such as class
 *    or CSS styles or size
 -->
<#macro formTextarea path attributes="">
    <@bind path/>
    <textarea id="${status.expression}" name="${status.expression}" ${attributes}>${stringStatusValue}</textarea>
</#macro>

<#--
 * formSingleSelect
 *
 * Show a selectbox (dropdown) input element allowing a single value to be chosen
 * from a list of options.
 *
 * @param path the name of the field to bind to
 * @param options a map (value=label) of all the available options
 * @param attributes any additional attributes for the element (such as class
 *    or CSS styles or size
-->
<#macro formSingleSelect path options attributes="">
    <@bind path/>
    <select id="${status.expression}" name="${status.expression}" ${attributes}>
        <#if options?is_hash>
            <#list options?keys as value>
            <option value="${value?html}"<@checkSelected value/>>${options[value]?html}</option>
            </#list>
        <#else>
            <#list options as value>
            <option value="${value?html}"<@checkSelected value/>>${value?html}</option>
            </#list>
        </#if>
    </select>
</#macro>

<#--
 * formMultiSelect
 *
 * Show a listbox of options allowing the user to make 0 or more choices from
 * the list of options.
 *
 * @param path the name of the field to bind to
 * @param options a map (value=label) of all the available options
 * @param attributes any additional attributes for the element (such as class
 *    or CSS styles or size
-->
<#macro formMultiSelect path options attributes="">
    <@bind path/>
    <select multiple="multiple" id="${status.expression}" name="${status.expression}" ${attributes}>
        <#list options?keys as value>
        <#assign isSelected = contains(status.value?default([""]), value)>
        <option value="${value?html}"<#if isSelected> selected="selected"</#if>>${options[value]?html}</option>
        </#list>
    </select>
</#macro>

<#--
 * formRadioButtons
 *
 * Show radio buttons.
 *
 * @param path the name of the field to bind to
 * @param options a map (value=label) of all the available options
 * @param separator the html tag or other character list that should be used to
 *    separate each option. Typically '&nbsp;' or '<br>'
 * @param attributes any additional attributes for the element (such as class
 *    or CSS styles or size
-->
<#macro formRadioButtons path options separator attributes="">
    <@bind path/>
    <#list options?keys as value>
    <#assign id="${status.expression}${value_index}">
    <input type="radio" id="${id}" name="${status.expression}" value="${value?html}"<#if stringStatusValue == value> checked="checked"</#if> ${attributes}<@closeTag/>
    <label for="${id}">${options[value]?html}</label>${separator}
    </#list>
</#macro>

<#--
 * formCheckboxes
 *
 * Show checkboxes.
 *
 * @param path the name of the field to bind to
 * @param options a map (value=label) of all the available options
 * @param separator the html tag or other character list that should be used to
 *    separate each option. Typically '&nbsp;' or '<br>'
 * @param attributes any additional attributes for the element (such as class
 *    or CSS styles or size
-->
<#macro formCheckboxes path options separator attributes="">
    <@bind path/>
    <#list options?keys as value>
    <#assign id="${status.expression}${value_index}">
    <#assign isSelected = contains(status.value?default([""]), value)>
    <input type="checkbox" id="${id}" name="${status.expression}" value="${value?html}"<#if isSelected> checked="checked"</#if> ${attributes}<@closeTag/>
    <label for="${id}">${options[value]?html}</label>${separator}
    </#list>
    <input type="hidden" name="_${status.expression}" value="on"/>
</#macro>

<#--
 * showErrors
 *
 * Show validation errors for the currently bound field, with
 * optional style attributes.
 *
 * @param separator the html tag or other character list that should be used to
 *    separate each option. Typically '<br>'.
 * @param classOrStyle either the name of a CSS class element (which is defined in
 *    the template or an external CSS file) or an inline style. If the value passed in here
 *    contains a colon (:) then a 'style=' attribute will be used, else a 'class=' attribute
 *    will be used.
-->
<#macro showErrors separator classOrStyle="">
    <#list status.errorMessages as error>
    <#if classOrStyle == "">
        <b>${error}</b>
    <#else>
        <#if classOrStyle?index_of(":") == -1><#assign attr="class"><#else><#assign attr="style"></#if>
        <span ${attr}="${classOrStyle}">${error}</span>
    </#if>
    <#if error_has_next>${separator}</#if>
    </#list>
</#macro>

<#--
 * checkSelected
 *
 * Check a value in a list to see if it is the currently selected value.
 * If so, add the 'selected="selected"' text to the output.
 * Handles values of numeric and string types.
 * This function is used internally but can be accessed by user code if required.
 *
 * @param value the current value in a list iteration
-->
<#macro checkSelected value>
    <#if stringStatusValue?is_number && stringStatusValue == value?number>selected="selected"</#if>
    <#if stringStatusValue?is_string && stringStatusValue == value>selected="selected"</#if>
</#macro>

<#--
 * contains
 *
 * Macro to return true if the list contains the scalar, false if not.
 * Surprisingly not a FreeMarker builtin.
 * This function is used internally but can be accessed by user code if required.
 *
 * @param list the list to search for the item
 * @param item the item to search for in the list
 * @return true if item is found in the list, false otherwise
-->
<#function contains list item>
    <#list list as nextInList>
    <#if nextInList == item><#return true></#if>
    </#list>
    <#return false>
</#function>

<#--
 * closeTag
 *
 * Simple macro to close an HTML tag that has no body with '>' or '/>',
 * depending on the value of a 'xhtmlCompliant' variable in the namespace
 * of this library.
-->
<#macro closeTag>
    <#if xhtmlCompliant?exists && xhtmlCompliant>/><#else>></#if>
</#macro>

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

spring.ftl 的相关文章

随机推荐

  • 时空RBF-NN预测混沌时间序列

    时空RBF NN预测混沌时间序列 混沌理论是现代非线性动力学研究的重要分支之一 混沌现象不仅存在于物理系统中 还出现在金融 生物等领域中 混沌时间序列的预测一直是研究者关注的焦点 本文提出了一种基于时空RBF NN的混沌时间序列预测方法 并
  • OMA DM终端管理

    居然还有这个东西 今天才知道 好强大 OMA全称是Open Mobile Alliance 即开放移动联盟 成立于2002年7月 由近200家公司组成 它的目的是搜集市场需求 规范业务应用层和网络功能层之间的接口 定义一个公开的标准框架 从
  • web项目时Spring监听器配置

    问题 每次使用ClassPathXmlApplicationContext 和getBean 方法时 都会加载spring配置文件 影响性能 解决方案 1 在服务器启动的时候 创建对象加载配置文件 2 底层使用监听器 listener 和S
  • ISE中FIFO IP核的Standard FIFO和First-word-Fall-Through模式的仿真比较

    ISE下的FIFO IP核有Standard FIFO和First word Fall Through两种模式 相对于标准模式FWFT First word Fall Through 可以不需要读命令 自动的将最新数据放在dout上 接下来
  • Qt中的串口编程之一

    QtSerialPort 简介 QtSerialPort模块是Qt5库的附加部分 为硬件和虚拟的串口提供了统一的接口 注意 该模块也增加了对Qt4的支持 串口由于其简单和可靠 目前在像嵌入式系统 机器人等工业中依旧用得很多 使用QtSeri
  • QFrame类使用总结

    QFrame与QWidget的区别 QFrame是基本控件的基类 QWidget是QFrame基类 关系如下 QPushButton QLabel gt QFrame gt QWidget 我们经常会从QFrame或者QWidget继承然后
  • 手机把网页保存为html,怎么保存整个网页

    手机评站网今天精心准备的是 怎么保存整个网页 下面是详解 如何另存整个网页 如何另存整个网页 如何另存整个网页 1 在手机桌面中找到手机百度 点击打开手机百度 如下图所示 2 在手机百度中找到自己想要另存为的网页 点击进入该网页如下图所示
  • Visual Studio运行程序执行太快,看不到运行屏幕的结果,设置项目属性解决。

    一 右击项目 找到属性 二 找到链接器 三 链接器中找到子系统 子系统 选择控制台 SUBSYSTEM CONSOLE 应用 确定即可 四 也可以补充getchar 可以利用从键盘获取一个字符 来显示调试窗口
  • C++ 二叉树序列化与反序列化

    本人微信公众号 CPP进阶之旅 如果觉得这篇文章对您有帮助 欢迎关注 CPP进阶之旅 学习更多技术干货 C 二叉树序列化与反序列化 1 题目要求 2 题目说明 3 核心问题 4 解题思路 5 代码实现 6 问题扩展 7 重要说明 1 题目要
  • 从源码出发浅析 Android TV 的焦点移动原理(下篇)

    转自 https cloud tencent com developer article 1006297 2 2 findNextFocus 如果开发者没有指定nextFocusId 则用findNextFocus找指定方向上最近的视图看一
  • 方差、协方差、期望、相关系数等概念集合

    首先说明一下 本文是本人在复习方差等相关知识的过程中 通过网络上的相关讲解 进行个人总结后得到的 并非个人原创 在此发布只是为了作为一个学习记录与大家分享 1 期望 试验中可能出现的值及其概率的乘积 即是数学期望 1 离散型 离散型随机变量
  • git add 命令详解

    1 前言 2 git add 基本操作 3 git add 命令参数 4 git add 背后做了什么 1 前言 众所周知 git 中有工作区 暂存区 版本库三大组成部分 工作区 电脑中能看到的目录 也就是写代码的地方 暂存区 英文叫 st
  • vue3中通过自定义指令,实现点击空白处触发事件,点击非自身dom触发事件

    我们经常在开发过程中 会遇到这些问题 怎么实现点击空白处关闭指定盒子 怎么实现点击空白处收起下拉框 即 怎么触发点击空白处事件 怎么触发 点击非自身dom而触发的事件 在vue3当中 使用自定义指令解决这个问题 在utils directi
  • 开启network-manager.service

    ubuntu20 04 本身系统会默认开机自动连接网络服务 但是我之前自己设置关闭了 所以现在要手动打开使用一下命令 先进入root xxz sudo systemctl start network manager service 回车执行
  • 《一》HI3518E视频处理基础知识----- 系统控制mpp

    目录 一 MPP的概述 1 视频方面 2 音频方面 3 MPP所处层次框架图 二 mpp处理平台架构 三 视频缓存池 1 视频缓冲池 VB 2 要点 3 相关的数据结构和API 1 VB CONF S 2 HI MPI VB SetConf
  • 家谱(特殊的层级人物关系)数据结构与自动排版算法的一种实现

    github源代码 家谱海本地私有版 https github com fengchangfight familytreesea 出处 http www fengchang cc post 24 家谱的数据结构并不复杂 逻辑上可以抽象成一种
  • BES2300x笔记(28) -- 左右耳同时按下的骚操作

    哈喽大家好 这是该系列博文的第二十八篇 篇 lt lt 系列博文索引 快速通道 gt gt 一 前言 市面上的TWS耳机 一般中高端耳机都会有触摸按键和入耳检测功能 使用触摸按键更方便外观和防水处理 但同时也限制了UI交互方式 有限的交互方
  • eclipse快速打开和闭合函数方法代码块的快捷方式

    ctrl shift 小键盘 收起和ctrl shift 小键盘 闭合
  • 基于深度学习的变化检测算法实现

    我是研究生期间研究主要研究SAR影像的变化检测 这是一段简单的基于深度学习的变化检测方法 以CNN实现 首先说下基于深度学习的变化检测任务的思路 制作训练样本 gt 训练模型 gt 使用训练的模型遍历图片中每个像元得出结果 1 筛选训练样本
  • spring.ftl

    lt ftl strip whitespace true gt lt spring ftl This file consists of a collection of FreeMarker macros aimed at easing so