Search in sources :

Example 31 with ModelFormField

use of org.apache.ofbiz.widget.model.ModelFormField in project ofbiz-framework by apache.

the class MacroFormRenderer method renderDateTimeField.

public void renderDateTimeField(Appendable writer, Map<String, Object> context, DateTimeField dateTimeField) throws IOException {
    ModelFormField modelFormField = dateTimeField.getModelFormField();
    String paramName = modelFormField.getParameterName(context);
    String defaultDateTimeString = dateTimeField.getDefaultDateTimeString(context);
    String className = "";
    String alert = "false";
    String name = "";
    String formattedMask = "";
    String event = modelFormField.getEvent();
    String action = modelFormField.getAction(context);
    if (UtilValidate.isNotEmpty(modelFormField.getWidgetStyle())) {
        className = modelFormField.getWidgetStyle();
        if (modelFormField.shouldBeRed(context)) {
            alert = "true";
        }
    }
    boolean useTimeDropDown = "time-dropdown".equals(dateTimeField.getInputMethod());
    String stepString = dateTimeField.getStep();
    int step = 1;
    StringBuilder timeValues = new StringBuilder();
    if (useTimeDropDown && UtilValidate.isNotEmpty(step)) {
        try {
            step = Integer.parseInt(stepString);
        } catch (IllegalArgumentException e) {
            Debug.logWarning("Invalid value for step property for field[" + paramName + "] with input-method=\"time-dropdown\" " + " Found Value [" + stepString + "]  " + e.getMessage(), module);
        }
        timeValues.append("[");
        for (int i = 0; i <= 59; ) {
            if (i != 0) {
                timeValues.append(", ");
            }
            timeValues.append(i);
            i += step;
        }
        timeValues.append("]");
    }
    Map<String, String> uiLabelMap = UtilGenerics.checkMap(context.get("uiLabelMap"));
    if (uiLabelMap == null) {
        Debug.logWarning("Could not find uiLabelMap in context", module);
    }
    String localizedInputTitle = "", localizedIconTitle = "";
    // whether the date field is short form, yyyy-mm-dd
    boolean shortDateInput = ("date".equals(dateTimeField.getType()) || useTimeDropDown ? true : false);
    if (useTimeDropDown) {
        name = UtilHttp.makeCompositeParam(paramName, "date");
    } else {
        name = paramName;
    }
    // the default values for a timestamp
    int size = 25;
    int maxlength = 30;
    if (shortDateInput) {
        size = maxlength = 10;
        if (uiLabelMap != null) {
            localizedInputTitle = uiLabelMap.get("CommonFormatDate");
        }
    } else if ("time".equals(dateTimeField.getType())) {
        size = maxlength = 8;
        if (uiLabelMap != null) {
            localizedInputTitle = uiLabelMap.get("CommonFormatTime");
        }
    } else {
        if (uiLabelMap != null) {
            localizedInputTitle = uiLabelMap.get("CommonFormatDateTime");
        }
    }
    /*
         * FIXME: Using a builder here is a hack. Replace the builder with appropriate code.
         */
    ModelFormFieldBuilder builder = new ModelFormFieldBuilder(modelFormField);
    boolean memEncodeOutput = modelFormField.getEncodeOutput();
    if (useTimeDropDown) {
        // If time-dropdown deactivate encodingOutput for found hour and minutes
        // FIXME: Encoding should be controlled by the renderer, not by the model.
        builder.setEncodeOutput(false);
    }
    // FIXME: modelFormField.getEntry ignores shortDateInput when converting Date objects to Strings.
    if (useTimeDropDown) {
        builder.setEncodeOutput(memEncodeOutput);
    }
    modelFormField = builder.build();
    String contextValue = modelFormField.getEntry(context, dateTimeField.getDefaultValue(context));
    String value = contextValue;
    if (UtilValidate.isNotEmpty(value)) {
        if (value.length() > maxlength) {
            value = value.substring(0, maxlength);
        }
    }
    String id = modelFormField.getCurrentContainerId(context);
    ModelForm modelForm = modelFormField.getModelForm();
    String formName = FormRenderer.getCurrentFormName(modelForm, context);
    String timeDropdown = dateTimeField.getInputMethod();
    String timeDropdownParamName = "";
    String classString = "";
    boolean isTwelveHour = false;
    String timeHourName = "";
    int hour2 = 0, hour1 = 0, minutes = 0;
    String timeMinutesName = "";
    String amSelected = "", pmSelected = "", ampmName = "";
    String compositeType = "";
    // search for a localized label for the icon
    if (uiLabelMap != null) {
        localizedIconTitle = uiLabelMap.get("CommonViewCalendar");
    }
    if (!"time".equals(dateTimeField.getType())) {
        String tempParamName;
        if (useTimeDropDown) {
            tempParamName = UtilHttp.makeCompositeParam(paramName, "date");
        } else {
            tempParamName = paramName;
        }
        timeDropdownParamName = tempParamName;
        defaultDateTimeString = UtilHttp.encodeBlanks(modelFormField.getEntry(context, defaultDateTimeString));
    }
    // dropdowns
    if (useTimeDropDown) {
        className = modelFormField.getWidgetStyle();
        classString = (className != null ? className : "");
        isTwelveHour = "12".equals(dateTimeField.getClock());
        // set the Calendar to the default time of the form or now()
        Calendar cal = null;
        try {
            Timestamp defaultTimestamp = Timestamp.valueOf(contextValue);
            cal = Calendar.getInstance();
            cal.setTime(defaultTimestamp);
        } catch (IllegalArgumentException e) {
            Debug.logWarning("Form widget field [" + paramName + "] with input-method=\"time-dropdown\" was not able to understand the default time [" + defaultDateTimeString + "]. The parsing error was: " + e.getMessage(), module);
        }
        timeHourName = UtilHttp.makeCompositeParam(paramName, "hour");
        if (cal != null) {
            int hour = cal.get(Calendar.HOUR_OF_DAY);
            hour2 = hour;
            if (hour == 0) {
                hour = 12;
            }
            if (hour > 12) {
                hour -= 12;
            }
            hour1 = hour;
            minutes = cal.get(Calendar.MINUTE);
        }
        timeMinutesName = UtilHttp.makeCompositeParam(paramName, "minutes");
        compositeType = UtilHttp.makeCompositeParam(paramName, "compositeType");
        // if 12 hour clock, write the AM/PM selector
        if (isTwelveHour) {
            amSelected = ((cal != null && cal.get(Calendar.AM_PM) == Calendar.AM) ? "selected" : "");
            pmSelected = ((cal != null && cal.get(Calendar.AM_PM) == Calendar.PM) ? "selected" : "");
            ampmName = UtilHttp.makeCompositeParam(paramName, "ampm");
        }
    }
    // check for required field style on single forms
    if ("single".equals(modelFormField.getModelForm().getType()) && modelFormField.getRequiredField()) {
        String requiredStyle = modelFormField.getRequiredFieldStyle();
        if (UtilValidate.isEmpty(requiredStyle)) {
            requiredStyle = "required";
        }
        if (UtilValidate.isEmpty(className)) {
            className = requiredStyle;
        } else {
            className = requiredStyle + " " + className;
        }
    }
    String mask = dateTimeField.getMask();
    if ("Y".equals(mask)) {
        if ("date".equals(dateTimeField.getType())) {
            formattedMask = "9999-99-99";
        } else if ("time".equals(dateTimeField.getType())) {
            formattedMask = "99:99:99";
        } else if ("timestamp".equals(dateTimeField.getType())) {
            formattedMask = "9999-99-99 99:99:99";
        }
    }
    String tabindex = modelFormField.getTabindex();
    StringWriter sr = new StringWriter();
    sr.append("<@renderDateTimeField ");
    sr.append("name=\"");
    sr.append(name);
    sr.append("\" className=\"");
    sr.append(className);
    sr.append("\" alert=\"");
    sr.append(alert);
    sr.append("\" value=\"");
    sr.append(value);
    sr.append("\" title=\"");
    sr.append(localizedInputTitle);
    sr.append("\" size=\"");
    sr.append(Integer.toString(size));
    sr.append("\" maxlength=\"");
    sr.append(Integer.toString(maxlength));
    sr.append("\" step=\"");
    sr.append(Integer.toString(step));
    sr.append("\" timeValues=\"");
    sr.append(timeValues.toString());
    sr.append("\" id=\"");
    sr.append(id);
    sr.append("\" event=\"");
    sr.append(event);
    sr.append("\" action=\"");
    sr.append(action);
    sr.append("\" dateType=\"");
    sr.append(dateTimeField.getType());
    sr.append("\" shortDateInput=");
    sr.append(Boolean.toString(shortDateInput));
    sr.append(" timeDropdownParamName=\"");
    sr.append(timeDropdownParamName);
    sr.append("\" defaultDateTimeString=\"");
    sr.append(defaultDateTimeString);
    sr.append("\" localizedIconTitle=\"");
    sr.append(localizedIconTitle);
    sr.append("\" timeDropdown=\"");
    sr.append(timeDropdown);
    sr.append("\" timeHourName=\"");
    sr.append(timeHourName);
    sr.append("\" classString=\"");
    sr.append(classString);
    sr.append("\" hour1=");
    sr.append(Integer.toString(hour1));
    sr.append(" hour2=");
    sr.append(Integer.toString(hour2));
    sr.append(" timeMinutesName=\"");
    sr.append(timeMinutesName);
    sr.append("\" minutes=");
    sr.append(Integer.toString(minutes));
    sr.append(" isTwelveHour=");
    sr.append(Boolean.toString(isTwelveHour));
    sr.append(" ampmName=\"");
    sr.append(ampmName);
    sr.append("\" amSelected=\"");
    sr.append(amSelected);
    sr.append("\" pmSelected=\"");
    sr.append(pmSelected);
    sr.append("\" compositeType=\"");
    sr.append(compositeType);
    sr.append("\" formName=\"");
    sr.append(formName);
    sr.append("\" mask=\"");
    sr.append(formattedMask);
    sr.append("\" tabindex=\"");
    sr.append(tabindex);
    sr.append("\" />");
    executeMacro(writer, sr.toString());
    this.addAsterisks(writer, context, modelFormField);
    this.appendTooltip(writer, context, modelFormField);
}
Also used : StringWriter(java.io.StringWriter) ModelFormField(org.apache.ofbiz.widget.model.ModelFormField) Calendar(com.ibm.icu.util.Calendar) ModelFormFieldBuilder(org.apache.ofbiz.widget.model.ModelFormFieldBuilder) Timestamp(java.sql.Timestamp) ModelForm(org.apache.ofbiz.widget.model.ModelForm)

