Package at.reppeitsolutions.formbuilder.components

Examples of at.reppeitsolutions.formbuilder.components.FormFillerInternal


    public static final String FAMILY = "at.rits.formfillerinternal";

    @Override
    public void encodeBegin(FacesContext ctx,
            UIComponent component) throws IOException {
        FormFillerInternal formFiller = (FormFillerInternal) component;
        ResponseWriter writer = ctx.getResponseWriter();
        HtmlForm form = FormBuilderInternalRenderer.getHtmlForm(formFiller);
        form.setTransient(true);
        formFiller.getFormContent().setTransient(true);
        formFiller.getFormContent().setId(form.getId() + "formContent" + UUID.randomUUID().toString());

        FormData formModel = formFiller.getFormData();

        if (formModel != null) {
            List<FormBuilderContainer> components = new ArrayList<>();

            boolean mandatoryError = false;
            FormBuilderItemConstraint activeConstraint = null;

            if (formModel.getData() != null) {
                for (FormBuilderItemData item : formModel.getData()) {
                    ConstraintVariablesContainer constraintVariablesContainer = new ConstraintVariablesContainer();
                    activeConstraint = checkConstraints(item, activeConstraint, constraintVariablesContainer, formFiller.getWorkflowState(), formFiller.getConstraintClient());
                    if (!item.getFormBuilderItem().getSkipRendering()
                            && item.getFormBuilderItem().getProperties().getVisible()) {
                        components.add(new FormBuilderContainer(item.getFormBuilderItem(), FormBuilderItemFactory.getUIComponent(item, formFiller.getMode(), formFiller)));
                        if (item.getFormBuilderItem().getProperties().getMandatoryError()) {
                            mandatoryError = true;
                            item.getFormBuilderItem().getProperties().setMandatoryError(false);
                        }
                    }
                }
            }

            if (mandatoryError) {
                writer.write("<script type=\"text/javascript\">$(function(){$(\"#mandatoryError\").show();});</script>");
            } else {
                writer.write("<script type=\"text/javascript\">$(function(){$(\"#mandatoryError\").hide();});</script>");
            }

            for (FormBuilderContainer comp : components) {
                HtmlDiv icons = new HtmlDiv();
                icons.setClassString("icons");

                addInfoIcon(comp, icons, writer);

                HtmlListItem li = new HtmlListItem();
                li.getChildren().add(icons);
                li.setClassString("ui-state-default box-runde-ecken");
                li.setStyle("width:" + comp.getHtmlfbitem().getWidth() + ";");
                li.getChildren().add(comp.getHtmlfbitem());
                li.setTransient(true);
                li.setStyle("position: relative;width:" + comp.getHtmlfbitem().getWidth() + ";");
                formFiller.getFormContent().getChildren().add(li);
            }
        } else {
            HtmlOutputText output = new HtmlOutputText();
            output.setValue("ERROR: Model of form builder is null.");
            formFiller.getChildren().add(output);
        }
    }
