use of com.liferay.faces.alloy.component.inputdate.InputDate in project liferay-faces-alloy by liferay.
the class WeekdayValidator method validate.
@Override
public void validate(FacesContext facesContext, UIComponent uiComponent, Object object) throws ValidatorException {
if (object != null) {
Date date;
InputDate inputDate = (InputDate) uiComponent;
String timeZoneString = inputDate.getTimeZone();
TimeZone timeZone = TimeZone.getTimeZone(timeZoneString);
if (object instanceof Date) {
date = (Date) object;
} else {
String dateString = object.toString();
String datePattern = inputDate.getPattern();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(datePattern);
simpleDateFormat.setTimeZone(timeZone);
try {
date = simpleDateFormat.parse(dateString);
} catch (ParseException e) {
String message = AlloyValidatorHelper.getMessage(facesContext, inputDate, "invalid-selection");
FacesMessage facesMessage = new FacesMessage(FacesMessage.SEVERITY_ERROR, message, message);
throw new ValidatorException(facesMessage, e);
}
}
Calendar calendar = new GregorianCalendar(timeZone);
calendar.setTime(date);
int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
if ((dayOfWeek == Calendar.SATURDAY) || (dayOfWeek == Calendar.SUNDAY)) {
String message = AlloyValidatorHelper.getMessage(facesContext, inputDate, "sat-and-sun-are-not-valid");
FacesMessage facesMessage = new FacesMessage(FacesMessage.SEVERITY_WARN, message, message);
throw new ValidatorException(facesMessage);
}
}
}
use of com.liferay.faces.alloy.component.inputdate.InputDate in project liferay-faces-alloy by liferay.
the class InputDateRenderer method getAlloyClassName.
@Override
public String getAlloyClassName(FacesContext facesContext, UIComponent uiComponent) {
String alloyClassName = super.getAlloyClassName(facesContext, uiComponent);
BrowserSniffer browserSniffer = BrowserSnifferFactory.getBrowserSnifferInstance(facesContext.getExternalContext());
InputDate inputDate = (InputDate) uiComponent;
if (isNative(browserSniffer, inputDate)) {
alloyClassName = alloyClassName.concat("Native");
}
return alloyClassName;
}
use of com.liferay.faces.alloy.component.inputdate.InputDate in project liferay-faces-alloy by liferay.
the class InputDateRenderer method encodeJavaScriptCustom.
@Override
public void encodeJavaScriptCustom(FacesContext facesContext, UIComponent uiComponent) throws IOException {
BrowserSniffer browserSniffer = BrowserSnifferFactory.getBrowserSnifferInstance(facesContext.getExternalContext());
InputDate inputDate = (InputDate) uiComponent;
String showOn = inputDate.getShowOn();
if (isNative(browserSniffer, inputDate) || "button".equals(showOn)) {
String clientVarName = getClientVarName(facesContext, inputDate);
String clientKey = inputDate.getClientKey();
if (clientKey == null) {
clientKey = clientVarName;
}
JavaScriptFragment liferayComponent = new JavaScriptFragment("Liferay.component('" + clientKey + "')");
ResponseWriter responseWriter = facesContext.getResponseWriter();
if (isNative(browserSniffer, inputDate)) {
String clientId = uiComponent.getClientId(facesContext);
String inputClientId = clientId.concat(INPUT_SUFFIX);
Object maxDateObject = inputDate.getMaxDate();
Object minDateObject = inputDate.getMinDate();
String maxDateString = null;
String minDateString = null;
if ((maxDateObject != null) || (minDateObject != null)) {
String datePattern = inputDate.getPattern();
String timeZoneString = inputDate.getTimeZone();
TimeZone timeZone = TimeZone.getTimeZone(timeZoneString);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(InputDate.DEFAULT_HTML5_DATE_PATTERN, Locale.ENGLISH);
if (maxDateObject != null) {
Date maxDate = inputDate.getObjectAsDate(maxDateObject, datePattern, timeZone);
maxDateString = simpleDateFormat.format(maxDate);
}
if (maxDateObject != null) {
Date minDate = inputDate.getObjectAsDate(minDateObject, datePattern, timeZone);
minDateString = simpleDateFormat.format(minDate);
}
}
encodeFunctionCall(responseWriter, "LFAI.initDateTimePickerMobile", liferayComponent, inputClientId, maxDateString, minDateString);
} else if ("button".equals(showOn)) {
String clientId = inputDate.getClientId(facesContext);
String inputClientId = clientId.concat(INPUT_SUFFIX);
EscapedClientId escapedInputClientId = new EscapedClientId(inputClientId);
encodeFunctionCall(responseWriter, "LFAI.initDatePickerShowOnButton", 'A', escapedInputClientId, liferayComponent);
}
}
}
use of com.liferay.faces.alloy.component.inputdate.InputDate in project liferay-faces-alloy by liferay.
the class InputDateRenderer method getModules.
@Override
public String[] getModules(FacesContext facesContext, UIComponent uiComponent) {
String[] modules = getModules(MODULES[0], facesContext, uiComponent);
InputDate inputDate = (InputDate) uiComponent;
String showOn = inputDate.getShowOn();
if ("button".equals(showOn)) {
modules = StringHelper.append(modules, "aui-datatype-date-parse");
}
return modules;
}
use of com.liferay.faces.alloy.component.inputdate.InputDate in project liferay-faces-alloy by liferay.
the class InputDateRenderer method encodeDate.
protected void encodeDate(ResponseWriter responseWriter, InputDate inputDate, String attributeName, Object dateObject, boolean first) throws IOException {
String datePattern = inputDate.getPattern();
String timeZoneString = inputDate.getTimeZone();
TimeZone timeZone = TimeZone.getTimeZone(timeZoneString);
Date date = inputDate.getObjectAsDate(dateObject, datePattern, timeZone);
// Note: The JavaScript date object expects zero-based month numbers, so it is necessary to offset the month
// by 1.
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("'new Date'(yyyy,M-1,d,0,0,0,0)");
simpleDateFormat.setTimeZone(timeZone);
String dateString = simpleDateFormat.format(date);
encodeNonEscapedObject(responseWriter, attributeName, dateString, first);
}
Aggregations