Question

I have a template that renders a chart according to a given list (retrieved from my domain layer). This template is displayed several times (with a different list) on a same page (let's say "home page") and in several pages as well.

For instance,

<g:render template="/template/chart" model="order: 'asc', orderBy: 'age', max: 5, domainClass: Person"></g:render>

should show a list of 5 persons ordered by age in ascendant order.

But the problem is that I need to construct the list of persons by querying the domain layer and unfortunately this can be done only through the template code like :

<%
    def vizuService = grailsApplication.classLoader.loadClass('com.myapp.VizuService').newInstance()
%>
<img src="${vizuService.getChartImage(order, orderBy, max, domainClass)}"/>
//The service method getChartImage will query the DB 

This design is flawed because I am retrieving my data through my View layer. But, I cannot reasonably send the data list to the template through the home page controller because the controller might even NOT know how many charts (and what data) are displayed in the Home page.

So, How can I design it in a MVC manner? (i.e. the Controller should be responsible for getting/passing the data). Is TagLib the only way to do it? (and IMO, TagLib does not really respect MVC principles) Maybe, AJAX is the (only) solution?

Thx for your ideas.

Was it helpful?

Solution

I have solved my problem by using the include tag that allows to include partial views rendered by the response of another controller/action

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top