Skip to content

OHSU-OCTRI/common-lib

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

89 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OCTRI Common Library

This package contains the common classes useful for the development of OCTRI Spring-based web applications, including:

  • Utility classes for working with Mustache views
  • Abstract classes and interfaces
  • Patterns for method security
  • Configuration class for overriding date/time formats in Mustache

It also makes a collection of WebJars available as transitive dependencies in downstream projects.

Using This Package

To use this package, add it to your pom.xml file.

	<dependency>
		<groupId>org.octri.common</groupId>
		<artifactId>common_lib</artifactId>
		<version>${common_lib.version}</version>
	</dependency>

WebJar Dependencies

By including the webjar-locator dependency in pom.xml, this package provides simple version management for WebJar dependencies. That includes WebJar dependencies provided by this package, as well as dependencies that are declared in projects that depend on this package.

The provided WebJars include:

  • Bootstrap 5
  • DataTables 2
  • Font Awesome
  • jQuery 3
  • jQuery-UI

Dependency Conflicts

To avoid unexpected behavior, avoid overriding dependencies provided by this package in downstream builds.

Dependency conflicts may also arise when different versions of this package appear across a project's dependency tree. When possible, harmonize dependencies on this package to a single version. If versions cannot be fully harmonized, ensure that the selected versions include compatible versions of the above WebJar dependencies.

Implementation

The library is implemented using Spring Boot. For a detailed list of dependencies, see pom.xml.

Custom Date Formatting in Mustache Templates

To use custom date formats in your application, enable component scanning on common packages in your application:

@ComponentScan(basePackages = { "org.octri.common", ...})

Set the common properties. For example, to use the U.S. Date Pattern:

  • octri.common.view.date-pattern=MM-dd-yyyy
  • octri.common.view.date-pattern-regex=[0-9]{2}-[0-9]{2}-[0-9]{4}
  • octri.common.view.date-time-pattern=MM-dd-yyyy HH:mm a

In your @ControllerAdvice class, autowire the ViewConfig component and add this attribute to your model:

model.addAttribute("octriViewConfig", viewConfig.getProperties());

Other OCTRI libraries will look for this attribute when displaying dates in forms. Your application should follow the same pattern to work with custom dates. For example:

<div class="form-group">
    <label for="start_date" class="form-label">Start date</label>
    <div class="input-group date-control">
        <input type="text" class="form-control" id="start_date" name="startDate" value="{{#startDate}}{{.}}{{/startDate}}"
            pattern="{{octriViewConfig.datePatternRegex}}" placeholder="{{octriViewConfig.datePatternPlaceholder}}" autocomplete="off"
            data-provide="datepicker" data-date-format="{{octriViewConfig.datePattern}}">
        <span class="input-group-text rounded-end"><i class="far fa-calendar-alt"></i></span>
    </div>
    <div class="invalid-feedback">Value must be formatted {{octriViewConfig.datePatternPlaceholder}}</div>
</div>

About

Common classes useful for the development of Spring-based web applications

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors