protected void encodeMultipleMarkup(FacesContext context, AutoComplete ac) throws IOException { ResponseWriter writer = context.getResponseWriter(); String clientId = ac.getClientId(context); String inputId = clientId + "_input"; if (ac.isValid()) { values = (List) ac.getValue(); Object submittedValue = ac.getSubmittedValue(); try { values = (List) getConvertedValue(context, ac, submittedValue); boolean disabled = ac.isDisabled(); String title = ac.getTitle(); String style = ac.getStyle(); String styleClass = ac.getStyleClass(); styleClass = styleClass == null ? AutoComplete.MULTIPLE_STYLE_CLASS : AutoComplete.MULTIPLE_STYLE_CLASS + " " + styleClass; String listClass = ac.isDropdown() ? AutoComplete.MULTIPLE_CONTAINER_WITH_DROPDOWN_CLASS : AutoComplete.MULTIPLE_CONTAINER_CLASS; listClass = disabled ? listClass + " ui-state-disabled" : listClass; listClass = ac.isValid() ? listClass : listClass + " ui-state-error"; String autocompleteProp = (ac.getAutocomplete() != null) ? ac.getAutocomplete() : "off"; String var = ac.getVar(); boolean pojo = var != null; Collection<Object> items = ac.isUnique() ? new HashSet<Object>(values) : values; for (Object value : items) { Object itemValue = null;
@Override public void queueEvent(FacesEvent event) { FacesContext context = getFacesContext(); Map<String, String> params = context.getExternalContext().getRequestParameterMap(); String eventName = params.get(Constants.RequestParams.PARTIAL_BEHAVIOR_EVENT_PARAM); Object selectedItemValue = convertValue(context, params.get(getClientId(context) + "_itemSelect")); SelectEvent selectEvent = new SelectEvent(this, ajaxBehaviorEvent.getBehavior(), selectedItemValue); selectEvent.setPhaseId(ajaxBehaviorEvent.getPhaseId()); Object unselectedItemValue = convertValue(context, params.get(getClientId(context) + "_itemUnselect")); UnselectEvent unselectEvent = new UnselectEvent(this, ajaxBehaviorEvent.getBehavior(), unselectedItemValue); unselectEvent.setPhaseId(ajaxBehaviorEvent.getPhaseId());
protected void encodeScript(FacesContext context, AutoComplete ac) throws IOException { String clientId = ac.getClientId(context); WidgetBuilder wb = getWidgetBuilder(context); wb.init("AutoComplete", ac.resolveWidgetVar(), clientId); wb.attr("minLength", ac.getMinQueryLength(), 1) .attr("delay", ac.getQueryDelay()) .attr("forceSelection", ac.isForceSelection(), false) .attr("scrollHeight", ac.getScrollHeight(), Integer.MAX_VALUE) .attr("multiple", ac.isMultiple(), false) .attr("appendTo", SearchExpressionFacade.resolveClientId(context, ac, ac.getAppendTo()), null) .attr("grouping", ac.getValueExpression(AutoComplete.PropertyKeys.groupBy.toString()) != null, false) .attr("queryEvent", ac.getQueryEvent(), null) .attr("dropdownMode", ac.getDropdownMode(), null) .attr("autoHighlight", ac.isAutoHighlight(), true) .attr("myPos", ac.getMy(), null) .attr("atPos", ac.getAt(), null) .attr("active", ac.isActive(), true) .attr("unique", ac.isUnique(), false) .attr("dynamic", ac.isDynamic(), false) .attr("autoSelection", ac.isAutoSelection(), true); if (ac.isCache()) { wb.attr("cache", true).attr("cacheTimeout", ac.getCacheTimeout()); String effect = ac.getEffect(); if (effect != null) { wb.attr("effect", effect, null) .attr("effectDuration", ac.getEffectDuration(), Integer.MAX_VALUE);
@Override public String getInputClientId() { return getClientId(getFacesContext()) + "_input"; }
public List<Column> getColums() { List<Column> columns = new ArrayList<>(); for (int i = 0; i < getChildCount(); i++) { UIComponent child = getChildren().get(i); if (child instanceof Column) { columns.add((Column) child); } } return columns; }
protected void decodeSingle(FacesContext context, AutoComplete ac) { Map<String, String> params = context.getExternalContext().getRequestParameterMap(); String clientId = ac.getClientId(context); String valueParam = (ac.getVar() != null) ? clientId + "_hinput" : clientId + "_input"; String submittedValue = params.get(valueParam); if (submittedValue != null) { ac.setSubmittedValue(submittedValue); } }
protected void encodeSuggestionsAsTable(FacesContext context, AutoComplete ac, List items, Converter converter) throws IOException { ResponseWriter writer = context.getResponseWriter(); String var = ac.getVar(); Map<String, Object> requestMap = context.getExternalContext().getRequestMap(); boolean pojo = var != null; UIComponent itemtip = ac.getFacet("itemtip"); boolean hasHeader = false; boolean hasGroupByTooltip = (ac.getValueExpression(AutoComplete.PropertyKeys.groupByTooltip.toString()) != null); for (int i = 0; i < ac.getColums().size(); i++) { Column column = ac.getColums().get(i); if (column.isRendered() && (column.getHeaderText() != null || column.getFacet("header") != null)) { hasHeader = true; for (int i = 0; i < ac.getColums().size(); i++) { Column column = ac.getColums().get(i); if (!column.isRendered()) { continue; String value = converter == null ? String.valueOf(ac.getItemValue()) : converter.getAsString(context, ac, ac.getItemValue()); writer.writeAttribute("data-item-value", value, null); writer.writeAttribute("data-item-label", ac.getItemLabel(), null); writer.writeAttribute("data-item-class", ac.getItemStyleClass(), null); writer.writeAttribute("data-item-group", ac.getGroupBy(), null); writer.writeAttribute("data-item-group-tooltip", ac.getGroupByTooltip(), null); for (int i = 0; i < ac.getColums().size(); i++) { Column column = ac.getColums().get(i); if (column.isRendered()) {
protected void encodeInput(FacesContext context, AutoComplete ac, String clientId) throws IOException { ResponseWriter writer = context.getResponseWriter(); boolean disabled = ac.isDisabled(); String var = ac.getVar(); String itemLabel; String defaultStyleClass = ac.isDropdown() ? AutoComplete.INPUT_WITH_DROPDOWN_CLASS : AutoComplete.INPUT_CLASS; String styleClass = disabled ? defaultStyleClass + " ui-state-disabled" : defaultStyleClass; styleClass = ac.isValid() ? styleClass : styleClass + " ui-state-error"; String inputStyle = ac.getInputStyle(); String inputStyleClass = ac.getInputStyleClass(); inputStyleClass = (inputStyleClass == null) ? styleClass : styleClass + " " + inputStyleClass; String autocompleteProp = (ac.getAutocomplete() != null) ? ac.getAutocomplete() : "off"; writer.writeAttribute("type", ac.getType(), null); writer.writeAttribute("class", inputStyleClass, null); writer.writeAttribute("autocomplete", autocompleteProp, null); if (ac.isValid()) { requestMap.put(var, ac.getValue()); itemLabel = ac.getItemLabel(); Object submittedValue = ac.getSubmittedValue(); Object value = ac.getValue(); itemLabel = ac.getItemLabel(); Object item = getConvertedValue(context, ac, String.valueOf(submittedValue)); requestMap.put(var, item); itemLabel = ac.getItemLabel();
protected void encodeInput(FacesContext context, AutoComplete ac, String clientId) throws IOException { ResponseWriter writer = context.getResponseWriter(); boolean disabled = ac.isDisabled(); String var = ac.getVar(); String itemLabel; String defaultStyleClass = ac.isDropdown() ? AutoComplete.INPUT_WITH_DROPDOWN_CLASS : AutoComplete.INPUT_CLASS; String styleClass = disabled ? defaultStyleClass + " ui-state-disabled" : defaultStyleClass; styleClass = ac.isValid() ? styleClass : styleClass + " ui-state-error"; String inputStyle = ac.getInputStyle(); String inputStyleClass = ac.getInputStyleClass(); inputStyleClass = (inputStyleClass == null) ? styleClass : styleClass + " " + inputStyleClass; String labelledBy = ac.getLabelledBy(); writer.writeAttribute("type", ac.getType(), null); writer.writeAttribute("class", inputStyleClass, null); writer.writeAttribute("autocomplete", "off", null); if (ac.isValid()) { requestMap.put(var, ac.getValue()); itemLabel = ac.getItemLabel(); Object submittedValue = ac.getSubmittedValue(); Object value = ac.getValue(); itemLabel = ac.getItemLabel(); Object item = getConvertedValue(context, ac, String.valueOf(submittedValue)); requestMap.put(var, item); itemLabel = ac.getItemLabel();
protected void encodeInput(FacesContext context, AutoComplete ac) throws IOException { ResponseWriter writer = context.getResponseWriter(); String clientId = ac.getClientId(context); String inputId = clientId + "_input"; String var = ac.getVar(); String itemLabel; if (ac.isValid()) { requestMap.put(var, ac.getValue()); itemLabel = ac.getItemLabel(); Object submittedValue = ac.getSubmittedValue(); Object value = ac.getValue(); itemLabel = ac.getItemLabel(); String.valueOf(submittedValue)); requestMap.put(var, item); itemLabel = ac.getItemLabel(); if (ac.isDisabled()) { writer.writeAttribute("disabled", "disabled", null); if (ac.isReadonly()) { writer.writeAttribute("readonly", "readonly", null); if (ac.getVar() != null) { encodeHiddenInput(context, ac, clientId);
protected void encodeSingleMarkup(FacesContext context, AutoComplete ac) throws IOException { ResponseWriter writer = context.getResponseWriter(); String clientId = ac.getClientId(context); String styleClass = ac.getStyleClass(); styleClass = styleClass == null ? AutoComplete.STYLE_CLASS : AutoComplete.STYLE_CLASS + " " + styleClass; writer.startElement("span", null); writer.writeAttribute("id", clientId, null); writer.writeAttribute("class", styleClass, null); if (ac.getStyle() != null) { writer.writeAttribute("style", ac.getStyle(), null); } encodeInput(context, ac, clientId); if (ac.getVar() != null) { encodeHiddenInput(context, ac, clientId); } if (ac.isDropdown()) { encodeDropDown(context, ac); } if (!ac.isDynamic()) { encodePanel(context, ac); } writer.endElement("span"); }
protected void encodePanel(FacesContext context, AutoComplete ac) throws IOException { ResponseWriter writer = context.getResponseWriter(); String styleClass = ac.getPanelStyleClass(); styleClass = styleClass == null ? AutoComplete.PANEL_CLASS : AutoComplete.PANEL_CLASS + " " + styleClass; writer.startElement("span", null); writer.writeAttribute("id", ac.getClientId(context) + "_panel", null); writer.writeAttribute("class", styleClass, null); writer.writeAttribute("role", "listbox", null); if (ac.getPanelStyle() != null) { writer.writeAttribute("style", ac.getPanelStyle(), null); } if (ac.isDynamic() && ac.isDynamicLoadRequest(context)) { Map<String, String> params = context.getExternalContext().getRequestParameterMap(); String query = params.get(ac.getClientId(context) + "_query"); encodeResults(context, ac, query); } writer.endElement("span"); }
@Override protected void encodeScript(FacesContext context, AutoComplete ac) throws IOException { String clientId = ac.getClientId(context); WidgetBuilder wb = getWidgetBuilder(context); wb.init("AutoComplete", ac.resolveWidgetVar(), clientId); wb.attr("minLength", ac.getMinQueryLength(), 1) .attr("delay", ac.getQueryDelay(), 300); String emptyMessage = ac.getEmptyMessage(); if (emptyMessage != null) { wb.attr("emptyMessage", emptyMessage, null); } encodeClientBehaviors(context, ac); wb.finish(); }
@Override public void decode(FacesContext context, UIComponent component) { AutoComplete ac = (AutoComplete) component; String clientId = ac.getClientId(context); Map<String, String> params = context.getExternalContext().getRequestParameterMap(); if (ac.isDisabled() || ac.isReadonly()) { return; } if (ac.isMultiple()) { decodeMultiple(context, ac); } else { decodeSingle(context, ac); } decodeBehaviors(context, ac); // AutoComplete event String query = params.get(clientId + "_query"); if (query != null) { AutoCompleteEvent autoCompleteEvent = new AutoCompleteEvent(ac, query); autoCompleteEvent.setPhaseId(PhaseId.APPLY_REQUEST_VALUES); ac.queueEvent(autoCompleteEvent); } }
@Override protected void encodeSuggestions(FacesContext context, AutoComplete ac, List items) throws IOException { ResponseWriter writer = context.getResponseWriter(); String var = ac.getVar(); boolean pojo = (var != null); Map<String, Object> requestMap = context.getExternalContext().getRequestMap(); Converter converter = ComponentUtils.getConverter(context, ac); boolean hasContent = (ac.getChildCount() > 0); String value = (converter == null) ? (String) ac.getItemValue() : converter.getAsString(context, ac, ac.getItemValue()); writer.writeAttribute("data-item-value", value, null); writer.writeAttribute("data-item-label", ac.getItemLabel(), null); writer.writeAttribute("data-item-class", ac.getItemStyleClass(), null); writer.writeText(ac.getItemLabel(), null); writer.writeAttribute("data-item-label", item, null); writer.writeAttribute("data-item-value", item, null); writer.writeAttribute("data-item-class", ac.getItemStyleClass(), null);
@Override public void decode(FacesContext context, UIComponent component) { AutoComplete ac = (AutoComplete) component; String clientId = ac.getClientId(context); Map<String, String> params = context.getExternalContext().getRequestParameterMap(); if (!shouldDecode(ac)) { return; } if (ac.isMultiple()) { decodeMultiple(context, ac); } else { decodeSingle(context, ac); } decodeBehaviors(context, ac); // AutoComplete event String query = params.get(clientId + "_query"); if (query != null) { AutoCompleteEvent autoCompleteEvent = new AutoCompleteEvent(ac, query); autoCompleteEvent.setPhaseId(PhaseId.APPLY_REQUEST_VALUES); ac.queueEvent(autoCompleteEvent); } }
@Override protected void encodeMarkup(FacesContext context, AutoComplete ac) throws IOException { ResponseWriter writer = context.getResponseWriter(); String clientId = ac.getClientId(context); String style = ac.getStyle(); String styleClass = ac.getStyleClass(); writer.startElement("div", null); writer.writeAttribute("id", clientId, null); if (style != null) { writer.writeAttribute("style", style, null); } if (styleClass != null) { writer.writeAttribute("class", styleClass, null); } encodeInput(context, ac); encodePanel(context, ac); writer.endElement("div"); }
protected void decodeMultiple(FacesContext context, AutoComplete ac) { Map<String, String[]> paramValues = context.getExternalContext().getRequestParameterValuesMap(); Map<String, String> params = context.getExternalContext().getRequestParameterMap(); String clientId = ac.getClientId(context); String[] hinputValues = paramValues.get(clientId + "_hinput"); String[] submittedValues = (hinputValues != null) ? hinputValues : new String[]{}; String inputValue = params.get(clientId + "_input"); if (!isValueBlank(inputValue)) { submittedValues = LangUtils.concat(submittedValues, new String[]{inputValue}); } if (submittedValues.length > 0) { ac.setSubmittedValue(submittedValues); } else { ac.setSubmittedValue(""); } }
@Override public void encodeEnd(FacesContext context, UIComponent component) throws IOException { AutoComplete autoComplete = (AutoComplete) component; Map<String, String> params = context.getExternalContext().getRequestParameterMap(); String query = params.get(autoComplete.getClientId(context) + "_query"); if (query != null) { if (autoComplete.isDynamicLoadRequest(context)) { encodePanel(context, autoComplete); } else { encodeResults(context, component, query); } } else { encodeMarkup(context, autoComplete); encodeScript(context, autoComplete); } }
public void encodeMoreText(FacesContext context, AutoComplete ac) throws IOException { int colSize = ac.getColums().size(); String moreText = ac.getMoreText(); ResponseWriter writer = context.getResponseWriter(); if (colSize > 0) { writer.startElement("tr", null); writer.writeAttribute("class", AutoComplete.MORE_TEXT_TABLE_CLASS, null); writer.startElement("td", null); writer.writeAttribute("colspan", colSize, null); writer.writeText(moreText, "moreText"); writer.endElement("td"); writer.endElement("tr"); } else { writer.startElement("li", null); writer.writeAttribute("class", AutoComplete.MORE_TEXT_LIST_CLASS, null); writer.writeText(moreText, "moreText"); writer.endElement("li"); } } }