You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by Alex Siman <al...@gmail.com> on 2009/11/17 01:49:49 UTC

Pretty mapping of actions

I have found some pretty RESTful approaches to map actions. I think Struts 2
must borrowed these ideas.

>From V|Raptor:
http://vraptor.caelum.com.br/documentation/vraptor3-ten-minutes-guide/

public class ProductsController {
    //...
   
    @Get
    @Path("/products")
    public List<Product> list() {...}
   
    @Post
    @Path("/products")
    public void add(Product product) {...}

    @Get
    @Path("/products/{product.id}")
    public void view(Product product) {...}
   
    @Put
    @Path("/products/{product.id}")
    public void update(Product product) {...}
   
    @Delete
    @Path("/products/{product.id}")
    public void remove(Product product) {...}
   
}


>From Spring MVC 3:
http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/ch15s03.html

@Controller
@RequestMapping("/appointments")
public class AppointmentsController {

    private final AppointmentBook appointmentBook;
    
    @Autowired
    public AppointmentsController(AppointmentBook appointmentBook) {
        this.appointmentBook = appointmentBook;
    }

    @RequestMapping(method = RequestMethod.GET)
    public Map<String, Appointment> get() {
        return appointmentBook.getAppointmentsForToday();
    }

    @RequestMapping(value="/{day}", method = RequestMethod.GET)
    public Map<String, Appointment> getForDay(@PathVariable
@DateTimeFormat(iso=ISO.DATE) Date day, Model model) {
        return appointmentBook.getAppointmentsForDay(day);
    }

    @RequestMapping(value="/new", method = RequestMethod.GET)
    public AppointmentForm getNewForm() {
        return new AppointmentForm();
    }

    @RequestMapping(method = RequestMethod.POST)
    public String add(@Valid AppointmentForm appointment, BindingResult
result) {
        if (result.hasErrors()) {
            return "appointments/new";
        }
        appointmentBook.addAppointment(appointment);
        return "redirect:/appointments";
    }
}

And about Struts 2 RESTful plugin: I found it not so good as it could be. It
is not flexible enough. Maybe it can be rewritten to allow map actions like
in examples above?
-- 
View this message in context: http://old.nabble.com/Pretty-mapping-of-actions-tp26382540p26382540.html
Sent from the Struts - Dev mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org


Re: Pretty mapping of actions

Posted by Alex Siman <al...@gmail.com>.
Hi there!

Anyone interested? Any thoughts?

Alex Siman wrote:
> 
> I have found some pretty RESTful approaches to map actions. I think Struts
> 2 must borrowed these ideas.
> 
> From V|Raptor:
> http://vraptor.caelum.com.br/documentation/vraptor3-ten-minutes-guide/
> 
> public class ProductsController {
>     //...
>    
>     @Get
>     @Path("/products")
>     public List<Product> list() {...}
>    
>     @Post
>     @Path("/products")
>     public void add(Product product) {...}
> 
>     @Get
>     @Path("/products/{product.id}")
>     public void view(Product product) {...}
>    
>     @Put
>     @Path("/products/{product.id}")
>     public void update(Product product) {...}
>    
>     @Delete
>     @Path("/products/{product.id}")
>     public void remove(Product product) {...}
>    
> }
> 
> 
> From Spring MVC 3:
> http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/ch15s03.html
> 
> @Controller
> @RequestMapping("/appointments")
> public class AppointmentsController {
> 
>     private final AppointmentBook appointmentBook;
>     
>     @Autowired
>     public AppointmentsController(AppointmentBook appointmentBook) {
>         this.appointmentBook = appointmentBook;
>     }
> 
>     @RequestMapping(method = RequestMethod.GET)
>     public Map<String, Appointment> get() {
>         return appointmentBook.getAppointmentsForToday();
>     }
> 
>     @RequestMapping(value="/{day}", method = RequestMethod.GET)
>     public Map<String, Appointment> getForDay(@PathVariable
> @DateTimeFormat(iso=ISO.DATE) Date day, Model model) {
>         return appointmentBook.getAppointmentsForDay(day);
>     }
> 
>     @RequestMapping(value="/new", method = RequestMethod.GET)
>     public AppointmentForm getNewForm() {
>         return new AppointmentForm();
>     }
> 
>     @RequestMapping(method = RequestMethod.POST)
>     public String add(@Valid AppointmentForm appointment, BindingResult
> result) {
>         if (result.hasErrors()) {
>             return "appointments/new";
>         }
>         appointmentBook.addAppointment(appointment);
>         return "redirect:/appointments";
>     }
> }
> 
> And about Struts 2 RESTful plugin: I found it not so good as it could be.
> It is not flexible enough. Maybe it can be rewritten to allow map actions
> like in examples above?
> 

-- 
View this message in context: http://old.nabble.com/Pretty-mapping-of-actions-tp26382540p26523572.html
Sent from the Struts - Dev mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org