Module portlets are defined in the omod/src/main/webapp/portlets folder.
Portlets are included in a jsp by using the following tag:
<openmrs:portlet url="this.portlet" id="thisportlet" moduleId="ModuleID" />
Note that you must specify moduleId="...", which differs from using a portlet in core code.
where the actual portlet would be a file called this.jsp in the above folder.
Create a controller such as the following:
@Controller @RequestMapping("**/this.portlet") public class ThisPortletController extends PortletController { private static final Log log = LogFactory.getLog(ThisPortletController.class); @SuppressWarnings("unchecked") @Override protected void populateModel(HttpServletRequest request, Map<String, Object> model) { // your code here }
and make sure the following line exists in your ModuleApplicationContext.xml file (it can be put just above the </beans> tag at the end:
<context:component-scan base-package="org.openmrs.module.integration" />
Obsolete starting here
If your portlet doesn't need a custom controller, then that is all you need to do. If you want a custom controller, then in the basicUrlMapping bean in webModuleApplicationContext, add a property for the portlet, pointing to the portlet's controller:
<prop key="**/thismodulesportlet.portlet">thismodulesportletController</prop>
Obsolete starting here
<prop key="**/thismodulesportlet.portlet">thismodulesportletController</prop>
And the controller bean takes a simple bean declaration:
<bean id="thismodulesportletController" class="@MODULE_PACKAGE@.web.controller.ThisModulesPortletController"> </bean>
Obsolete ending here
The ThisModulesPortletController should extend PortletController and override the populateModel method.
Any property added to the model in the populateModule method is available UNDER the "model" property. So if you add "myvar" to the model object, in your portlet jsp you access it with ${model.myvar}
The code inside of a portlet shouldn't have to differ from a standard OpenMRS portletportlet, meaning that it looks exactly like a jsp (or part of a jsp).
Obsolete starting here?
Also, note that in the core basicUrlMapping mapping for openMRS, portlets have a default mapping:
<prop key="**/*.portlet">portletController</prop>
To override this mapping, be sure that your module's basicUrlMapping has the following property:
<property name="order"><value>50</value></property>
where the value is anything less than 99 (this prioritizes the module's mappings over the core's default portlet mapping). This may change in the future, but this necessity was created with an upgrade to Spring 2.5 – if this value ever disappears from openMRS's core basicUrlMapping, it probably doesn't have to be in your module, either.
Obsolete ending here