2 * Copyright (C) 2016 Roland Haeder
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package org.mxchange.pizzaapplication.validator.birthday;
19 import java.text.MessageFormat;
20 import java.util.Date;
21 import javax.faces.component.UIComponent;
22 import javax.faces.context.FacesContext;
23 import javax.faces.validator.FacesValidator;
24 import javax.faces.validator.Validator;
25 import javax.faces.validator.ValidatorException;
26 import javax.naming.Context;
27 import javax.naming.InitialContext;
28 import javax.naming.NamingException;
29 import org.mxchange.jcoreee.validator.date.BaseDateValidator;
30 import org.mxchange.jcoreeelogger.beans.local.logger.Log;
31 import org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal;
34 * A birthday validator
36 * @author Roland Haeder<roland@mxchange.org>
38 @FacesValidator("BirthdayValidator")
39 public class PizzaBirthdayValidator extends BaseDateValidator implements Validator {
44 private static final long serialVersionUID = 28_735_756_819_460L;
50 private LoggerBeanLocal loggerBeanLocal;
55 public PizzaBirthdayValidator () {
58 // Get initial context
59 Context context = new InitialContext();
62 this.loggerBeanLocal = (LoggerBeanLocal) context.lookup("java:global/jcore-logger-ejb/logger!org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal"); //NOI18N
63 } catch (final NamingException ex) {
64 // Continue to throw it
65 throw new RuntimeException(MessageFormat.format("context.lookup() failed: {0}", ex.getMessage()), ex); //NOI18N
70 public void validate (final FacesContext context, final UIComponent component, final Object value) throws ValidatorException {
72 this.loggerBeanLocal.logTrace(MessageFormat.format("validate: context={0},component={1},value={2} - CALLED!", context, component, value)); //NOI18N
74 // All accepted, required fields
75 String[] requiredFields = {"birthday", "contactBirthday"}; //NOI18N
77 // Pre-validation (example: not null, not a string, empty string ...)
78 super.preValidate(context, component, value, requiredFields, false);
81 Date birthday = (Date) value;
83 // @TODO Finish this, e.g. load maximum,minimum birthday from properties file
86 this.loggerBeanLocal.logTrace("validate: EXIT!"); //NOI18N