1

My goal is to display values as a list from a table to the model pop-up on the JSP page.

action

public class IcdAction extends ActionSupport {

    private List<Icd10> icdCodes;

    public String execute() throws MalformedURLException, JsonProcessingException {
        SomeProcess ap = new SomeProcess();
        icdCodes = ap.getList();
        return SUCCESS;     
    }
}

js

var myApp = angular.module('myApp', []);

myApp.controller('MainCtrl', function ($scope, $http) {

    $http.get('IcdCodesAction')
    .success(function(response){
         $scope.icdcodes = response;
    });
});

struts.xml

<action name="IcdCodesAction" class="com.emr.action.IcdAction" >    
    <result type="json">
    </result>
</action>

In the JSP file I am using ng-repeaton the icdcodes.

I am new to AngularJS. I am not able to figure out where is the issue which is preventing the list to be displayed.

If I use hardcoded json data for $scopes.icdcodes, then it is working fine.

Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243

1 Answers1

0

The json result is processed by the struts2-json-plugin, that serializes the whole Action.

Then you can:

  1. read only the desired object from the serialized action:

    $http.get('IcdCodesAction')
    .success(function(response){
         console.log("this is the serialzied action -> " + response);
         console.log("this is what I want:  " + response.icdCodes);
         $scope.icdcodes = response.icdCodes;
    });
    

    OR

  2. use the root attribute of the json result to specify the single element to serialize:

    <action name="IcdCodesAction" class="com.emr.action.IcdAction" >    
        <result type="json">
            <param name="root">icdCodes</param>
        </result>
    </action>
    
Community
  • 1
  • 1
Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243
  • this is the serialzied action -> [object Object] icdcodeangular.js:9 this is what I want: undefined, this is what I am getting on console. Am I missing something in the action class? – Misha Mahto Dec 24 '15 at 06:58
  • Can you run the $http.get from the devTools console of your browser and open the [object Object] that is returned ? What's inside ? – Andrea Ligios Dec 24 '15 at 07:10
  • [{"addedBy":null,"addedOn":null,"code":"a0","deleted":null,"description":"first icd"}] – Misha Mahto Dec 24 '15 at 07:31
  • Thanks Andrea. I modified last line to $scope.icdcodes = response; its working as I wanted to. – Misha Mahto Dec 24 '15 at 07:46
  • So you've used the root object. I guess you've used BOTH the approaches, while you should use the first **OR** the second. Glad that helped btw – Andrea Ligios Dec 24 '15 at 09:00