grails的datePicker标签很好,但是并不能设置成yyyy-MM-dd的格式,另外,在月份选择列表中,显示的是中文的:一月、二月等等,对于追求简捷的中国人来说,这不符合我们的习惯。怎么办?
在grails英文指南页面中,显示了它的源代码位置在:/grails/src/groovy/org/codehaus/groovy/grails/plugins/web/taglib/FormTagLib.groovy
因此,在www.grails.org把源代码下载下来,按照路径找到这个FormTagLib.groovy文件,把里面关于datePicker的一节复制下来,在自己所做项目的taglib目录下建立一个tag文件MyTagLig.Groovy,把代码拷贝进去,稍作修改。
1、把年、月、日的代码按顺序替换一下;
2、在月份的实现部分替换掉。
package com.mycompany
import java.text.DateFormatSymbols
import java.text.DateFormat
import org.springframework.web.servlet.support.RequestContextUtils as RCU
class MyTagLib {
static namespace = "my"
def datePicker = { attrs ->
def out = out // let x = x ?
def xdefault = attrs['default']
if (xdefault == null) {
xdefault = new Date()
}
...........................................
...........................................
out.println "<input type=\"hidden\" name=\"${name}\" value=\"date.struct\" />"
// create year select
if (precision >= PRECISION_RANKINGS["year"]) {
out.println "<select name=\"${name}_year\" id=\"${id}_year\">"
if (noSelection) {
renderNoSelectionOptionImpl(out, noSelection.key, noSelection.value, '')
out.println()
}
for (i in years) {
out.println "<option value=\"${i}\"${i == year ? ' selected="selected"' : ''}>${i}</option>"
}
out.println '</select>'
}
// create month select
if (precision >= PRECISION_RANKINGS["month"]) {
out.println "<select name=\"${name}_month\" id=\"${id}_month\">"
if (noSelection) {
renderNoSelectionOptionImpl(out, noSelection.key, noSelection.value, '')
out.println()
}
dfs.months.eachWithIndex {m, i ->
if (m) {
def monthIndex = i + 1
out.println "<option value=\"${monthIndex}\"${i == month ? ' selected="selected"' : ''}>
${monthIndex}月</option>"
}
}
out.println '</select>'
}
// create day select
if (precision >= PRECISION_RANKINGS["day"]) {
out.println "<select name=\"${name}_day\" id=\"${id}_day\">"
if (noSelection) {
renderNoSelectionOptionImpl(out, noSelection.key, noSelection.value, '')
out.println()
}
for (i in 1..31) {
out.println "<option value=\"${i}\"${i == day ? ' selected="selected"' : ''}>${i}</option>"
}
out.println '</select>'
}
...........................................
...........................................
}
}
def
renderNoSelectionOption = {noSelectionKey, noSelectionValue, value ->
renderNoSelectionOptionImpl(out, noSelectionKey, noSelectionValue, value)
}
def
renderNoSelectionOptionImpl(out, noSelectionKey, noSelectionValue, value) {
// If a label for the '--Please choose--' first item is supplied, write it out
out << "<option value=\"${(noSelectionKey == null ? '' : noSelectionKey)}\"${noSelectionKey == value ? ' selected="selected"' : ''}>${noSelectionValue.encodeAsHTML()}</option>"
}
}
注意加上红色部分代码,否则会报错。
分享到:
相关推荐
jar包,官方版本,自测可用
jar包,官方版本,自测可用
jar包,官方版本,自测可用
grails-4.0.4.zip
Grails Grails Grails Grails Grails
Grails权威指南Grails权威指南Grails权威指南Grails权威指南Grails权威指南Grails权威指南
使用说明看: http://hi.baidu.com/vottot/blog/item/fd6465069b99e277020881e2.html
Grails项目的应用越来越多,而对于初学者来说,在Eclipse下搭建Grails项目是一个难题,这个文档将教会你如何搭建Grails项目,希望对你有所帮助。
Grails入门指南中文pdf -- 针对grails1.0.4更新,附加idea8 开发grails的流程
在学习任何东西之前,最重要的是培养兴趣,Groovy世界最耀眼的技术之一--Grails相信大家早已耳闻,我将通过Grails实战系列文章 向您展现Grails的迷人风采,使您感受到Grails的魅力,以至疯狂地爱上Grails,并坠入...
详细讲解grails开发环境配置。 详细讲解grails连接mysql数据库,crud开发
Grails1.1中文文档
grails+Xfire webservice
Grails专为下一代JavaWeb应用程序而设计的框架,其借助于Groovy动态语言,使Web开发变得简单而方便。Grails尽量为更多现有的Java项目创建一个全面的框架(不仅局限于视图处理),这和当前一些Java框架提供给用户的一...
grails-2.1.zip.001
grails_API_文档,CHM格式 ,内容详细.
Grails 中文 参考手册
grails的插件系统也是其亮点之一。首先,和rails,django等web框架类似,基于微内核的思想,插件(可重用模块)是框架的一等公民。grails除了核心模块以外的功能几乎都是通过插件方式实现的。实际上,一个grails插件...