【问题标题】:Appfuse-Maven Date picker not being shownAppfuse-Maven 日期选择器未显示
【发布时间】:2015-08-01 03:54:03
【问题描述】:

我使用 Appfuse 开发了一个 webmodule。我有一个预定义的数据库,其中包含几个具有 Date 字段的表。我能够使用 Jetty 成功运行 appfuse,但是它没有向我显示日期选择器,它只是显示我必须手动输入日期的文本字段。有没有办法默认获取日期选择器?

我做了以下步骤来生成模板

  • appfuse:gen-model:从数据库表生成 Java 类。
  • appfuse:gen:生成和安装测试、DAO、管理器、 基于 POJO 的控制器和视图。
  • appfuse:remove:删除已安装 appfuse:gen 的工件。
  • appfuse:full-source:将 AppFuse 基础项目转换为全源 没有 AppFuse 依赖项。还重命名包以匹配您的 项目的 groupId。
  • appfuse:copy-templates:为 CRUD 复制 FreeMarker 模板 生成到 src/test/resources/appfuse。这些模板可以 定制以满足您的需求。

【问题讨论】:

    标签: maven appfuse


    【解决方案1】:

    如果您的属性类型是 java.util.Date,您应该为您的文本字段获取一个日期选择器。如果没有,请检查您的 JavaScript 控制台,可能有错误。您也可以尝试将<input type="text"> 更改为<input type="date">

    这是 AppFuse 默认使用的日期选择器技术:

    1. 向 WebJar 添加依赖项:

      <dependency>
          <groupId>org.webjars</groupId>
          <artifactId>bootstrap-datepicker</artifactId>
          <version>1.3.1</version>
      </dependency>
      
    2. 然后在日期字段上使用 class="date" 并使用以下 HTML/JS 来初始化该字段。

      <link rel="stylesheet" type="text/css" media="all" href="/webjars/bootstrap-datepicker/1.3.1/css/datepicker.css" />
      <script type="text/javascript" src="/webjars/bootstrap-datepicker/1.3.1/js/bootstrap-datepicker.js"></script>
      <script type="text/javascript">
          $(document).ready(function() {
              $('.date').datepicker({format: "mm/dd/yyyy", weekStart: "0"});
          });
      </script>
      

    【讨论】: