use of com.liferay.faces.alloy.render.internal.EscapedClientId in project liferay-faces-alloy by liferay.
the class DataTableRenderer method encodeJavaScriptCustom.
@Override
public void encodeJavaScriptCustom(FacesContext facesContext, UIComponent uiComponent) throws IOException {
DataTable dataTable = (DataTable) uiComponent;
String selectionMode = dataTable.getSelectionMode();
if ("checkbox".equals(selectionMode) || "radio".equals(selectionMode)) {
String dataTableClientId = dataTable.getClientId(facesContext);
EscapedClientId escapedDataTableClientId = new EscapedClientId(dataTableClientId);
String hiddenFieldClientId = dataTableClientId.concat("_selectedRowIndexes");
EscapedClientId escapedHiddenFieldClientId = new EscapedClientId(hiddenFieldClientId);
ResponseWriter responseWriter = facesContext.getResponseWriter();
// rowSelect
JavaScriptFragment rowSelectClientBehaviorScript = getRowEventClientBehaviorScript(facesContext, dataTable, dataTableClientId, RowSelectEvent.ROW_SELECT, "rowIndex");
// rowSelectRange
JavaScriptFragment rowSelectRangeClientBehaviorScript = getRowEventClientBehaviorScript(facesContext, dataTable, dataTableClientId, RowSelectRangeEvent.ROW_SELECT_RANGE, "rowIndexRange");
// rowDeselect
JavaScriptFragment rowDeselectClientBehaviorScript = getRowEventClientBehaviorScript(facesContext, dataTable, dataTableClientId, RowDeselectEvent.ROW_DESELECT, "rowIndex");
// rowDeSelectRange
JavaScriptFragment rowDeselectRangeClientBehaviorScript = getRowEventClientBehaviorScript(facesContext, dataTable, dataTableClientId, RowDeselectRangeEvent.ROW_DESELECT_RANGE, "rowIndexRange");
if ("checkbox".equals(selectionMode)) {
// Register the onclick event callback for the "Select All" checkbox.
String selectAllCheckboxClientId = dataTableClientId.concat("_selectAll");
EscapedClientId escapedSelectAllCheckboxClientId = new EscapedClientId(selectAllCheckboxClientId);
encodeFunctionCall(responseWriter, "LFAI.initDataTableSelectAllCheckbox", 'A', escapedDataTableClientId, escapedSelectAllCheckboxClientId, rowSelectRangeClientBehaviorScript, rowDeselectRangeClientBehaviorScript);
// Register the onclick event callback for each row-level checkbox.
encodeFunctionCall(responseWriter, "LFAI.initDataTableCheckboxSelection", 'A', escapedDataTableClientId, escapedHiddenFieldClientId, rowSelectClientBehaviorScript, rowDeselectClientBehaviorScript);
} else if ("radio".equals(selectionMode)) {
// Register the onclick event callback for each row-level radio button.
encodeFunctionCall(responseWriter, "LFAI.initDataTableRadioSelection", 'A', escapedDataTableClientId, escapedHiddenFieldClientId, rowSelectClientBehaviorScript, rowDeselectClientBehaviorScript);
}
}
}
use of com.liferay.faces.alloy.render.internal.EscapedClientId in project liferay-faces-alloy by liferay.
the class InputDateRenderer method encodeCalendar.
protected void encodeCalendar(FacesContext facesContext, ResponseWriter responseWriter, InputDate inputDate, boolean first) throws IOException {
// The calendar attribute value provides the opportunity to specify dateClick events, minDate, maxDate as
// key:value pairs via JSON syntax. For example: "calendar: {minDate: new Date(2015,1,1,0,0,0,0)}"
boolean calendarFirst = true;
encodeNonEscapedObject(responseWriter, "calendar", "", first);
responseWriter.write("{");
Object maxDateObject = inputDate.getMaxDate();
if (maxDateObject != null) {
encodeDate(responseWriter, inputDate, "maximumDate", maxDateObject, calendarFirst);
calendarFirst = false;
}
Object minDateObject = inputDate.getMinDate();
if (minDateObject != null) {
encodeDate(responseWriter, inputDate, "minimumDate", minDateObject, calendarFirst);
calendarFirst = false;
}
String showOn = inputDate.getShowOn();
boolean showOnButton = "button".equals(showOn);
Map<String, List<ClientBehavior>> clientBehaviorMap = inputDate.getClientBehaviors();
List<ClientBehavior> valueChangeClientBehaviors = clientBehaviorMap.get(VALUE_CHANGE);
boolean valueChangeClientBehaviorsNotEmpty = (valueChangeClientBehaviors != null) && !valueChangeClientBehaviors.isEmpty();
if (showOnButton || valueChangeClientBehaviorsNotEmpty) {
encodeNonEscapedObject(responseWriter, "on", "", calendarFirst);
responseWriter.write("{");
encodeNonEscapedObject(responseWriter, "dateClick", "", true);
responseWriter.write("function(event){");
String clientId = inputDate.getClientId(facesContext);
String inputClientId = clientId.concat(INPUT_SUFFIX);
EscapedClientId escapedInputClientId = new EscapedClientId(inputClientId);
JavaScriptFragment selectable = new JavaScriptFragment("this._canBeSelected(event.date)");
JavaScriptFragment date = null;
if (showOnButton) {
// Each time a date is clicked, the input must be updated via javascript because the datePicker is not
// attached to the input.
String datePattern = inputDate.getPattern();
String mask = getMaskFromDatePattern(datePattern);
String escapedMask = RendererUtil.escapeJavaScript(mask);
date = new JavaScriptFragment("A.Date.format(event.date,{format:'".concat(escapedMask).concat("'})"));
}
encodeFunctionCall(responseWriter, "LFAI.inputDateTimePickerSelect", 'A', escapedInputClientId, selectable, date, valueChangeClientBehaviorsNotEmpty);
responseWriter.append(";}");
responseWriter.write("}");
calendarFirst = false;
}
responseWriter.write("}");
}
use of com.liferay.faces.alloy.render.internal.EscapedClientId in project liferay-faces-alloy by liferay.
the class InputTimeRenderer method encodeAutocomplete.
protected void encodeAutocomplete(FacesContext facesContext, ResponseWriter responseWriter, InputTime inputTime, boolean first) throws IOException {
encodeNonEscapedObject(responseWriter, "autocomplete", "", first);
responseWriter.write("{");
boolean autoCompleteFirst = true;
boolean activateFirstItem = inputTime.isActivateFirstItem();
encodeBoolean(responseWriter, ACTIVATE_FIRST_ITEM, activateFirstItem, autoCompleteFirst);
autoCompleteFirst = false;
Boolean circular = inputTime.getCircular();
if (circular != null) {
encodeBoolean(responseWriter, CIRCULAR, circular, autoCompleteFirst);
autoCompleteFirst = false;
}
String filterType = inputTime.getFilterType();
if (filterType != null) {
encodeString(responseWriter, "resultFilters", filterType, autoCompleteFirst);
autoCompleteFirst = false;
}
String height = inputTime.getHeight();
if (height != null) {
encodeString(responseWriter, HEIGHT, height, autoCompleteFirst);
autoCompleteFirst = false;
}
String highlighterType = inputTime.getHighlighterType();
if (highlighterType != null) {
encodeString(responseWriter, "resultHighlighter", highlighterType, autoCompleteFirst);
autoCompleteFirst = false;
}
Integer maxResults = inputTime.getMaxResults();
if (maxResults != null) {
encodeString(responseWriter, MAX_RESULTS, maxResults, autoCompleteFirst);
autoCompleteFirst = false;
}
Integer queryDelay = inputTime.getQueryDelay();
if (queryDelay != null) {
encodeString(responseWriter, QUERY_DELAY, queryDelay, autoCompleteFirst);
autoCompleteFirst = false;
}
Boolean scrollIntoView = inputTime.getScrollIntoView();
if (scrollIntoView != null) {
encodeBoolean(responseWriter, SCROLL_INTO_VIEW, scrollIntoView, autoCompleteFirst);
autoCompleteFirst = false;
}
String showOn = inputTime.getShowOn();
boolean showOnButton = "button".equals(showOn);
Map<String, List<ClientBehavior>> clientBehaviorMap = inputTime.getClientBehaviors();
List<ClientBehavior> valueChangeClientBehaviors = clientBehaviorMap.get(VALUE_CHANGE);
boolean valueChangeClientBehaviorsNotEmpty = (valueChangeClientBehaviors != null) && !valueChangeClientBehaviors.isEmpty();
if (showOnButton || valueChangeClientBehaviorsNotEmpty) {
encodeNonEscapedObject(responseWriter, "after", "", autoCompleteFirst);
responseWriter.write("{");
encodeNonEscapedObject(responseWriter, "select", "", true);
responseWriter.write("function(event){");
String clientId = inputTime.getClientId(facesContext);
String inputClientId = clientId.concat(INPUT_SUFFIX);
EscapedClientId escapedInputClientId = new EscapedClientId(inputClientId);
boolean selectable = true;
JavaScriptFragment time = null;
if (showOnButton) {
time = new JavaScriptFragment("event.result.text");
}
encodeFunctionCall(responseWriter, "LFAI.inputDateTimePickerSelect", 'A', escapedInputClientId, selectable, time, valueChangeClientBehaviorsNotEmpty);
responseWriter.append(";}");
responseWriter.write("}");
autoCompleteFirst = false;
}
responseWriter.write("}");
}
use of com.liferay.faces.alloy.render.internal.EscapedClientId 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);
}
}
}
Aggregations