Documentation Home

Rule Builders

Broadleaf provides a customizable admin field called a Rule Builder. This allows the admin user to create a set of conditions that will be dynamically evaluated to identify entities that satisfy these criteria.

Using a Rule Builder

Admin Page

Adding New Rules

Rule Builders are powered through Entity specific FieldServices. Adding new fields requires an override of these classes. Here is two new fields being added to the Product Rule Builders as an example:

    public class ExtendedProductFieldService extends ProductFieldServiceImpl {
        @Override
        public void init() {
            // Call super to get all existing rules
            super.init();

            // Add new fields below

            fields.add(new FieldData.Builder()
                    .label("Rental") // Display name in Rule Builder set as string
                    .name("rental") // Reflection accessed Java variable name on Product
                    .operators(RuleOperatorType.BOOLEAN)
                    .options(RuleOptionType.EMPTY_COLLECTION)
                    .type(SupportedFieldType.BOOLEAN)
                    .build());

            fields.add(new FieldData.Builder()
                    .label("rule_manufacturerBrand") // Display name resolved through message.properties
                    .name("manufacturerBrand.id") // Reflection accessed Many to One Relationship between Product and Manufacturer Brand
                    .operators(RuleOperatorType.SELECTIZE) // Give list of distinct options in a dropdown
                    .selectizeSectionKey("mfg-brand") // Admin Section URL for related entity
                    .options(RuleOptionType.EMPTY_COLLECTION)
                    .type(SupportedFieldType.COLLECTION)
                    .build());
            }
    }