marceloemanoel / vraptor-js-controller

Javascript Controller Generated to Help Ajax Communications
7 stars 2 forks source link

Add method overloading support to generated javascript #1

Open rponte opened 12 years ago

rponte commented 12 years ago

If a VRaptor controller has two or more methods with the same name (Java supports method overloading but JavaScript doesn't) the javascript controller is generated with problems in its routes. But I'm not sure what would be the real behavior in production when calling a duplicated action from javascript controller.

The plugin should analyze the duplicated methods and defaults to one of them, maybe the method with a @Get route.

marceloemanoel commented 12 years ago

I've simulated this. What really happens is this: the last declared method wins.

Suppose you have the following java methods:

 @Get
 @Path("/new")
  public void newProduct(){

  }

  @Post
  @Path("/new")
  public void newProduct(Product product){
    products.add(product);
    result.use(status()).ok();
  }

the generated javascript routes will be like this:

 var routes = {      
           newProduct: {
                    url: "/sample/products/new",
                    method: ['GET']
           },
           newProduct: {
                    url: "/sample/products/new",
                    method: ['POST']
           }
  }

the routes object will have one route only, the last declared!

I'll conduct more investigation on how to solve this problem!