Emerjoin / Hi-Framework-features

Java EE Framework
5 stars 1 forks source link

Model approach #128

Open Emerjoin opened 7 years ago

Emerjoin commented 7 years ago

Motivation

MVC is about having a controller that provides data (model) to populate the view it decides to display. In Hi-Framework controllers don't decide the view they want to show, they must simply provide the data populate a view because in reality, a controller has actions/methods that have their own meaning, giving a hint of the data manipulated/required in the "action" context. The way things are displayed is not a problem of the controller, its only problem is what do display. Calling a view is a decision out of the controller scope. The callView method invocation turns unit testing a very complicated mission on Hi-Framework based apps.


@Mapping("/order")
 public class OrderController{

         //Example: GET oder/item?id=12
         public void item(@Map("id") String id, ViewScope scope){

                Order order = //Fetch from whatever u want              
                scope.set("totalItems",order.getTotalItems())
                            .set("amout",order.getAmount())
                            .set("currency",order.getPayment().getCurrency());               
         }
}