Dialog Angularjs get parameters from Spring MVC through Json

Monday, July 18th, 2016 (0 Comment)

In this article, we create a modal or dialog angularjs get parameters from Spring MVC through Json. We will use Angularjs modal and bootstap to show a dialog.

Scenario: In Spring mvc,  we have entity Users and entity Roles. Users have many role and Role have many user. we want to get object user and convert to json. On screen, it will show dialog angularjs with properties of object user and after we click OK button, it will get values property of object and handle in AngularJs depend on your purpose.

1. Show dialog angularjs use angular modal and bootstap

At the first, we will run an example to see the final result about above scenario.

Demo

  • Line 16 –  31: dialog’s informations, you can add more infor of user object
  • Line 33: demo show dialog run on HTML
  • Line 34: only run in Spring MVC. In Spring Controller, you add class entity model.addAttribute(“_userEntity”, user) and call in jsp page ng-click=openInSpring(‘lg’,’${_userEntity}’)
  • Line 35: redirect to new link,  often use when delete an object, it will get confirm before call function delete in Spring mvc
  • Line 36: demo with parameter directly when run in Spring MVC

2. Something need to modify in Spring MVC

2.1. Config library maven in pom.xml:

2.2. Create Utils class to convert object to json string to show in dialog Angularjs

  • Line 11: fixed error when convert to json “com.fasterxml.jackson.databind JsonMappingException: could not initialize proxy – no Session

2.3. Users entity class

  • line 23: add fetch=FetchType.EAGER fixed for issue: if user have many roles, when convert to json then property roles of user will be set null.
  • Line 29: convert direct entity to json string

Additions: in Controller Spring mvc, you can declare @SessionAttributes(“entity”) to keep all values is not null when show some value of entity in jsp page

We often use the dialog (here is dialog angularjs) to verify or confirm some information before calling which functions.

Tags: , , , ,

Related Posts

angularjs
Angularjs filter checkbox examples mvc
angularjs
Angularjs listbox examples mvc
angularjs
Angularjs combobox examples mvc
angularjs
Create update delete CRUD in Angularjs MVC

Related Posts

angularjs
Angularjs filter checkbox examples mvc
angularjs
Angularjs listbox examples mvc
angularjs
Angularjs combobox examples mvc
angularjs
Create update delete CRUD in Angularjs MVC

Leave a Reply

Your email address will not be published. Required fields are marked *