<%--
  % This Javer Server Page is part of the iX JSP tutorial.
  % Check Customer
  % 
 --%>


<%-- Setting up an error page --%>
<%@ page errorPage="/jspTutorial/errorpage.jsp" %>


<%-- import needed java classes --%>	 
<%@ page import="java.util.*" %>
<%@ page import="java.text.*" %>
<%@ page import="de.ix.jspTutorial.model.Customer" %>

<jsp:useBean id="customer" class="de.ix.jspTutorial.model.Customer" scope="session"/>
<jsp:setProperty name="customer" property="*" />

<jsp:useBean id="pizzaAccessor" type="de.ix.jspTutorial.model.PizzaAccessor" scope="application"/>

<%
boolean isLoginValid = false ;
if(customer.getId() > 0) {
   isLoginValid = pizzaAccessor.checkCustomer(customer) ;
} else {
   isLoginValid = pizzaAccessor.newCustomer(customer) ;
}
if(isLoginValid) 
{
%>
	<jsp:forward page="choice.jsp" />
<%
} else 
{
   session.removeAttribute("customer") ;   
%>
	<jsp:forward page="customer.jsp" />
<%
} %>