Specifying Component Property Values
AjaxSwing allows configuring component application properties at instance, class and global levels, and the value is resolved in that order. Instance values are specified via a client property that is added to a particular component instance in Java code. Class and global values are specified in AjaxSwing application properties file.
For a list of supported properties refer to class AjaxSwingProperties and the User Guide.
Lets look at some examples to better understand this topic.
Specifying Global and Class DefaultsTo set a property for all components, * can be used in AjaxSwing properties file. For example, to enable all components in application WebUI the following syntax should be used in WebUI.properties:
component.*.enable=trueSetting the property at the class level allows providing different defaults for different classes. For example, to enable all radio buttons and disable all checkboxes the following syntax should be used:
Specifying Instance Property ValuesIf different instances of the components of the same class need to have different values, the property should be set in Java code instead of the properties file. This can be done using standard Swing method JComponent.putClientProperty() or with the help of AjaxSwingProperties.setClientProperty() method which has extra logic and support for classes that do not extend JComponent. The following examples all set the value of sortable property to true:
AjaxSwingProperties.setClientProperty(this.jTable, AjaxSwingProperties.COMPONENT_SORTABLE, Boolean.TRUE); AjaxSwingProperties.setClientProperty(this.jTable, "sortable", Boolean.TRUE); jTable.putClientProperties("sortable", Boolean.TRUE);
- The first version is verbose but most flexible and error-free
- The second version is still flexible but may break if property name is mistyped or renamed later
- The last version doesn't use AjaxSwing classes but somewhat error prone. Will not work for non-JComponent classes like JDialog
Upgrading from previous versions
Due to performance optimizations (Java handling of regular expressions is very CPU intensive) and to better position applications for internationilization starting from AjaxSwing 3.0.4 the support for regular expressions in component references has been discountinued. This is an incompatible change that requires updates to application properties files and possibly to Java source files.
Upgrading requires reviewing each line in the application properties file and eithe replacing it with component.XXX syntax in the properties file, or moving the value into Java code when class or global defaults are not appropriate.