Last active
December 18, 2015 13:59
-
-
Save IsmiKin/5793893 to your computer and use it in GitHub Desktop.
CRUD de JSF - Resolucion de Examen
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
/* | |
* To change this template, choose Tools | Templates | |
* and open the template in the editor. | |
*/ | |
import dao.CustomerFacadeLocal; | |
import dao.DiscountCodeFacadeLocal; | |
import dao.MicroMarketFacadeLocal; | |
import entidades.Customer; | |
import entidades.DiscountCode; | |
import entidades.MicroMarket; | |
import java.io.IOException; | |
import java.util.List; | |
import javax.annotation.PostConstruct; | |
import javax.ejb.EJB; | |
import javax.faces.bean.ApplicationScoped; | |
import javax.faces.bean.ManagedBean; | |
import javax.faces.bean.RequestScoped; | |
import javax.faces.context.FacesContext; | |
/** | |
* | |
* @author IsmiKin | |
*/ | |
@ManagedBean | |
@ApplicationScoped | |
public class customerBean { | |
@EJB | |
private MicroMarketFacadeLocal microMarketFacade; | |
@EJB | |
private DiscountCodeFacadeLocal discountCodeFacade; | |
@EJB | |
private CustomerFacadeLocal customerFacade; | |
private Customer seleccionada; | |
private List<Customer> todas; | |
private List<MicroMarket> todosMicro; | |
private List<DiscountCode> todosDiscount; | |
private String FK_Micro =""; | |
private String FK_Discount=""; | |
/** | |
* Creates a new instance of customerBean | |
*/ | |
public customerBean() { | |
} | |
@PostConstruct | |
private void Init(){ | |
todas = customerFacade.findAll(); | |
todosDiscount = discountCodeFacade.findAll(); | |
todosMicro = microMarketFacade.findAll(); | |
seleccionada = new Customer(); | |
} | |
public Customer getSeleccionada() { | |
return seleccionada; | |
} | |
public void setSeleccionada(Customer seleccionada) { | |
this.seleccionada = seleccionada; | |
} | |
public List<Customer> getTodas() { | |
return todas; | |
} | |
public void setTodas(List<Customer> todas) { | |
this.todas = todas; | |
} | |
public List<MicroMarket> getTodosMicro() { | |
return todosMicro; | |
} | |
public void setTodosMicro(List<MicroMarket> todosMicro) { | |
this.todosMicro = todosMicro; | |
} | |
public List<DiscountCode> getTodosDiscount() { | |
return todosDiscount; | |
} | |
public void setTodosDiscount(List<DiscountCode> todosDiscount) { | |
this.todosDiscount = todosDiscount; | |
} | |
public String getFK_Micro() { | |
return FK_Micro; | |
} | |
public void setFK_Micro(String FK_Micro) { | |
this.FK_Micro = FK_Micro; | |
} | |
public String getFK_Discount() { | |
return FK_Discount; | |
} | |
public void setFK_Discount(String FK_Discount) { | |
this.FK_Discount = FK_Discount; | |
} | |
public void AddCustomer() throws IOException{ | |
if(FK_Micro!="") | |
seleccionada.setZip(microMarketFacade.find(FK_Micro)); | |
if(FK_Discount!=""){ | |
Character c = (Character)this.FK_Discount.charAt(0); | |
seleccionada.setDiscountCode(discountCodeFacade.find(c)); | |
} | |
customerFacade.create(seleccionada); | |
todas = customerFacade.findAll(); | |
FacesContext.getCurrentInstance().getExternalContext().redirect("listar.do"); | |
} | |
public void eliminar(Customer aEliminar){ | |
customerFacade.remove(aEliminar); | |
todas = customerFacade.findAll(); | |
} | |
} |
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
<?xml version='1.0' encoding='UTF-8' ?> | |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml" | |
xmlns:h="http://java.sun.com/jsf/html" | |
xmlns:f="http://java.sun.com/jsf/core"> | |
<h:head> | |
<title>Facelet Title</title> | |
</h:head> | |
<h:body> | |
<f:view> | |
<h:form> | |
<h1><h:outputText value="Create/Edit"/></h1> | |
<h:panelGrid columns="2"> | |
<h:outputLabel value="CustomerId:" for="customerId" /> | |
<h:inputText id="customerId" value="#{customerBean.seleccionada.customerId}" title="CustomerId" required="true" requiredMessage="The CustomerId field is required."/> | |
<h:outputLabel value="Name:" for="name" /> | |
<h:inputText id="name" value="#{customerBean.seleccionada.name}" title="Name" /> | |
<h:outputLabel value="Addressline1:" for="addressline1" /> | |
<h:inputText id="addressline1" value="#{customerBean.seleccionada.addressline1}" title="Addressline1" /> | |
<h:outputLabel value="Addressline2:" for="addressline2" /> | |
<h:inputText id="addressline2" value="#{customerBean.seleccionada.addressline2}" title="Addressline2" /> | |
<h:outputLabel value="City:" for="city" /> | |
<h:inputText id="city" value="#{customerBean.seleccionada.city}" title="City" > | |
<f:validateLength minimum="2" maximum="5" /> | |
</h:inputText> | |
<h:outputLabel value="State:" for="state" /> | |
<h:inputText id="state" value="#{customerBean.seleccionada.state}" title="State" /> | |
<h:outputLabel value="Phone:" for="phone" /> | |
<h:inputText id="phone" value="#{customerBean.seleccionada.phone}" title="Phone" /> | |
<h:outputLabel value="Fax:" for="fax" /> | |
<h:inputText id="fax" value="#{customerBean.seleccionada.fax}" title="Fax" /> | |
<h:outputLabel value="Email:" for="email" /> | |
<h:inputText id="email" value="#{customerBean.seleccionada.email}" title="Email" /> | |
<h:outputLabel value="CreditLimit:" for="creditLimit" /> | |
<h:inputText id="creditLimit" value="#{customerBean.seleccionada.creditLimit}" title="CreditLimit" /> | |
<h:outputLabel value="Zip:" for="zip" /> | |
<h:selectOneMenu id="zip" value="#{customerBean.FK_Micro}" title="Zip" required="true" requiredMessage="The Zip field is required."> | |
<f:selectItems value="#{customerBean.todosMicro}" var="micro" itemLabel="#{micro.zipCode}" itemValue="#{micro.zipCode}"/> | |
</h:selectOneMenu> | |
<h:outputLabel value="DiscountCode:" for="discountCode" /> | |
<h:selectOneMenu id="discountCode" value="#{customerBean.FK_Discount}" title="DiscountCode" required="true" requiredMessage="The DiscountCode field is required."> | |
<f:selectItems value="#{customerBean.todosDiscount}" var="disc" itemLabel="#{disc.discountCode}" itemValue="#{disc.discountCode}"/> | |
</h:selectOneMenu> | |
<h:commandButton value="Crear" action="#{customerBean.AddCustomer()}" /> | |
<h:button value="Cancelar" outcome="listar.do" /> | |
</h:panelGrid> | |
</h:form> | |
</f:view> | |
</h:body> | |
</html> | |
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
<?xml version='1.0' encoding='UTF-8' ?> | |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml" | |
xmlns:h="http://java.sun.com/jsf/html" | |
xmlns:f="http://java.sun.com/jsf/core"> | |
<h:head> | |
<title>Facelet Title</title> | |
</h:head> | |
<h:body> | |
<f:view> | |
<h:form> | |
<h1><h:outputText value="List"/></h1> | |
<h:dataTable value="#{customerBean.todas}" var="item"> | |
<h:column> | |
<f:facet name="header"> | |
<h:outputText value="CustomerId"/> | |
</f:facet> | |
<h:outputText value="#{item.customerId}"/> | |
</h:column> | |
<h:column> | |
<f:facet name="header"> | |
<h:outputText value="Name"/> | |
</f:facet> | |
<h:outputText value="#{item.name}"/> | |
</h:column> | |
<h:column> | |
<f:facet name="header"> | |
<h:outputText value="Addressline1"/> | |
</f:facet> | |
<h:outputText value="#{item.addressline1}"/> | |
</h:column> | |
<h:column> | |
<f:facet name="header"> | |
<h:outputText value="Addressline2"/> | |
</f:facet> | |
<h:outputText value="#{item.addressline2}"/> | |
</h:column> | |
<h:column> | |
<f:facet name="header"> | |
<h:outputText value="City"/> | |
</f:facet> | |
<h:outputText value="#{item.city}"/> | |
</h:column> | |
<h:column> | |
<f:facet name="header"> | |
<h:outputText value="State"/> | |
</f:facet> | |
<h:outputText value="#{item.state}"/> | |
</h:column> | |
<h:column> | |
<f:facet name="header"> | |
<h:outputText value="Phone"/> | |
</f:facet> | |
<h:outputText value="#{item.phone}"/> | |
</h:column> | |
<h:column> | |
<f:facet name="header"> | |
<h:outputText value="Fax"/> | |
</f:facet> | |
<h:outputText value="#{item.fax}"/> | |
</h:column> | |
<h:column> | |
<f:facet name="header"> | |
<h:outputText value="Email"/> | |
</f:facet> | |
<h:outputText value="#{item.email}"/> | |
</h:column> | |
<h:column> | |
<f:facet name="header"> | |
<h:outputText value="CreditLimit"/> | |
</f:facet> | |
<h:outputText value="#{item.creditLimit}"/> | |
</h:column> | |
<h:column> | |
<f:facet name="header"> | |
<h:outputText value="Zip"/> | |
</f:facet> | |
<h:outputText value="#{item.zip.zipCode}"/> | |
</h:column> | |
<h:column> | |
<f:facet name="header"> | |
<h:outputText value="DiscountCode"/> | |
</f:facet> | |
<h:outputText value="#{item.discountCode.discountCode}"/> | |
</h:column> | |
<h:column> | |
<f:facet name="header"> | |
Acciones | |
<h:button outcome="editar.do" value="Crear"/> | |
</f:facet> | |
<h:commandButton value="Eliminar" > | |
<f:ajax execute="#{customerBean.eliminar(item)}" render="@all" /> | |
</h:commandButton> | |
</h:column> | |
</h:dataTable> | |
</h:form> | |
</f:view> | |
</h:body> | |
</html> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment