use of com.liferay.faces.util.i18n.I18n in project liferay-faces-alloy by liferay.
the class AlloyValidatorHelper method getMessage.
public static String getMessage(FacesContext facesContext, InputDate inputDate, String messageId) {
ExternalContext externalContext = facesContext.getExternalContext();
I18n i18n = I18nFactory.getI18nInstance(externalContext);
Object localeObject = inputDate.getLocale(facesContext);
Locale locale = getObjectAsLocale(localeObject);
return i18n.getMessage(facesContext, locale, messageId);
}
use of com.liferay.faces.util.i18n.I18n in project liferay-faces-alloy by liferay.
the class AlloyValidatorHelper method getMessage.
public static String getMessage(FacesContext facesContext, InputTime inputTime, String messageId) {
ExternalContext externalContext = facesContext.getExternalContext();
I18n i18n = I18nFactory.getI18nInstance(externalContext);
Object localeObject = inputTime.getLocale(facesContext);
Locale locale = getObjectAsLocale(localeObject);
return i18n.getMessage(facesContext, locale, messageId);
}
use of com.liferay.faces.util.i18n.I18n in project liferay-faces-alloy by liferay.
the class InputDateTime method validateValue.
protected final void validateValue(FacesContext facesContext, Object newValue, Date minDate, Date maxDate, TimeZone timeZone) {
String pattern = getPattern();
Date submittedDate = getObjectAsDate(newValue, pattern, timeZone);
try {
// the maximum date.
if (submittedDate.before(minDate) || submittedDate.after(maxDate)) {
setValid(false);
String validatorMessage = getValidatorMessage();
FacesMessage facesMessage;
if (validatorMessage != null) {
facesMessage = new FacesMessage(FacesMessage.SEVERITY_ERROR, validatorMessage, validatorMessage);
} else {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
simpleDateFormat.setTimeZone(timeZone);
String minDateString = simpleDateFormat.format(minDate);
String maxDateString = simpleDateFormat.format(maxDate);
Locale locale = getObjectAsLocale(getLocale(facesContext));
ExternalContext externalContext = facesContext.getExternalContext();
I18n i18n = I18nFactory.getI18nInstance(externalContext);
String message = i18n.getMessage(facesContext, locale, "please-enter-a-value-between-x-and-x", minDateString, maxDateString);
facesMessage = new FacesMessage(FacesMessage.SEVERITY_ERROR, message, message);
}
String clientId = getClientId(facesContext);
facesContext.addMessage(clientId, facesMessage);
} else {
setValid(true);
}
} catch (FacesException e) {
setValid(false);
String message = e.getMessage();
FacesMessage facesMessage = new FacesMessage(FacesMessage.SEVERITY_ERROR, message, message);
String clientId = getClientId(facesContext);
facesContext.addMessage(clientId, facesMessage);
}
}
use of com.liferay.faces.util.i18n.I18n in project liferay-faces-alloy by liferay.
the class InputFile method validateValue.
@Override
protected void validateValue(FacesContext facesContext, Object value) {
super.validateValue(facesContext, value);
if (isValid()) {
Long maxFileSize = getMaxFileSize();
String contentTypeSet = getContentTypes();
if ((maxFileSize != null) || (contentTypeSet != null)) {
Locale locale = facesContext.getViewRoot().getLocale();
ExternalContext externalContext = facesContext.getExternalContext();
I18n i18n = I18nFactory.getI18nInstance(externalContext);
String clientId = getClientId(facesContext);
@SuppressWarnings("unchecked") List<UploadedFile> uploadedFiles = (List<UploadedFile>) value;
for (UploadedFile uploadedFile : uploadedFiles) {
if ((maxFileSize != null) && (maxFileSize >= 0) && (uploadedFile.getSize() > maxFileSize)) {
String errorMessage = i18n.getMessage(facesContext, locale, "file-x-is-y-bytes-but-may-not-exceed-z-bytes", uploadedFile.getName(), uploadedFile.getSize(), maxFileSize);
handleInvalidFile(facesContext, clientId, uploadedFile, errorMessage);
}
String contentType = uploadedFile.getContentType();
if ((contentType == null) || ((contentTypeSet != null) && !contentTypeSet.contains(contentType))) {
String errorMessage = i18n.getMessage(facesContext, locale, "file-x-has-an-invalid-content-type-y", uploadedFile.getName(), contentType);
handleInvalidFile(facesContext, clientId, uploadedFile, errorMessage);
}
}
}
}
}
use of com.liferay.faces.util.i18n.I18n in project liferay-faces-alloy by liferay.
the class PaginatorRenderer method encodeSummary.
protected void encodeSummary(FacesContext facesContext, ResponseWriter responseWriter, Paginator paginator, String summaryPostion, Locale locale, int first, int curPageNumber, int rows, int rowCount, int pageCount) throws IOException {
// If the paginator is to appear above or below the pagination controls, then
boolean encodePaginationDiv = ("top".equals(summaryPostion) || "bottom".equals(summaryPostion));
if (encodePaginationDiv) {
// Encode the starting <div> element that represents the Bootstrap pagination component.
responseWriter.startElement("div", paginator);
responseWriter.startElement("ul", paginator);
responseWriter.writeAttribute("class", "pagination", null);
}
// Determine the first page number and the last page number.
int paginatorFirst = first + 1;
int paginatorLast = Math.min(first + rows, rowCount);
// Get an internationalized message that contains the pagination summary.
ExternalContext externalContext = facesContext.getExternalContext();
I18n i18n = I18nFactory.getI18nInstance(externalContext);
String message = i18n.getMessage(facesContext, locale, "results-x-x-of-x-page-x-of-x", paginatorFirst, paginatorLast, rowCount, curPageNumber, pageCount);
// Encode a list item inside the Bootstrap pagination component that contains the pagination summary message.
responseWriter.startElement("li", paginator);
responseWriter.startElement("span", paginator);
responseWriter.writeAttribute("class", "alloy-paginator-summary disabled", null);
responseWriter.writeText(message, paginator, null);
responseWriter.endElement("span");
responseWriter.endElement("li");
// If the paginator is to appear above or below the pagination controls, then
if (encodePaginationDiv) {
// Encode the closing </div> element that represents the Bootstrap pagination component.
responseWriter.endElement("ul");
responseWriter.endElement("div");
}
}
Aggregations