View Full Code Here


    @Override
    public void encodeEnd(FacesContext ctx,
            UIComponent component) throws IOException {
        ResponseWriter writer = ctx.getResponseWriter();
        FormFillerInternal formFiller = (FormFillerInternal) component;
        HtmlForm form = FormBuilderInternalRenderer.getHtmlForm(formFiller);
        writer.write("<script type=\"text/javascript\">"
                + "$(function(){"
                + "initFormFiller(\"" + form.getClientId() + "\","
                + "\"" + FormBuilderInternalRenderer.getFormActionStringId(component) + "\","
                + "\"" + FormBuilderInternalRenderer.getFormContentStringId(component) + "\""
                + ");"
                + "});"
                + "</script>");

        if (formFiller.getInvokeCallback()) {
            writer.write("<script type=\"text/javascript\">"
                    + "$(function(){"
                    + "parent.submitParentForm();"
                    + "});"
                    + "</script>");
View Full Code Here

        return key.substring(key.indexOf(HtmlFormBuilderItem.DATA_UUID_PREFIX) + HtmlFormBuilderItem.DATA_UUID_PREFIX.length(), key.length());
    }

    @Override
    public void decode(FacesContext ctx, UIComponent component) {
        FormFillerInternal formFiller = (FormFillerInternal) component;
        boolean fillError = false;
        HttpServletRequest request = (HttpServletRequest) ctx.getExternalContext().getRequest();

        String formContentString = ctx.getExternalContext().getRequestParameterMap().get(FormBuilderInternalRenderer.getFormContentStringId(component));
        String formActionString = ctx.getExternalContext().getRequestParameterMap().get(FormBuilderInternalRenderer.getFormActionStringId(component));

        boolean formSubmit = true;

        if (formActionString != null) {
            switch (formActionString) {
                case "download":
                    if (formFiller.getFormData().getData() != null) {
                        for (FormBuilderItemData data : formFiller.getFormData().getData()) {
                            if (data.getUuid().equals(formContentString)) {
                                HttpServletResponse response = (HttpServletResponse) ctx.getExternalContext().getResponse();
                                prepareResponseFor(response, data.getFile());
                                try {
                                    streamFileTo(response, data.getFile());
                                } catch (IOException ex) {
                                    Logger.getLogger(FormFillerInternalRenderer.class.getName()).log(Level.SEVERE, null, ex);
                                }
                            }
                        }
                    }
                    formSubmit = false;
                    break;
            }
        }

        if (formFiller.getFormData().getData() != null && formSubmit) {
            MultipartRequest multiRequest = new MultipartRequest(request);
            for (String key : multiRequest.getFiles().keySet()) {
                if (key.contains(HtmlFormBuilderItem.DATA_UUID_PREFIX)) {
                    String dataUuid = extractDataUuid(key);
                    for (FormBuilderItemData data : formFiller.getFormData().getData()) {
                        if (data.getUuid().equals(dataUuid)) {
                            data.setFile(multiRequest.getFiles().get(key));
                        }
                    }
                }
            }
            for (String key : multiRequest.getParameterMaps().keySet()) {
                if (key.contains(HtmlFormBuilderItem.DATA_UUID_PREFIX)) {
                    String dataUuid = extractDataUuid(key);
                    for (FormBuilderItemData data : formFiller.getFormData().getData()) {
                        if (data.getUuid().equals(dataUuid)) {
                            List<String> result = multiRequest.getParameterMaps().get(key);
                            if (data.getFormBuilderItem() instanceof FormBuilderItemNumber) {
                                if (result.size() == 1) {
                                    try {
                                        if (!"".equals(result.get(0).trim())) {
                                            data.setNumberValue(Float.parseFloat(result.get(0).replaceAll(",", ".")));
                                        }
                                    } catch (NumberFormatException ex) {
                                        throw new NumberFormatException("Internal error with number component. Number not parseable.");
                                    }
                                }
                                if (data.getFormBuilderItem().getProperties().getMandatory()
                                        && data.getNumberValue() == null) {
                                    fillError = true;
                                    data.getFormBuilderItem().getProperties().setMandatoryError(true);
                                }
                            } else {
                                if (result.size() == 1) {
                                    data.setValue(result.get(0));
                                } else {
                                    String tmp = "";
                                    for (String str : result) {
                                        tmp += str;
                                        tmp += ";";
                                    }
                                    data.setValue(tmp.substring(0, tmp.length() - 1));
                                }
                                if (data.getFormBuilderItem().getProperties().getMandatory()
                                        && (data.getValue() == null
                                        || "".equals(data.getValue().trim()))) {
                                    fillError = true;
                                    data.getFormBuilderItem().getProperties().setMandatoryError(true);
                                }
                            }
                        }
                    }
                }
            }
            //Check every field if it is filled
        }

        if (!fillError) {
            formFiller.setInvokeCallback(true);
        }
    }
View Full Code Here

TOP

Related Classes of at.reppeitsolutions.formbuilder.components.FormFillerInternal

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.