use of com.liferay.faces.util.client.BrowserSniffer in project liferay-faces-alloy by liferay.
the class InputDateTimeRenderer method getModules.
protected String[] getModules(String defaultModule, FacesContext facesContext, UIComponent uiComponent) {
String[] modules = new String[] { defaultModule };
BrowserSniffer browserSniffer = BrowserSnifferFactory.getBrowserSnifferInstance(facesContext.getExternalContext());
InputDateTime inputDateTime = (InputDateTime) uiComponent;
if (isNative(browserSniffer, inputDateTime)) {
modules[0] = defaultModule.concat("-native");
} else {
Map<String, List<ClientBehavior>> clientBehaviorMap = inputDateTime.getClientBehaviors();
List<ClientBehavior> valueChangeClientBehaviors = clientBehaviorMap.get(VALUE_CHANGE);
if ((valueChangeClientBehaviors != null) && !valueChangeClientBehaviors.isEmpty()) {
modules = StringHelper.append(modules, NODE_EVENT_SIMULATE);
}
}
return modules;
}
use of com.liferay.faces.util.client.BrowserSniffer in project liferay-faces-alloy by liferay.
the class InputTime method getPattern.
@Override
public String getPattern() {
String timePattern;
FacesContext facesContext = FacesContext.getCurrentInstance();
BrowserSniffer browserSniffer = BrowserSnifferFactory.getBrowserSnifferInstance(facesContext.getExternalContext());
if (browserSniffer.isMobile() && isNativeWhenMobile()) {
timePattern = DEFAULT_HTML5_TIME_PATTERN;
} else {
timePattern = super.getPattern();
}
return timePattern;
}
use of com.liferay.faces.util.client.BrowserSniffer in project liferay-faces-alloy by liferay.
the class InputTimeRenderer method getAlloyClassName.
@Override
public String getAlloyClassName(FacesContext facesContext, UIComponent uiComponent) {
String alloyClassName = super.getAlloyClassName(facesContext, uiComponent);
BrowserSniffer browserSniffer = BrowserSnifferFactory.getBrowserSnifferInstance(facesContext.getExternalContext());
InputTime inputTime = (InputTime) uiComponent;
if (isNative(browserSniffer, inputTime)) {
alloyClassName = alloyClassName.concat("Native");
}
return alloyClassName;
}
use of com.liferay.faces.util.client.BrowserSniffer in project liferay-faces-alloy by liferay.
the class InputTimeRenderer method encodeHiddenAttributes.
@Override
protected void encodeHiddenAttributes(FacesContext facesContext, ResponseWriter responseWriter, InputTime inputTime, boolean first) throws IOException {
BrowserSniffer browserSniffer = BrowserSnifferFactory.getBrowserSnifferInstance(facesContext.getExternalContext());
if (!isNative(browserSniffer, inputTime)) {
encodeAutocomplete(facesContext, responseWriter, inputTime, first);
first = false;
encodeHiddenAttributesInputDateTime(facesContext, responseWriter, inputTime, first);
first = false;
}
}
use of com.liferay.faces.util.client.BrowserSniffer in project liferay-faces-alloy by liferay.
the class InputTimeRenderer method encodeJavaScriptCustom.
@Override
public void encodeJavaScriptCustom(FacesContext facesContext, UIComponent uiComponent) throws IOException {
InputTime inputTime = (InputTime) uiComponent;
String clientVarName = getClientVarName(facesContext, inputTime);
String clientKey = inputTime.getClientKey();
if (clientKey == null) {
clientKey = clientVarName;
}
ResponseWriter responseWriter = facesContext.getResponseWriter();
BrowserSniffer browserSniffer = BrowserSnifferFactory.getBrowserSnifferInstance(facesContext.getExternalContext());
if (isNative(browserSniffer, inputTime)) {
JavaScriptFragment liferayComponent = new JavaScriptFragment("Liferay.component('" + clientKey + "')");
String clientId = uiComponent.getClientId(facesContext);
String inputClientId = clientId.concat(INPUT_SUFFIX);
// Get the max and min times in the HTML5 format which does not include seconds.
int defaultHTML5PatternLength = InputTime.DEFAULT_HTML5_TIME_PATTERN.length();
String maxTime = inputTime.getMaxTime().substring(0, defaultHTML5PatternLength);
String minTime = inputTime.getMinTime().substring(0, defaultHTML5PatternLength);
encodeFunctionCall(responseWriter, "LFAI.initDateTimePickerMobile", liferayComponent, inputClientId, maxTime, minTime);
} else {
encodeLiferayComponentVar(responseWriter, clientVarName, clientKey);
// Replace the default TimePicker._setValues() method with setValues() (defined in alloy.js) which simply
// passes values through to the autocomplete without processing them.
responseWriter.write(clientVarName);
responseWriter.write("._setValues=LFAI.timePickerSetValues;");
// Set the values of the timePicker.
responseWriter.write(clientVarName);
responseWriter.write(".set('values',[");
String minTimeStamp = inputTime.getMinTime();
String maxTimeStamp = inputTime.getMaxTime();
long minTime;
long maxTime;
try {
minTime = getMillisFromTimeStamp(minTimeStamp);
maxTime = getMillisFromTimeStamp(maxTimeStamp);
} catch (ParseException e) {
throw new IOException(e);
}
if (minTime > maxTime) {
throw new IOException("minTime must not be later than maxTime.");
}
String timePattern = inputTime.getPattern();
Object objectLocale = inputTime.getLocale();
Locale locale = inputTime.getObjectAsLocale(objectLocale);
TimeZone timeZone = TimeZone.getTimeZone("Greenwich");
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(timePattern, locale);
simpleDateFormat.setTimeZone(timeZone);
Integer millisecondStep = inputTime.getStep() * 1000;
boolean firstTimeStamp = true;
if (millisecondStep < 1) {
throw new IOException("step cannot be less than 1.");
}
// step, and printing each resulting value.
for (long milliseconds = minTime; milliseconds <= maxTime; milliseconds = milliseconds + millisecondStep) {
if (!firstTimeStamp) {
responseWriter.write(",");
} else {
firstTimeStamp = false;
}
Date time = new Date(milliseconds);
String dateString = simpleDateFormat.format(time);
String escapedDateString = RendererUtil.escapeJavaScript(dateString);
responseWriter.write("'");
responseWriter.write(escapedDateString);
responseWriter.write("'");
}
responseWriter.write("]);");
}
}
Aggregations