Application Settings

This add-on provides a simple API and UI to work with mutable values of different types stored in database. These values are usually used as parameters of different functionality of the application.

Installation

For automatic installation through Jmix Marketplace, follow instructions in the Add-ons section.

For manual installation, add the following dependencies to your build.gradle:

implementation("io.jmix.appsettings:jmix-appsettings-starter")
implementation("io.jmix.appsettings:jmix-appsettings-flowui-starter")

Usage

To define some settings, create an entity extending the io.jmix.appsettings.entity.AppSettingsEntity class:

@JmixEntity
@Table(name = "CUSTOMER_SETTINGS")
@Entity
public class CustomerSettings extends AppSettingsEntity {

    @Column(name = "NOTIFICATION_TEXT")
    private String notificationText;

    @AppSettingsDefault("B")
    @Column(name = "DEFAULT_GRADE")
    private String defaultGrade;

    @AppSettingsDefault("1000")
    @Column(name = "SALES_THRESHOLD", precision = 19, scale = 2)
    private BigDecimal salesThreshold;

    // getters and setters

After that, you will be able to set values for this entity attributes using the Application settings view.

To get settings in the application code, use the AppSettings bean, for example:

@Autowired
private AppSettings appSettings;

@Subscribe
public void onInitEntity(InitEntityEvent<Customer> event) {
    CustomerSettings customerSettings = appSettings.load(CustomerSettings.class);
    CustomerGrade defaultGrade = customerSettings.getDefaultGrade();

    Customer customer = event.getEntity();
    customer.setGrade(defaultGrade);
}