Example 32 with ModelFormField

use of org.apache.ofbiz.widget.model.ModelFormField in project ofbiz-framework by apache.

the class FormRenderer method renderSingleFormString.

private void renderSingleFormString(Appendable writer, Map<String, Object> context, int positions) throws IOException {
    List<ModelFormField> tempFieldList = new LinkedList<>();
    tempFieldList.addAll(modelForm.getFieldList());
    // Check to see if there is a field, same name and same use-when (could come from extended form)
    for (int j = 0; j < tempFieldList.size(); j++) {
        ModelFormField modelFormField = tempFieldList.get(j);
        if (modelForm.getUseWhenFields().contains(modelFormField.getName())) {
            boolean shouldUse1 = modelFormField.shouldUse(context);
            for (int i = j + 1; i < tempFieldList.size(); i++) {
                ModelFormField curField = tempFieldList.get(i);
                if (curField.getName() != null && curField.getName().equals(modelFormField.getName())) {
                    boolean shouldUse2 = curField.shouldUse(context);
                    if (shouldUse1 == shouldUse2) {
                        tempFieldList.remove(i--);
                    }
                } else {
                    continue;
                }
            }
        }
    }
    Set<String> alreadyRendered = new TreeSet<>();
    FieldGroup lastFieldGroup = null;
    // render form open
    if (!modelForm.getSkipStart()) {
        formStringRenderer.renderFormOpen(writer, context, modelForm);
    }
    // render all hidden & ignored fields
    List<ModelFormField> hiddenIgnoredFieldList = this.getHiddenIgnoredFields(context, alreadyRendered, tempFieldList, -1);
    this.renderHiddenIgnoredFields(writer, context, formStringRenderer, hiddenIgnoredFieldList);
    // render formatting wrapper open
    // This should be covered by fieldGroup.renderStartString
    // formStringRenderer.renderFormatSingleWrapperOpen(writer, context, this);
    // render each field row, except hidden & ignored rows
    Iterator<ModelFormField> fieldIter = tempFieldList.iterator();
    ModelFormField lastFormField = null;
    ModelFormField currentFormField = null;
    ModelFormField nextFormField = null;
    if (fieldIter.hasNext()) {
        currentFormField = fieldIter.next();
    }
    if (fieldIter.hasNext()) {
        nextFormField = fieldIter.next();
    }
    FieldGroup currentFieldGroup = null;
    String currentFieldGroupName = null;
    String lastFieldGroupName = null;
    if (currentFormField != null) {
        currentFieldGroup = (FieldGroup) modelForm.getFieldGroupMap().get(currentFormField.getFieldName());
        if (currentFieldGroup == null) {
            currentFieldGroup = modelForm.getDefaultFieldGroup();
        }
        if (currentFieldGroup != null) {
            currentFieldGroupName = currentFieldGroup.getId();
        }
    }
    boolean isFirstPass = true;
    boolean haveRenderedOpenFieldRow = false;
    while (currentFormField != null) {
        // don't do it on the first pass though...
        if (isFirstPass) {
            isFirstPass = false;
            List<FieldGroupBase> inbetweenList = getInbetweenList(lastFieldGroup, currentFieldGroup);
            for (FieldGroupBase obj : inbetweenList) {
                if (obj instanceof ModelForm.Banner) {
                    ((ModelForm.Banner) obj).renderString(writer, context, formStringRenderer);
                }
            }
            if (currentFieldGroup != null && (lastFieldGroup == null || !lastFieldGroupName.equals(currentFieldGroupName))) {
                currentFieldGroup.renderStartString(writer, context, formStringRenderer);
                lastFieldGroup = currentFieldGroup;
            }
        } else {
            if (fieldIter.hasNext()) {
                // at least two loops left
                lastFormField = currentFormField;
                currentFormField = nextFormField;
                nextFormField = fieldIter.next();
            } else if (nextFormField != null) {
                // okay, just one loop left
                lastFormField = currentFormField;
                currentFormField = nextFormField;
                nextFormField = null;
            } else {
                // at the end...
                currentFormField = null;
                // nextFormField is already null
                break;
            }
            currentFieldGroup = null;
            if (currentFormField != null) {
                currentFieldGroup = (FieldGroup) modelForm.getFieldGroupMap().get(currentFormField.getName());
            }
            if (currentFieldGroup == null) {
                currentFieldGroup = modelForm.getDefaultFieldGroup();
            }
            currentFieldGroupName = currentFieldGroup.getId();
            if (lastFieldGroup != null) {
                lastFieldGroupName = lastFieldGroup.getId();
                if (!lastFieldGroupName.equals(currentFieldGroupName)) {
                    if (haveRenderedOpenFieldRow) {
                        formStringRenderer.renderFormatFieldRowClose(writer, context, modelForm);
                        haveRenderedOpenFieldRow = false;
                    }
                    lastFieldGroup.renderEndString(writer, context, formStringRenderer);
                    List<FieldGroupBase> inbetweenList = getInbetweenList(lastFieldGroup, currentFieldGroup);
                    for (FieldGroupBase obj : inbetweenList) {
                        if (obj instanceof ModelForm.Banner) {
                            ((ModelForm.Banner) obj).renderString(writer, context, formStringRenderer);
                        }
                    }
                }
            }
            if (lastFieldGroup == null || !lastFieldGroupName.equals(currentFieldGroupName)) {
                currentFieldGroup.renderStartString(writer, context, formStringRenderer);
                lastFieldGroup = currentFieldGroup;
            }
        }
        FieldInfo fieldInfo = currentFormField.getFieldInfo();
        if (fieldInfo.getFieldType() == FieldInfo.HIDDEN || fieldInfo.getFieldType() == FieldInfo.IGNORED) {
            continue;
        }
        if (alreadyRendered.contains(currentFormField.getName())) {
            continue;
        }
        if (!currentFormField.shouldUse(context)) {
            if (UtilValidate.isNotEmpty(lastFormField)) {
                currentFormField = lastFormField;
            }
            continue;
        }
        alreadyRendered.add(currentFormField.getName());
        if (focusFieldName.isEmpty()) {
            if (fieldInfo.getFieldType() != FieldInfo.DISPLAY && fieldInfo.getFieldType() != FieldInfo.HIDDEN && fieldInfo.getFieldType() != FieldInfo.DISPLAY_ENTITY && fieldInfo.getFieldType() != FieldInfo.IGNORED && fieldInfo.getFieldType() != FieldInfo.IMAGE) {
                focusFieldName = currentFormField.getName();
                context.put(modelForm.getName().concat(".focusFieldName"), focusFieldName);
            }
        }
        boolean stayingOnRow = false;
        if (lastFormField != null) {
            if (lastFormField.getPosition() >= currentFormField.getPosition()) {
                // moving to next row
                stayingOnRow = false;
            } else {
                // staying on same row
                stayingOnRow = true;
            }
        }
        int positionSpan = 1;
        Integer nextPositionInRow = null;
        if (nextFormField != null) {
            if (nextFormField.getPosition() > currentFormField.getPosition()) {
                positionSpan = nextFormField.getPosition() - currentFormField.getPosition() - 1;
                nextPositionInRow = Integer.valueOf(nextFormField.getPosition());
            } else {
                positionSpan = positions - currentFormField.getPosition();
            }
        }
        if (stayingOnRow) {
        // no spacer cell, might add later though...
        // formStringRenderer.renderFormatFieldRowSpacerCell(writer, context, currentFormField);
        } else {
            if (haveRenderedOpenFieldRow) {
                // render row formatting close
                formStringRenderer.renderFormatFieldRowClose(writer, context, modelForm);
                haveRenderedOpenFieldRow = false;
            }
            // render row formatting open
            formStringRenderer.renderFormatFieldRowOpen(writer, context, modelForm);
            haveRenderedOpenFieldRow = true;
        }
        // 
        if (!haveRenderedOpenFieldRow) {
            formStringRenderer.renderFormatFieldRowOpen(writer, context, modelForm);
            haveRenderedOpenFieldRow = true;
        }
        // render title formatting open
        formStringRenderer.renderFormatFieldRowTitleCellOpen(writer, context, currentFormField);
        // render title (unless this is a submit or a reset field)
        if (fieldInfo.getFieldType() != FieldInfo.SUBMIT && fieldInfo.getFieldType() != FieldInfo.RESET) {
            formStringRenderer.renderFieldTitle(writer, context, currentFormField);
        } else {
            formStringRenderer.renderFormatEmptySpace(writer, context, modelForm);
        }
        // render title formatting close
        formStringRenderer.renderFormatFieldRowTitleCellClose(writer, context, currentFormField);
        // render separator
        formStringRenderer.renderFormatFieldRowSpacerCell(writer, context, currentFormField);
        // render widget formatting open
        formStringRenderer.renderFormatFieldRowWidgetCellOpen(writer, context, currentFormField, positions, positionSpan, nextPositionInRow);
        // render widget
        currentFormField.renderFieldString(writer, context, formStringRenderer);
        // render widget formatting close
        formStringRenderer.renderFormatFieldRowWidgetCellClose(writer, context, currentFormField, positions, positionSpan, nextPositionInRow);
    }
    // render row formatting close after the end if needed
    if (haveRenderedOpenFieldRow) {
        formStringRenderer.renderFormatFieldRowClose(writer, context, modelForm);
    }
    if (lastFieldGroup != null) {
        lastFieldGroup.renderEndString(writer, context, formStringRenderer);
    }
    // render form close
    if (!modelForm.getSkipEnd()) {
        formStringRenderer.renderFormClose(writer, context, modelForm);
    }
}
Also used : FieldGroup(org.apache.ofbiz.widget.model.ModelForm.FieldGroup) ModelFormField(org.apache.ofbiz.widget.model.ModelFormField) LinkedList(java.util.LinkedList) TreeSet(java.util.TreeSet) FieldInfo(org.apache.ofbiz.widget.model.FieldInfo) FieldGroupBase(org.apache.ofbiz.widget.model.ModelForm.FieldGroupBase)

