Created
May 18, 2012 13:22
-
-
Save miere/2725247 to your computer and use it in GitHub Desktop.
Exemplo de uso do Coffee Framework
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package comprase.ofertaDeCompra; | |
import java.util.Date; | |
import java.util.List; | |
import javax.ejb.EJB; | |
import coffee.annotation.Action; | |
import coffee.annotation.Parameter; | |
import coffee.annotation.WebResource; | |
import comprase.core.PersistenceException; | |
@WebResource( | |
rootURL="/ofertaDeCompra/", | |
template="comprase/ofertaDeCompra/OfertaDeCompra.xhtml" | |
) | |
public class OfertaDeCompraResource { | |
@EJB | |
private OfertaDeCompraService service; | |
private OfertaDeCompra ofertaDeCompra; | |
private List<OfertaDeCompra> ofertasDeCompra; | |
@Action(pattern="/") | |
public void home() {} | |
@Action(pattern="/view", template="comprase/ofertaDeCompra/OfertaDeCompraView.xhtml") | |
public void view () { | |
setOfertaDeCompra(service.retrieve().get(5)); | |
} | |
@Action(pattern="/view/#{id}/", template="comprase/ofertaDeCompra/OfertaDeCompraView.xhtml") | |
public void view (@Parameter("id") Long id) { | |
setOfertaDeCompra(service.retrieveById(id)); | |
} | |
@Action(redirectTo="/ofertaDeCompra/list") | |
public void create () throws PersistenceException { | |
ofertaDeCompra.setDataCriacao(new java.sql.Date(new Date().getTime())); | |
int year = Integer.parseInt(ofertaDeCompra.getStrDataValidade().split("/")[2]); | |
int month = Integer.parseInt(ofertaDeCompra.getStrDataValidade().split("/")[1]); | |
int day = Integer.parseInt(ofertaDeCompra.getStrDataValidade().split("/")[0]); | |
ofertaDeCompra.setDataValidade(new java.sql.Date(year, month, day)); | |
service.create(ofertaDeCompra); | |
} | |
@Action(template="comprase/ofertaDeCompra/OfertaDeCompraList.xhtml") | |
public void list() { | |
ofertasDeCompra = service.retrieve(); | |
} | |
public void setOfertaDeCompra(OfertaDeCompra ofertaDeCompra) { | |
this.ofertaDeCompra = ofertaDeCompra; | |
} | |
public OfertaDeCompra getOfertaDeCompra() { | |
return ofertaDeCompra; | |
} | |
public void setOfertasDeCompra(List<OfertaDeCompra> ofertasDeCompra) { | |
this.ofertasDeCompra = ofertasDeCompra; | |
} | |
public List<OfertaDeCompra> getOfertasDeCompra() { | |
return ofertasDeCompra; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Para mapear os métodos que serão chamados, devemos primeiramente definir a raiz que este resource irá representar (de maneira similar às Servlets). Em nosso exemplo: /ofertaDeCompra/. Com isto realizado, podemos mapear nossos métodos através da annotation coffee.annotation.Action.
Existem duas maneiras de mapear os métodos: