Whilst Metawidget is primarily focussed on the runtime generation of UIs, there are some scenarios where static UI generation is more appropriate.
Static generation has a different set of advantages and disadvantages to runtime generation. For example it cannot be as dynamic in responding to the state of the system, such as changing the UI based on the security of the logged-in user. It also tends to insert a lot of lines of code into your project. On the other hand, static generation does not introduce additional runtime dependencies. It also has an easier learning curve when tweaking the generated UI.
Nothing about the Metawidget pipeline (see Chapter 2, Architecture) is explictly static or runtime-based. Therefore the static Metawidgets all use the same approach of pluggable WidgetBuilders, WidgetProcessors and so on, to configure your UI. The static Metawidgets even reuse the exact same Inspectors and InspectionResultProcessors. For example JpaInspector can be used to inspect JPA annotations on classes for either runtime or static scenarios.
StaticPropertyStyle sits at the same conceptual level as, say, JavaBeanPropertyStyle or GroovyPropertyStyle. It allows Metawidget Inspectors to be repurposed to inspect static classes, as opposed to objects.
StaticMetawidget is the base class for all static UI generation.
An important requirement for static code generation is the Metawidget should not rely on the
technology being generated being available. For example, a static JSF Metawidget should not rely
on FacesContext.getCurrentInstance
. Architectually, this makes all static
Metawidgets more similar to each other than to their corresponding runtime version. For example,
the static JSF Metawidget is more similar to the static Spring Metawidget than it is to the
runtime JSF Metawidget. Therefore, it makes sense to have a StaticMetawidget base class.
The base class concerns itself with manipulating instances of StaticWidgets. These represent fragments of static output (text, basically) that the Metawidget assembles. Subclasses of StaticWidget provide more domain-specific APIs. For example StaticXmlWidget handles XML fragments, including opening and closing tags and tracking namespaces. Equally StaticJavaWidget handles fragments of Java code, including opening and closing braces and tracking imports.