Examples of FormState


Examples of org.apache.isis.viewer.scimpi.dispatcher.edit.FormState

        return parameters;
    }

    private FormState validateParameters(final RequestContext context, final ObjectAction action,
        final ObjectAdapter object) {
        final FormState formState = new FormState();
        final List<ObjectActionParameter> parameters2 = action.getParameters();
        final int parameterCount = action.getParameterCount();
        for (int i = 0; i < parameterCount; i++) {
            final String fieldName = parameterName(i);
            String newEntry = context.getParameter(fieldName);

            if (newEntry != null && newEntry.equals("-OTHER-")) {
                newEntry = context.getParameter(fieldName + "-other");
            }

            if (newEntry == null) {
                // TODO figure out a better way to determine if boolean or a password
                final ObjectSpecification spec = parameters2.get(i).getSpecification();
                if (spec.isOfType(IsisContext.getSpecificationLoader().loadSpecification(boolean.class))
                    || spec.isOfType(IsisContext.getSpecificationLoader().loadSpecification(Boolean.class))) {
                    newEntry = FALSE;
                } else {
                    newEntry = "";
                }
            }
            final FieldEditState fieldState = formState.createField(fieldName, newEntry);
            Consent consent = null;

            if (!parameters2.get(i).isOptional() && newEntry.equals("")) {
                consent = new Veto(parameters2.get(i).getName() + " required");
                formState.setError("Not all fields have been set");

            } else if (parameters2.get(i).getSpecification().getFacet(ParseableFacet.class) != null) {
                try {
                    final ParseableFacet facet = parameters2.get(i).getSpecification().getFacet(ParseableFacet.class);
                    final String message = parameters2.get(i).isValid(object, newEntry);
                    if (message != null) {
                        consent = new Veto(message);
                        formState.setError("Not all fields are valid");
                    }
                    final ObjectAdapter entry = facet.parseTextEntry(null, newEntry);
                    fieldState.setValue(entry);
                } catch (final TextEntryParseException e) {
                    consent = new Veto(e.getMessage());
                    formState.setError("Not all fields are valid");
                }
            } else {
                fieldState.setValue(newEntry == null ? null : context.getMappedObject(newEntry));
            }
            if (consent != null && consent.isVetoed()) {
                fieldState.setError(consent.getReason());
            }
        }

        if (formState.isValid()) {
            final ObjectAdapter[] parameters = getParameters(action, formState);
            final Consent consent = action.isProposedArgumentSetValid(object, parameters);
            if (consent != null && consent.isVetoed()) {
                formState.setError(consent.getReason());
            }
        }

        return formState;
    }
View Full Code Here

Examples of org.apache.isis.viewer.scimpi.dispatcher.edit.FormState

        hiddenFields.add(new HiddenInputField(ERRORS, error));
        if (view != null) {
            hiddenFields.add(new HiddenInputField(VIEW, view));
        }

        final FormState entryState = (FormState) request.getContext().getVariable(ENTRY_FIELDS);
        final InputField nameField = createdField("username", "User Name", InputField.TEXT, entryState);
        final String width = request.getOptionalProperty("width");
        if (width != null) {
            final int w = Integer.valueOf(width).intValue();
            nameField.setWidth(w);
        }
        final InputField passwordField = createdField("password", "Password", InputField.PASSWORD, entryState);
        final InputField[] fields = new InputField[] { nameField, passwordField, };

        final String formTitle = request.getOptionalProperty(FORM_TITLE);
        final String loginButtonTitle = request.getOptionalProperty(BUTTON_TITLE, "Log in");
        final String className = request.getOptionalProperty(CLASS, "action login full");
        final String id = request.getOptionalProperty(ID);

        HtmlFormBuilder.createForm(request, "logon.app",
            hiddenFields.toArray(new HiddenInputField[hiddenFields.size()]), fields, className, id, formTitle, null,
            null, loginButtonTitle, entryState == null ? null : entryState.getError());
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.