Package org.openfaces.component.input

Examples of org.openfaces.component.input.DropDownFieldBase


    }

    @Override
    protected void writeFieldAttributes(ResponseWriter writer, DropDownComponent fieldComponent) throws IOException {
        super.writeFieldAttributes(writer, fieldComponent);
        DropDownFieldBase dropDownField = (DropDownFieldBase) fieldComponent;
        writeAttribute(writer, "maxlength", dropDownField.getMaxlength(), Integer.MIN_VALUE);
    }
View Full Code Here


    @Override
    public void decode(FacesContext context, UIComponent component) {
        if (AjaxUtil.isAjaxPortionRequest(context, component))
            return;
        Map<String, String> requestMap = context.getExternalContext().getRequestParameterMap();
        DropDownFieldBase dropDownField = (DropDownFieldBase) component;
        String fieldId = getFieldClientId(context, dropDownField);
        String valueFieldId = getValueFieldId(context, dropDownField);

        String text = requestMap.get(fieldId);
        String value = requestMap.get(valueFieldId);
        if (text == null || value == null)
            Rendering.ensureComponentInsideForm(component);

        String submittedValue;
        if (value == null)
            return;
        if (value.length() == 0) {
            submittedValue = dropDownField.getCustomValueAllowed() ? text : null;
        } else {
            if (!value.startsWith("[") || !value.endsWith("]"))
                throw new IllegalStateException("Illegally formatted value received in request: " + value);
            submittedValue = value.substring(1, value.length() - 1);
        }

        if (submittedValue == null) {
            // from UIInput documentation: If the component wishes to indicate that no particular value was submitted,
            // it can either do nothing, or set the submitted value to null. So we're setting the value as empty string
            // because we the empty submitted value shouldn't be skipped
            submittedValue = "";
        }

        String state = requestMap.get(fieldId + PROMPT_VISIBLE_SUFFIX);
        if ("false".equals(state)) {
            if (!dropDownField.isDisabled())
                dropDownField.setSubmittedValue(submittedValue);
        }
    }
View Full Code Here

    @Override
    public void encodeChildren(FacesContext context, UIComponent uiComponent) throws IOException {
        if (AjaxUtil.getSkipExtraRenderingOnPortletsAjax(context))
            return;

        DropDownFieldBase dropDownField = (DropDownFieldBase) uiComponent;

        SuggestionMode suggestionMode = dropDownField.getSuggestionMode();
        int preloadedItemCount = dropDownField.getPreloadedItemCount();
        if (preloadedItemCount < -1)
            throw new FacesException("preloadedItemCount attribute should be specified as -1, 0, or a positive " +
                    "number, but was specified as: " + preloadedItemCount +
                    ". Component id: " + dropDownField.getClientId(context));
        int pageSize = dropDownField.getPageSize();
        if (pageSize == 0 || pageSize < -1)
            throw new FacesException("pageSize should be specified as -1 or a positive number, but the current value " +
                    "is: " + preloadedItemCount + ". Component id: " + dropDownField.getClientId(context));
        int totalItemCount = -1;
        if (
                SuggestionMode.ALL.equals(suggestionMode) ||
                        SuggestionMode.STRING_START.equals(suggestionMode) ||
                        SuggestionMode.SUBSTRING.equals(suggestionMode) ||
                        SuggestionMode.STRING_END.equals(suggestionMode)) {
            preloadedItemCount = -1;
        } else if (SuggestionMode.NONE.equals(suggestionMode)) {
            preloadedItemCount = (isManualListOpeningAllowed(dropDownField) || dropDownField.getAutoComplete()) ? -1 : 0;
        } else if (SuggestionMode.CUSTOM.equals(suggestionMode)) {
            if (!isManualListOpeningAllowed(dropDownField))
                preloadedItemCount = 0;
            else {
                ValueExpression ve = dropDownField.getValueExpression("totalItemCount");
                if (ve == null && preloadedItemCount != -1 && pageSize != -1)
                    throw new FacesException("totalItemCount attribute should be specified for the DropDownField " +
                            "component with pageSize attributes. Component id: " + dropDownField.getClientId(context));
                totalItemCount = ve != null ? (Integer) ve.getValue(context.getELContext()) : -1;
            }
        } else {
            throw new IllegalStateException("Unknown SuggestionMode enumeration value: " + suggestionMode);
        }
        if (preloadedItemCount == -1 && totalItemCount != -1)
            preloadedItemCount = totalItemCount;
        Collection<UISelectItem> items = preloadedItemCount != 0 ? collectSelectItems(dropDownField, 0, preloadedItemCount) : null;
        List<String[]> itemValues = prepareItemValues(context, dropDownField, items);
        if (itemValues != null) {
            dropDownField.getAttributes().put(ITEM_VALUES_ATTR_NAME, itemValues);
        } else {
            dropDownField.getAttributes().remove(ITEM_VALUES_ATTR_NAME);
        }

        DropDownPopup popup = dropDownField.getPopup();
        popup.setDropDownList(items);
        popup.encodeAll(context);
        Rendering.encodeClientActions(context, uiComponent);

        dropDownField.getAttributes().put(ATTR_TOTAL_ITEM_COUNT, totalItemCount);
        dropDownField.getAttributes().put(ATTR_PAGE_SIZE, pageSize);
    }
