Concepts

Introduction

Webby implements the concepts of

  • Describing business classes, their attributes and relations,
  • Telling the application how to find the model,
  • Providing declarative and programmatic definition of actions,
  • Simple GUI components that support editing and navigating of business objects and executing actions on them.

What is a business class / business object? A business class is a Java class that describes attributes, relations and behavior (as every class does) and that represents something meaningful to the users of an application, typically (but not always) related to something that exists in the real world outside the computer. Examples:

  • In a shopping cart application articles (you can buy), shopping carts (you can fill them), customers (that probably buy something) and billing addresses (where customers want their goods shipped to) are business objects, whereas the business classes describe these objects.
  • In a blogging application pictures, posts and comments would be among the business objects.

The descriptors

Every business class needs a descriptor, telling us the Java class of business instances, the attributes, the relations and the actions:

public interface EntityDescriptor extends Serializable {
    Class getEntityClass();
    List<AttributeDescriptor> getAttributes();
    List<RelationDescriptor> getRelations();
    List<BeanActionDescriptor> getActions();
    WebbyConfigurator getConfigurator();
}

Additionally, the descriptor needs to be Serializable (because session objects in wicket must be storable in the session; also each descriptor should know it's configurator.

The configurator: How to find descriptors

The UI components (and maybe other parts of the application) often have an EntityDescriptor reference given, but need to find/access other descriptors and/or instantiate wicket models or other UI components / pages. This is what the configurator should help with: Allow to find these things.

What might also be needed: A data provider to supply a component with a set of business objects, if another buesiness object has got a relation to this set:

public interface WebbyConfigurator extends Serializable {
    BeanPageFactory getEntityPageFactory();
    BeanModelFactory getBeanModelFactory();
    SortableDataProvider getToNRelationDataProvider(Class clazz, IModel beanModel, RelationDescriptor rd);
    Set getAllInstances(Class clazz);
    Set<Class> getViewableClasses();
    EntityDescriptor getEntityDescriptor(Class entityClass);
    BeanActionMethodInvoker getBeanActionMethodInvoker(Method method);
}

UI components: Edit, navigate, execute actions

Having a configurator and descriptors can be used by UI components to display and navigate business objects. Some simple forms, panels and pages are provided in Webby, which can be instantiated individually, e.g. like this:

    IModel businessModel = new YourModel(businessObject);
    EntityDescriptor descriptor = 
            configurator.getEntityDescriptor(businessObject.getClass());
    Page page = new SimpleEditBeanPage(businessModel, descriptor);

The simple UI components in turn use the configurator, if needed, to get access to sets of business objects for navigating a relation and for instantiating wicket models for business objects.

Introspection

In order to avoid coding descriptors manually, some utility classes for introspection and SimpleEntityDescriptor are available:

  • The utility classes UtilAttributes, UtilRelations and UtilActions use introspection to analyse java classes and create descriptor instances upon request. Basically, they use the getter and setter methods of the classes given. UtilActions additionally uses annotations: Finding actions by checking if a method is annotated as Action.

    Introspection must make some assumptions. An important one is that getters and setters of to-n relations use typed collections (based upon Java's Generics). It might be helpful to explain the assumptions better...

  • SimpleEntityDescriptor implements EntityDescriptor and uses the utility classes to create attributes, relations, and actions.

Persistence

Many web applications need persistence. Webby itself doesn't care about persistence, but it is well suited to have business classes persisted.

Webby4db is a lightweight artefact targeting exactly this, using databinder, which in turn uses Hibernate.

See the home of webby4db, but also look at the examples which also use Webby4db.