Sha256: 63daf90d1c7ddec9b85b334e270221f2eec73befdee34aca210b362fed094e3f

Contents?: true

Size: 1.73 KB

Versions: 2

Compression:

Stored size: 1.73 KB

Contents

package app.controllers;

import java.util.List;

import javax.persistence.EntityManager;

import app.models.Product;
import br.com.caelum.vraptor.Delete;
import br.com.caelum.vraptor.Get;
import br.com.caelum.vraptor.Path;
import br.com.caelum.vraptor.Post;
import br.com.caelum.vraptor.Put;
import br.com.caelum.vraptor.Resource;
import br.com.caelum.vraptor.Result;
import br.com.caelum.vraptor.view.Results;

@Resource
public class ProductController {

	private Result result;
	private EntityManager entityManager;
	
	public ProductController(Result result, EntityManager entityManager) {
		this.entityManager = entityManager;
		this.result = result;
	}
	
	@Get
	@Path("/products")
	public List<Product> index() {
		return entityManager.createQuery("from Product").getResultList();
	}
	
	@Post
	@Path("/products")
	public void create(Product product) {
		entityManager.persist(product);
		result.use(Results.logic()).redirectTo(ProductController.class).index();  
	}
	
	@Get
	@Path("/products/new")
	public Product newProduct() {
		return new Product();
	}
	
	@Put
	@Path("/products")
	public void update(Product product) {
		entityManager.merge(product);
		result.use(Results.logic()).redirectTo(ProductController.class).index();  
	}
	
	@Get
	@Path("/products/{product.id}/edit")
	public Product edit(Product product) {
		return entityManager.find(Product.class, product.getId());
	}

	@Get
	@Path("/products/{product.id}/show")
	public Product show(Product product) {
		return entityManager.find(Product.class, product.getId());
	}

	@Delete
	@Path("/products")
	public void destroy(Product product) {
		entityManager.remove(entityManager.find(Product.class, product.getId()));
		result.use(Results.logic()).redirectTo(ProductController.class).index();  
	}
}

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
vraptor-scaffold-0.0.1.beta3 spec/lib/generators/scaffold_generator/controller_generator/templates/ProductController.java
vraptor-scaffold-0.0.1.beta2 spec/lib/generators/scaffold_generator/controller_generator/templates/ProductController.java