Module Extension Points
Modules can extend the presentation layer through extension points. In an ideal world, modules would be able to modify the presentation layer with the same Aspect Oriented Programming (AOP) technique used for the API. However, the main presentation layer is currently via the webapp and html. There isn't currently a way to inject code in a general way into a jsp or html file.
Instead, Extension Points
must be placed throughout the webapp to provide "hooks". Modules then create Extension
s that hook into those points. A module can hook into any number of points any number of times. Each Extension must be defined in the config.xml file.
Extensions must extend the abstract class org.openmrs.module.web.Extension
. If the getOverrideContent(String)
returns a non-null, the returned value is inserted as the content for that extension.
For the webapp, the getMediaType()
should always return Extension.MEDIA_TYPE.html
or null. If generic display code is being returned, the media type can be null. The webapp will look for defined extension points that are either defined to be any (null) or html. In the future, when we have more than one type of presentation layer, we can have multiple MEDIA_TYPE options. (For now, the only one is html).
Example: Adding an Extension to a module (adding section to the admin screen)
Tags inserted into the config.xml file:
<extension>
<point>org.openmrs.admin.list</point>
<class>org.openmrs.module.htmlformentry.extension.html.AdminList</class>
</extension>
The org.openmrs.admin.list
Extension Point is defined in the /openmrs/admin/index.jsp file. This is one of several unique extension points that require certain methods to be implemented. The admin.list point requires a getTitle() method and a getLinks() method as defined in org.openmrs.module.web.extension.AdministrationSectionExt
. (To ensure validity, your Extension can simply extend this abstract class. To create an api/jar/library that you can include in your modul