Using @ModelAttribute in module doesn't build objects

I expect this is a simple issue to fix. Using OpenMRS 2.2 on iMac os 10.10. Code is found here: https://www.dropbox.com/s/02rcv77w3mignvk/basictest%20copy.zip?dl=0

I have a class, SimpleClass, with 2 fields (s and t) along with getters/setters. I create view to input values for the fields:

<form method="post">
    s: <input id="ss" type="text" name="s" />*
    t: <input id="tt" type="text" name="t" />*
    <input type="submit" value="Submit" />*
</form>

The controller code includes:

  public void post(PageModel model,
            @ModelAttribute("simp") SimpleClass simp ) {
        if (simp == null) {
            System.out.println("HelloWorldPageController, simp is null");
        } else {
            System.out.println("Model Attribute - POST; simp: " + simp.getS());
        }

When I run the code it always indicates HelloWorldPageController, simp is null so it doesn’t pick up the field values and build the object with those values. Thanks much, Barry

Whoops, never mind; I fixed the issue by including @BindParams SimpleClass simp

1 Like