Step 9: Setting fields to read-only behavior

In the very last step, we want to make all input fields read-only, except for those in dialogs. Even though the domain model that we have bound to our PMOs allows modification of the partner data, we want to change this behavior so we can control when and where the user changes data.

For that, we make use of linkki's PropertyBehaviors. For a detailed documentation about PropertyBehaviors, see section Cross-Sectional Data Binding in the chapter "Architecture" of the linkki Documentation.

Everywhere a DefaultBindingManager is created, we can additionally pass read-only PropertyBehaviors to the constructor. Technically, we need to pass through a PropertyBehaviorProvider that contains only one read-only PropertyBehavior. In AddressPage for example, this modification has to be applied to the instance of the field bindingManager.

AddressPage.java
    private BindingManager bindingManager = new DefaultBindingManager(
            ValidationService.NOP_VALIDATION_SERVICE,
            PropertyBehaviorProvider.with(PropertyBehavior.readOnly()));

Once you have applied this step for all pages including the SearchPage, you may realize that introducing this behavior also causes the search bar to be read-only. To fix this problem, the PropertyBehavior must be modified in the SearchPage. Instead of creating behavior that is always read-only, we create new behavior that sets a PMO as writable only if the class is a SearchSectionPmo.

SearchPage.java
    private BindingManager bindingManager = new DefaultBindingManager(
            ValidationService.NOP_VALIDATION_SERVICE,
            PropertyBehaviorProvider.with(PropertyBehavior
                    .writable((pmo, property) -> (pmo.getClass()
                            .equals(SearchSectionPmo.class)))));