request dispatch

5 views
Skip to first unread message

stark

unread,
Nov 3, 2012, 1:45:13 AM11/3/12
to scooter-...@googlegroups.com
Hello John,

Got some question...

1. How do we do request dispatching in the controllers for both get and post? say i got a EmployeeController->add() then i want to forward it to DepartmentController->add() ? Would it be ok to use the servlet request it self?

2. What's the convention on naming the controller's, it seems i can't do like this, EmployeeOfTheYearController, it cant find the route. is this expected for controllers?


Many Thanks!

John Chen

unread,
Nov 3, 2012, 11:58:32 AM11/3/12
to scooter-...@googlegroups.com
See my answers below.

On Sat, Nov 3, 2012 at 1:45 AM, stark <techi...@gmail.com> wrote:
Hello John,

Got some question...

1. How do we do request dispatching in the controllers for both get and post? say i got a EmployeeController->add() then i want to forward it to DepartmentController->add() ? Would it be ok to use the servlet request it self?

> Yes, it is doable. Just change the return code in EmployeeController->add() to 
return renderView("/department/add");

renderView method loads jsp files from views/department directory without going through DepartmentController. 

If you need code logic in DepartmentController's add() method, you can use redirect like the following:
return redirectTo("/department/add");


2. What's the convention on naming the controller's, it seems i can't do like this, EmployeeOfTheYearController, it cant find the route. is this expected for controllers?

>  Either you rename your controller class to "EmployeeoftheyearController" or add controller_class property in your route like the following:
routes.name.eoy=\
    url:/eoy; \
    controller:employeeoftheyear; \
    controller_class:greeting.controllers.EmployeeOfTheYearController; \
    action:index

Then you can hit URL "http://localhost:8080/greeting/eoy". 

The controller class is:
package greeting.controllers.EmployeeOfTheYearController;
import static com.scooterframework.web.controller.ActionControl.*;
public class EmployeeOfTheYearController {
    public String index() {
        return "This is EmployeeOfTheYearController";
    }
}


Many Thanks!

Reply all
Reply to author
Forward
0 new messages