Example 33 with ModelFormField

use of org.apache.ofbiz.widget.model.ModelFormField in project ofbiz-framework by apache.

the class FormRenderer method renderItemRows.

private void renderItemRows(Appendable writer, Map<String, Object> context, FormStringRenderer formStringRenderer, boolean formPerItem, int numOfColumns) throws IOException {
    String lookupName = modelForm.getListName();
    if (UtilValidate.isEmpty(lookupName)) {
        Debug.logError("No value for list or iterator name found.", module);
        return;
    }
    Object obj = context.get(lookupName);
    if (obj == null) {
        if (Debug.verboseOn()) {
            Debug.logVerbose("No object for list or iterator name [" + lookupName + "] found, so not rendering rows.", module);
        }
        return;
    }
    // if list is empty, do not render rows
    Iterator<?> iter = null;
    if (obj instanceof Iterator<?>) {
        iter = (Iterator<?>) obj;
    } else if (obj instanceof List<?>) {
        iter = ((List<?>) obj).listIterator();
    }
    // set low and high index
    Paginator.getListLimits(modelForm, context, obj);
    int listSize = ((Integer) context.get("listSize")).intValue();
    int lowIndex = ((Integer) context.get("lowIndex")).intValue();
    int highIndex = ((Integer) context.get("highIndex")).intValue();
    // we're passed a subset of the list, so use (0, viewSize) range
    if (modelForm.isOverridenListSize()) {
        lowIndex = 0;
        highIndex = ((Integer) context.get("viewSize")).intValue();
    }
    if (iter != null) {
        // render item rows
        if (UtilValidate.isNotEmpty(context.get("itemIndex"))) {
            if (UtilValidate.isNotEmpty(context.get("parentItemIndex"))) {
                context.put("parentItemIndex", context.get("parentItemIndex") + modelForm.getItemIndexSeparator() + context.get("itemIndex"));
            } else {
                context.put("parentItemIndex", modelForm.getItemIndexSeparator() + context.get("itemIndex"));
            }
        }
        int itemIndex = -1;
        Object item = null;
        context.put("wholeFormContext", context);
        Map<String, Object> previousItem = new HashMap<>();
        while ((item = safeNext(iter)) != null) {
            itemIndex++;
            if (itemIndex >= highIndex) {
                break;
            }
            // TODO: this is a bad design, for EntityListIterators we should skip to the lowIndex and go from there, MUCH more efficient...
            if (itemIndex < lowIndex) {
                continue;
            }
            Map<String, Object> itemMap = UtilGenerics.checkMap(item);
            MapStack<String> localContext = MapStack.create(context);
            if (UtilValidate.isNotEmpty(modelForm.getListEntryName())) {
                localContext.put(modelForm.getListEntryName(), item);
            } else {
                if (itemMap instanceof GenericEntity) {
                    // Rendering code might try to modify the GenericEntity instance,
                    // so we make a copy of it.
                    Map<String, Object> genericEntityClone = UtilGenerics.cast(((GenericEntity) itemMap).clone());
                    localContext.push(genericEntityClone);
                } else {
                    localContext.push(itemMap);
                }
            }
            localContext.push();
            localContext.put("previousItem", previousItem);
            previousItem = new HashMap<>();
            previousItem.putAll(itemMap);
            AbstractModelAction.runSubActions(modelForm.getRowActions(), localContext);
            localContext.put("itemIndex", Integer.valueOf(itemIndex - lowIndex));
            if (UtilValidate.isNotEmpty(context.get("renderFormSeqNumber"))) {
                localContext.put("formUniqueId", "_" + context.get("renderFormSeqNumber"));
            }
            if (Debug.verboseOn()) {
                Debug.logVerbose("In form got another row, context is: " + localContext, module);
            }
            // Check to see if there is a field, same name and same use-when (could come from extended form)
            List<ModelFormField> tempFieldList = new LinkedList<>();
            tempFieldList.addAll(modelForm.getFieldList());
            for (int j = 0; j < tempFieldList.size(); j++) {
                ModelFormField modelFormField = tempFieldList.get(j);
                if (!modelFormField.isUseWhenEmpty()) {
                    boolean shouldUse1 = modelFormField.shouldUse(localContext);
                    for (int i = j + 1; i < tempFieldList.size(); i++) {
                        ModelFormField curField = tempFieldList.get(i);
                        if (curField.getName() != null && curField.getName().equals(modelFormField.getName())) {
                            boolean shouldUse2 = curField.shouldUse(localContext);
                            if (shouldUse1 == shouldUse2) {
                                tempFieldList.remove(i--);
                            }
                        } else {
                            continue;
                        }
                    }
                }
            }
            // Each single item is rendered in one or more rows if its fields have
            // different "position" attributes. All the fields with the same position
            // are rendered in the same row.
            // The default position is 1, and represents the main row:
            // it contains the fields that are in the list header (columns).
            // The positions lower than 1 are rendered in rows before the main one;
            // positions higher than 1 are rendered after the main one.
            // We get a sorted (by position, ascending) set of lists;
            // each list contains all the fields with that position.
            Collection<List<ModelFormField>> fieldListsByPosition = this.getFieldListsByPosition(tempFieldList);
            // List hiddenIgnoredFieldList = getHiddenIgnoredFields(localContext, null, tempFieldList);
            for (List<ModelFormField> fieldListByPosition : fieldListsByPosition) {
                // For each position (the subset of fields with the same position attribute)
                // we have two phases: preprocessing and rendering
                List<ModelFormField> innerDisplayHyperlinkFieldsBegin = new LinkedList<>();
                List<ModelFormField> innerFormFields = new LinkedList<>();
                List<ModelFormField> innerDisplayHyperlinkFieldsEnd = new LinkedList<>();
                // Preprocessing:
                // all the form fields are evaluated and the ones that will
                // appear in the form are put into three separate lists:
                // - hyperlink fields that will appear at the beginning of the row
                // - fields of other types
                // - hyperlink fields that will appear at the end of the row
                Iterator<ModelFormField> innerDisplayHyperlinkFieldIter = fieldListByPosition.iterator();
                int currentPosition = 1;
                while (innerDisplayHyperlinkFieldIter.hasNext()) {
                    ModelFormField modelFormField = innerDisplayHyperlinkFieldIter.next();
                    FieldInfo fieldInfo = modelFormField.getFieldInfo();
                    // don't do any header for hidden or ignored fields
                    if (fieldInfo.getFieldType() == FieldInfo.HIDDEN || fieldInfo.getFieldType() == FieldInfo.IGNORED) {
                        continue;
                    }
                    if (FieldInfo.isInputFieldType(fieldInfo.getFieldType())) {
                        // okay, now do the form cell
                        break;
                    }
                    // if this is a list or multi form don't skip here because we don't want to skip the table cell, will skip the actual field later
                    if (!"list".equals(modelForm.getType()) && !"multi".equals(modelForm.getType()) && !modelFormField.shouldUse(localContext)) {
                        continue;
                    }
                    innerDisplayHyperlinkFieldsBegin.add(modelFormField);
                    currentPosition = modelFormField.getPosition();
                }
                Iterator<ModelFormField> innerFormFieldIter = fieldListByPosition.iterator();
                while (innerFormFieldIter.hasNext()) {
                    ModelFormField modelFormField = innerFormFieldIter.next();
                    FieldInfo fieldInfo = modelFormField.getFieldInfo();
                    // don't do any header for hidden or ignored fields
                    if (fieldInfo.getFieldType() == FieldInfo.HIDDEN || fieldInfo.getFieldType() == FieldInfo.IGNORED) {
                        continue;
                    }
                    // skip all of the display/hyperlink fields
                    if (!FieldInfo.isInputFieldType(fieldInfo.getFieldType())) {
                        continue;
                    }
                    // if this is a list or multi form don't skip here because we don't want to skip the table cell, will skip the actual field later
                    if (!"list".equals(modelForm.getType()) && !"multi".equals(modelForm.getType()) && !modelFormField.shouldUse(localContext)) {
                        continue;
                    }
                    innerFormFields.add(modelFormField);
                    currentPosition = modelFormField.getPosition();
                }
                while (innerDisplayHyperlinkFieldIter.hasNext()) {
                    ModelFormField modelFormField = innerDisplayHyperlinkFieldIter.next();
                    FieldInfo fieldInfo = modelFormField.getFieldInfo();
                    // don't do any header for hidden or ignored fields
                    if (fieldInfo.getFieldType() == FieldInfo.HIDDEN || fieldInfo.getFieldType() == FieldInfo.IGNORED) {
                        continue;
                    }
                    // skip all non-display and non-hyperlink fields
                    if (FieldInfo.isInputFieldType(fieldInfo.getFieldType())) {
                        continue;
                    }
                    // if this is a list or multi form don't skip here because we don't want to skip the table cell, will skip the actual field later
                    if (!"list".equals(modelForm.getType()) && !"multi".equals(modelForm.getType()) && !modelFormField.shouldUse(localContext)) {
                        continue;
                    }
                    innerDisplayHyperlinkFieldsEnd.add(modelFormField);
                    currentPosition = modelFormField.getPosition();
                }
                List<ModelFormField> hiddenIgnoredFieldList = getHiddenIgnoredFields(localContext, null, tempFieldList, currentPosition);
                // of one row (for the current position).
                if (innerDisplayHyperlinkFieldsBegin.size() > 0 || innerFormFields.size() > 0 || innerDisplayHyperlinkFieldsEnd.size() > 0) {
                    this.renderItemRow(writer, localContext, formStringRenderer, formPerItem, hiddenIgnoredFieldList, innerDisplayHyperlinkFieldsBegin, innerFormFields, innerDisplayHyperlinkFieldsEnd, fieldListByPosition, currentPosition, numOfColumns);
                }
            }
        // iteration on positions
        }
        // reduce the highIndex if number of items falls short
        if ((itemIndex + 1) < highIndex) {
            highIndex = itemIndex + 1;
            // if list size is overridden, use full listSize
            context.put("highIndex", Integer.valueOf(modelForm.isOverridenListSize() ? listSize : highIndex));
        }
        context.put("actualPageSize", Integer.valueOf(highIndex - lowIndex));
        if (iter instanceof EntityListIterator) {
            try {
                ((EntityListIterator) iter).close();
            } catch (GenericEntityException e) {
                Debug.logError(e, "Error closing list form render EntityListIterator: " + e.toString(), module);
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) ModelFormField(org.apache.ofbiz.widget.model.ModelFormField) LinkedList(java.util.LinkedList) GenericEntity(org.apache.ofbiz.entity.GenericEntity) GenericEntityException(org.apache.ofbiz.entity.GenericEntityException) Iterator(java.util.Iterator) EntityListIterator(org.apache.ofbiz.entity.util.EntityListIterator) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) EntityListIterator(org.apache.ofbiz.entity.util.EntityListIterator) FieldInfo(org.apache.ofbiz.widget.model.FieldInfo)

Example 34 with ModelFormField

use of org.apache.ofbiz.widget.model.ModelFormField in project ofbiz-framework by apache.

the class FoFormRenderer method renderTextareaField.

public void renderTextareaField(Appendable writer, Map<String, Object> context, TextareaField textareaField) throws IOException {
    ModelFormField modelFormField = textareaField.getModelFormField();
    this.makeBlockString(writer, modelFormField.getWidgetStyle(), modelFormField.getEntry(context, textareaField.getDefaultValue(context)));
    appendWhitespace(writer);
}
Also used : ModelFormField(org.apache.ofbiz.widget.model.ModelFormField)

Example 35 with ModelFormField

use of org.apache.ofbiz.widget.model.ModelFormField in project ofbiz-framework by apache.

the class FoFormRenderer method renderTextFindField.

public void renderTextFindField(Appendable writer, Map<String, Object> context, TextFindField textFindField) throws IOException {
    ModelFormField modelFormField = textFindField.getModelFormField();
    this.makeBlockString(writer, modelFormField.getWidgetStyle(), modelFormField.getEntry(context, textFindField.getDefaultValue(context)));
    appendWhitespace(writer);
}
Also used : ModelFormField(org.apache.ofbiz.widget.model.ModelFormField)

Aggregations

ModelFormField (org.apache.ofbiz.widget.model.ModelFormField)40 StringWriter (java.io.StringWriter)19 FieldInfo (org.apache.ofbiz.widget.model.FieldInfo)6 LinkedList (java.util.LinkedList)5 ModelForm (org.apache.ofbiz.widget.model.ModelForm)5 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Locale (java.util.Locale)3 ModelSingleForm (org.apache.ofbiz.widget.model.ModelSingleForm)3 TreeMap (java.util.TreeMap)2 HttpSession (javax.servlet.http.HttpSession)2 DisplayEntityField (org.apache.ofbiz.widget.model.ModelFormField.DisplayEntityField)2 Calendar (com.ibm.icu.util.Calendar)1 Timestamp (java.sql.Timestamp)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 TreeSet (java.util.TreeSet)1 GeneralException (org.apache.ofbiz.base.util.GeneralException)1