/** * Dynject 1.0 Copyright (C) 2007 Alexander Hristov * This file is part of Dynject 1.0 * * Dynject is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License (LGPL) as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Dynject is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with Dynject. If not, see . */ package testweb; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.planetalia.dynject.injection.Shell; import com.planetalia.dynject.sources.HttpRequestSource; import com.planetalia.dynject.validation.ErrorMap; @SuppressWarnings("all") public class SampleServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { doPost(request,response); } public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException { Customer customer = new Customer(); ErrorMap errorMap = Shell.assign(customer, new HttpRequestSource(request)); response.setContentType("text/html"); PrintWriter out = response.getWriter(); if (errorMap.size() > 0) { out.println("

Errors

"); for(String field : errorMap.keySet()) { out.println(field +" field : " + errorMap.get(field).get(0).getMessage()+"
"); } } out.println("

Data after validation

"); out.println("Customer Name = "+customer.customer+"
"); if (customer.birthdate != null) out.println("Customer BirthDate = "+customer.birthdate.getTime()+"
"); out.println("Discuount = "+customer.discount+"
"); out.flush(); } }