Index > Features > Editing Custom XML

XBean supports custom XML languages for different libraries of Java code. This page details some guidelines.

References

To refer to another POJO inside XBean you can use the # character to refer to another bean in the same file. This is similar to the <property name="foo" ref="bar"/> style in Spring.

e.g. consider this example

The topping bean is configured using the regular Spring way; the pizza bean is configured using XBean XML; however notice that the pizza bean is configured via the reference #topping. If you really do want to configure a property with a string which starts with # then escape it as ## as we are doing with the cheese property in this example. i.e. the cheese property will be set to the string "#Edam"

PropertyEditor Support

Sometimes you want to have property that takes a value that is more human friendly to set. For example, the ammount of beer remainaing in a keg. Folks tend to think in different units of measurment, but you POJO probably just want a an ammount in a specific unit. Since XBean 2.6, it supports a per property PropertyEditor. You can conifigure a PropertyEditor that should be used for a specific property when it is converting the user configured text property value to the actual value that will be set on the property. This gives you an oppertunity to let the user use values like "1000 ml" or "25 l" or "300 pints", and the PropertyEditor would take care of converting all those values into ml units.

Here's an example of what the user would configure:

Here's how the bean developer would setup the PropertyEditor for the "remaining" property:

And here is how the PropertyEditor was implemented: