我使用了富有的ui日期选择器。 我得到了日期的正确值。 但是如果我想设置richui的datechooser的值是怎么做的呢?
答案 0 :(得分:1)
您必须在控制器中手动解析日期,因为格式/模式不为grails所知。
def date = Date().parse("MM-dd-yyyy", params.date); //<-- consider using a constant for the date format
或将params值重置为java.util.Date类。
params.date = Date().parse("MM-dd-yyyy", params.date); //<-- re-assigns date string as date class
您可能还需要测试入站格式,以确保有人不会手动输入无效格式...
def date = (parmas.date.matches("\\d{2}-\\d{2}-\\d{4}"))? Date().parse("MM-dd-yyyy", params.date) : null; //<-- safely return null if doesn't match a date regex.
另见: