U
U
User4562019-06-12 12:37:22
Java
User456, 2019-06-12 12:37:22

How to display data from two other controllers on one page in grails?

Good afternoon! I am new to java programming, especially not familiar with frameworks. I found a guide on how to create tables (or controllers, I don’t know exactly what they are called here) through classes that contain fields for tables. Done, it works. Adds, removes, removes. But, I was given the task to display the contents of two controllers (that is, their data) on one page. They said that here you need to create a file that will be something like from view - index.gsp. If possible, explain everything in great detail, as I repeat, I had no business with frameworks and java before.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
U
User456, 2019-06-13
@User456

In general, through a very long search, the solution was barely found. We need to display the contents of two controllers: Shops and Country.
The Shops controller was taken as the source. (What is commented out is generated by grails). Substituted the following.

ShopsService shopsService
CountryService countryService
def index(Integer max) {
        //params.max = Math.min(max ?: 10, 100)
        //respond shopsService.list(params), model:[shopsCount: shopsService.count()]
    
    def list1 = countryService.list(params)
    def list2 = shopsService.list(params)
    def str = '';
    str += '<p>--------------------Country-------------------------</p>'
    for (def i = 0; i <list1.size; i++) {
      str += '<p>' + list1[i] + '</p>'
    }
    str += '<p>--------------------Shops-------------------------</p>'
    for (def i = 0; i <list2.size; i++) {
      str += '<p>' + list2[i] + '</p>'
    }
    render str
    }

It simply displays data in a column, on a white background. By the way, it displays what you specified when creating a class in the ToString method. Of course, the teacher did not like the result, but it worked.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question