Wiki Spaces

Documentation
Projects
Resources

Get Help from Others

Q&A: Ask OpenMRS
Discussion: OpenMRS Talk
Real-Time: IRC Chat | Slack

Documentation

Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Corrected mapping code examples to return false when no override has occured

...

This functionality requires the following modules:
1. App Framework 2.8
2. EMR API 1.1316
3. UI Framework 3.6

This demo requires the following additional modules which has the overridden pages:

...

Code Block
languagejava
titleSample Fragment Request Mapper
linenumberstrue
@Component
public class DemoHeaderFragmentRequestMapper implements FragmentRequestMapper {

   protected final Log log = LogFactory.getLog(getClass());

   /**
    * Implementations should call {@link FragmentRequest#setProviderNameOverride(String)} and
    * {@link FragmentRequest#setFragmentIdOverride(String)}, and return true if they want to remap a request,
    * or return false if they didn't remap it.
    *
    * @param request may have its providerNameOverride and pageNameOverride set
    * @return true if this page was mapped (by overriding the provider and/or page), false otherwise
    */
   public boolean mapRequest(FragmentRequest request) {
      log.info(request.toString());
      if (request.getProviderName().equals("appui")) {
         if (request.getFragmentId().equals("header")) {
            // change to the custom loginfragment provided by the module
            request.setProviderNameOverride("mapperoverridedemo");
            request.setFragmentIdOverride("demoHeader"); // no need to specify this if the name of the fragment is the same as the one being over
            log.info(request.toString());
				return true; 
         }
      }
	  // no override happened 
      return truefalse;
   }

}

Overriding a Page 

  1. Create the page and associated controller following the UI framework guidelines at https://wiki.openmrs.org/display/docs/Using+the+UI+Framework+in+Your+Module#UsingtheUIFrameworkinYourModule-FoldersandPackages usually best to copy the existing code from the page being overridden
  2. Create a page request mapper class following the same convention as the page controller. The fragment for this tutorial is called demoLogin.gsp hence the class name is DemoLoginPageRequestMapper with sample code below noting the following:

...

Code Block
languagejava
titleSample Page Request Mapper
linenumberstrue
@Component
public class DemoLoginPageRequestMapper implements PageRequestMapper {

   protected final Log log = LogFactory.getLog(getClass());

   /**
    * Implementations should call {@link PageRequest#setProviderNameOverride(String)} and
    * {@link PageRequest#setPageNameOverride(String)}, and return true if they want to remap a request,
    * or return false if they didn't remap it.
    *
    * @param request may have its providerNameOverride and pageNameOverride set
    * @return true if this page was mapped (by overriding the provider and/or page), false otherwise
    */
   public boolean mapRequest(PageRequest request) {
      if (request.getProviderName().equals("referenceapplication")) {
         if (request.getPageName().equals("login")) {
            // change to the custom login provided by the module
            request.setProviderNameOverride("mapperoverridedemo");
            request.setPageNameOverride("demoLogin");

            log.info(request.toString());
				return true; 
         }
      }
	  // no override happened 
      return truefalse;
   }

}

 

Troubleshooting Tips

  1. Request Mappers working in a random order, with some requests not being overridden - check to ensure that the classes only return true when an override has occurred not all the time