Groovy "no such property" error when creating RA app

Hi,

I’m trying to write an app for referenceapplication. I was following the Step by Step tutorial ( https://wiki.openmrs.org/display/docs/App+Framework+Step+by+Step+Tutorial ) and UI tutorial ( https://wiki.openmrs.org/display/docs/UI+Framework+Step+By+Step+Tutorial ) trying to replicate the work done in the frontend.

I suppose that code serves for getting all the decorations showed:

<%
        ui.decorateWith("appui", "standardEmrPage")
%>
<script type="text/javascript">
<% if (breadcrumbs) { %>
    var breadcrumbs = ${ breadcrumbs };
<% } else { %>
    var breadcrumbs = [
        { icon: "icon-home", link: '/' + OPENMRS_CONTEXT_PATH + '/index.htm' },
        { label: "${ ui.message(label)}"}
    ];
<% } %>
</script>

<h2>
	${ ui.message(heading) }
</h2>
<!-- The page itself -->
<h1> Hello world </h1>
<!-- end of the page>

but it doesnt’ work, when I just put it on my page in the gsp file (linked by an app from app dashboard). I don’t have anything else but the code generated by openmrs-skd:create-module, app declaration in helloWorld_app.json file and the helloWorld.gsp page. I have imported all the dependencies, as stated at the beginning of the UI tutorial, I work in the developer mode, but it doesn’t work in ‘normal’ mode either.

My app declaration:

[
    {
        "id": "coreapps.helloWorld",
        "description": "Example app, shows Hello World",
        "order": 2,
        "extensions": [
            {
                "id": "coreapps.activeVisitsHomepageLink",
                "extensionPointId": "org.openmrs.referenceapplication.homepageLink",
                "type": "link",
                "label": "Hello World label app",
                "url": "helloWorldmd/helloWorld.page",
                "icon": "icon-trophy",
                "requiredPrivilege": "App: coreapps.helloWorld"
            }
        ]
    }
]

I’ve also tried it with just

<%
    ui.decorateWith("appui", "standardEmrPage")
%>

<h1> Hello World! </h1>

but the same error appears. I suppose I need to include the ui somewhere, but I have no idea why, and none of the tutorials mentions that.

The error message:

Root Error
groovy.lang.MissingPropertyException: No such property: breadcrumbs for class: SimpleTemplateScript8

Full Error
org.openmrs.ui.framework.ViewException: Error rendering page view for helloWorld. Model properties:
sessionContext 
featureToggles 
patient 
ui 
context 
contextPath 
session 
param 
out
	at org.openmrs.ui.framework.page.GroovyPageView.render(GroovyPageView.java:55)

Full traceback: http://pastebin.com/c5LYPfXC

Offhand, from my phone, I think the error is

<% if (breadcrumbs) { %>

It’s invalid in a groovy template to refer to a variable name that is undefined in the scope.

  1. I’ve literally copied it from another module, where it works (findpatient page, /coreapps-omod/src/main/webapp/pages/findpatient/findPatient.gsp)
  2. I’ve also tried without that, with just the ui.decorate() and it still hasn’t worked.

Ok, I’ve found the solution.

  1. Additional equired dependencies for modulename-omod pom

     	<dependency>
     	<groupId>org.openmrs.module</groupId>
     	<artifactId>appframework-api</artifactId>
     </dependency>
     
     <dependency>
         <groupId>org.openmrs.module</groupId>
         <artifactId>appui-omod</artifactId>
         <type>jar</type>
     </dependency>
     
     <dependency>
     	<groupId>org.openmrs.module</groupId>
     	<artifactId>appui-omod</artifactId>
     	<version>${appuiVersion}</version>
     	<scope>provided</scope>
     </dependency>
    
  2. appuiVersion

    1.4-SNAPSHOT

  3. Page controller is required. Source should be in org.oopenmrs.module.moduleName.page.controller.appName

    package org.openmrs.module.helloWorldmd.page.controller.helloWorld;

import org.openmrs.module.appframework.domain.AppDescriptor; import org.openmrs.module.appui.UiSessionContext; import org.openmrs.module.coreapps.helper.BreadcrumbHelper; import org.openmrs.ui.framework.UiUtils; import org.openmrs.ui.framework.page.PageModel; import org.springframework.web.bind.annotation.RequestParam;

/** * */ public class HelloWorldPageController {

/**
 * This page is built to be shared across multiple apps. To use it, you must pass an "app"
 * request parameter, which must be the id of an existing app that is an instance of
 * coreapps.template.findPatient
 * 
 * @param model
 * @param app
 * @param sessionContext
 */
public void get(PageModel model, @RequestParam("app") AppDescriptor app, UiSessionContext sessionContext,
                UiUtils ui) {
    BreadcrumbHelper.addBreadcrumbsIfDefinedInApp(app, model, ui);
}

}

  1. Copy a class BreadcrumbHelper with method addBreadcrumbsIfDefinedInApp from coreapps module

  2. It will require a modification in the app description (appName_app…json), because now links have to specifiy app name in the GET parameter for module helloWorldmd and app helloWorld it will look like: http://*/openmrs/helloWorldmd/helloWorld/helloWorld.page?app=helloWorldmd.helloWorld

  3. I stil don’t know how to make ${ ui.message(label) } working. I’ve added message.properties to the project and specified label, but it still doesn’t work, so current solution is just to hardcode that value.

1 Like