java - Spring Webflow 中允许的月份和日期无效

标签 java spring-webflow

当我尝试输入日期格式 40/40/2017 时,spring webflow 将其转换为快速时间并将其转换为有效日期。这可以避免 validator 抛出任何错误。有什么方法可以使其无效而不将变量转换为字符串吗?

最佳答案

由于Spring MVC中有多种方法可以解决这些问题,例如使用initBinder。首先将此日期值传递给initBinder,以便它会抛出错误(在 validator 的验证时间)。
试试这个可能会有帮助

@InitBinder
public void initBinder(WebDataBinder binder) {
    SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
    binder.registerCustomEditor(Date.class, new 
                                       CustomDateEditor(dateFormat,true));
}

关于java - Spring Webflow 中允许的月份和日期无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46429656/

相关文章:

spring - 如何在Spring Webflow中的最终状态externalredirect中设置一些参数?

java - (Spring/Hibernate) 初始化子对象策略

java - Spring Web Flow单元测试: Set attribute in FlowScope without view-state

grails - Grails Web Flow:是否从另一个 Controller 操作重定向到Webflow?

java - 如何将现有的 android studio 项目导入到 eclipse 中,使其成为原生的并成为代号应用程序?

java - 在java中使用jdbc、results.getString(1)或results.getString ("field_name"哪个更有效)

java - Hibernate EJB 架构 - 模型 ClassNotFoundException

java - 向 JTextfield 添加提示文本属性

java - 使用 Hadoop 计数器 - 多个作业

java - 在 JSP 页面内调试?