View Full Code Here

    protected int getItemPresentationColumn(DropDownComponent dropDown) {
        return -1;
    }
   
    protected InitScript renderInitScript(FacesContext context, DropDownComponent dropDown) throws IOException {
        DropDownFieldBase dropDownField = (DropDownFieldBase) dropDown;

        DropDownPopup popup = dropDownField.getPopup();

        ScriptBuilder buf = new ScriptBuilder();
        TableStructure tableStructure = popup.getChildData().getTableStructure();
        buf.initScript(context, dropDownField, "O$.DropDownField._init",
                dropDownField.getTimeout(),
                dropDownField.getListAlignment(),

                Styles.getStyleClassesStr(context, dropDownField, dropDownField.getRolloverListItemStyle(),
                        dropDownField.getRolloverListItemClass(), DefaultStyles.getDefaultSelectionStyle(), StyleGroup.rolloverStyleGroup()),

                getItemValuesArray(getItemValues(dropDown)),
                dropDownField.getCustomValueAllowed(),
                dropDownField.isRequired(),
                dropDownField.getSuggestionMode(),
                dropDownField.getSuggestionDelay(),
                dropDownField.getSuggestionMinChars(),
                isManualListOpeningAllowed(dropDownField),
                dropDownField.getAutoComplete(),
                dropDownField.getAttributes().get(ATTR_TOTAL_ITEM_COUNT),
                dropDownField.getAttributes().get(ATTR_PAGE_SIZE),

                tableStructure.getInitParam(context, POPUP_TABLE_DEFAULT_STYLES),
                dropDownField.isCachingAllowed(),
                getItemPresentationColumn(dropDown),
                dropDownField.getChangeValueOnSelect()
        );
        popup.resetChildData();
        if (!dropDown.isReadonly()) {
            Map<String, Script> eventHandlers = new HashMap<String, Script>();

            String onchange = dropDownField.getOnchange();
            if (onchange != null)
                eventHandlers.put("onchange_adapted", new AnonymousFunction(new RawScript(onchange), "event"));

            String onkeypress = dropDownField.getOnkeypress();
            if (onkeypress != null)
                eventHandlers.put("onkeypress_adapted", new AnonymousFunction(new RawScript(onkeypress), "event"));

            String ondropdown = dropDownField.getOndropdown();
            if (ondropdown != null)
                eventHandlers.put("ondropdown", new AnonymousFunction(new RawScript(ondropdown), "event"));

            String oncloseup = dropDownField.getOncloseup();
            if (oncloseup != null)
                eventHandlers.put("oncloseup", new AnonymousFunction(new RawScript(oncloseup), "event"));

            buf.O$(dropDownField).dot().functionCall("_setCustomEvents", eventHandlers).semicolon();
        }
View Full Code Here

            if (portionNameSuffix.charAt(0) != '[')
                throw new IllegalArgumentException("Improperly formatted portionName suffix: " + portionNameSuffix);
            criterion = portionNameSuffix.substring(1, portionNameSuffix.length() - 1);
        }

        DropDownFieldBase dropDownField = (DropDownFieldBase) component;

        ResponseWriter responseWriter = context.getResponseWriter();
        Writer stringWriter = new StringWriter();
        ResponseWriter clonedResponseWriter = responseWriter.cloneWithWriter(stringWriter);
        context.setResponseWriter(clonedResponseWriter);
        List<String[]> itemValues;
        boolean appendItems;
        try {
            String var = "searchString";
            Map<String, Object> requestMap = context.getExternalContext().getRequestMap();

            int pageStart = 0;
            Collection<UISelectItem> items;
            Object oldVarValue = requestMap.put(var, criterion);
            try {
                if (jsonParam == null) {
                    appendItems = false;
                    items = collectSelectItems(dropDownField);
                } else {
                    try {
                        pageStart = jsonParam.getInt("pageStart");
                        int pageSize = jsonParam.getInt("pageSize");
                        items = collectSelectItems(dropDownField, pageStart, pageSize);
                        appendItems = !jsonParam.getBoolean("forceReload");
                    } catch (JSONException e) {
                        throw new RuntimeException(e);
                    }
                }
                itemValues = prepareItemValues(context, dropDownField, items);
            } finally {
                requestMap.put(var, oldVarValue);
            }

            DropDownPopup popup = dropDownField.getPopup();
            popup.setDropDownList(items);

            DropDownPopup.ChildData childData = popup.getChildData();
            popup.renderRows(context, dropDownField, childData, items, pageStart);
            popup.resetChildData();
View Full Code Here

TOP

Related Classes of org.openfaces.component.input.DropDownFieldBase

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.