Package org.apache.isis.viewer.scimpi.dispatcher.context

Examples of org.apache.isis.viewer.scimpi.dispatcher.context.RequestContext


        if (linkAllFields) {
            for (int i = 0; i < linkFields.length; i++) {
                linkFields[i] = fields.get(i).isOneToOneAssociation();
            }
        }
        final RequestContext context = request.getContext();
        final TableContentWriter rowBuilder = rowBuilder(request, context, null, context.mapObject(object, Scope.REQUEST), field.getId(), fields, showIconByDefault);
        write(request, collection, summary, rowBuilder, tableClass, rowClasses);
    }
View Full Code Here


    public static void write(final Request request, final ObjectAdapter object, final ObjectAction action,
        final String[] parameters, final String objectId, final String version, String forwardResultTo,
        String forwardVoidTo, String forwardErrorTo, final String variable, final String scope, String buttonTitle,
        final String completionMessage, final String resultOverride, final String idName, final String className) {
        final RequestContext context = request.getContext();

        buttonTitle = buttonTitle != null ? buttonTitle : action.getName();

        if (action.isVisible(IsisContext.getAuthenticationSession(), object).isVetoed()) {
            LOG.info("action not visible " + action.getName());
            return;
        }
        final Consent usable = action.isUsable(IsisContext.getAuthenticationSession(), object);
        if (usable.isVetoed()) {
            LOG.info("action not available: " + usable.getReason());
            return;
        }

        /*
         *
         * TODO this mechanism fails as it tries to process tags - which we dont need! Also it calls action 'edit' (not
         * 'action'). Field[] fields = new Field[0]; HiddenField[] hiddenFields = new HiddenField[] { new
         * HiddenField("service", serviceId), new HiddenField("method", methodName), new HiddenField("view",
         * forwardToView), variable == null ? null : new HiddenField("variable", variable), }; Form.createForm(request,
         * buttonTitle, fields, hiddenFields, false);
         */

        final String idSegment = idName == null ? "" : ("id=\"" + idName + "\" ");
        final String classSegment = "class=\"" + (className == null ? "action in-line" : className) + "\"";
        request.appendHtml("\n<form " + idSegment + classSegment + " action=\"action.app\" method=\"post\">\n");
        if (objectId == null) {
            request.appendHtml("  <input type=\"hidden\" name=\"" + "_" + OBJECT + "\" value=\""
                + context.getVariable(RequestContext.RESULT) + "\" />\n");
        } else {
            request
                .appendHtml("  <input type=\"hidden\" name=\"" + "_" + OBJECT + "\" value=\"" + objectId + "\" />\n");
        }
        request.appendHtml("  <input type=\"hidden\" name=\"" + "_" + VERSION + "\" value=\"" + version + "\" />\n");
        if (scope != null) {
            request.appendHtml("  <input type=\"hidden\" name=\"" + "_" + SCOPE + "\" value=\"" + scope + "\" />\n");
        }
        request.appendHtml("  <input type=\"hidden\" name=\"" + "_" + METHOD + "\" value=\"" + action.getId()
            + "\" />\n");
        if (forwardResultTo != null) {
            forwardResultTo = context.fullFilePath(forwardResultTo);
            request.appendHtml("  <input type=\"hidden\" name=\"" + "_" + VIEW + "\" value=\"" + forwardResultTo
                + "\" />\n");
        }
        if (forwardErrorTo == null) {
            forwardErrorTo = request.getContext().getResourceFile();
        }
        forwardErrorTo = context.fullFilePath(forwardErrorTo);
        request.appendHtml("  <input type=\"hidden\" name=\"" + "_" + ERRORS + "\" value=\"" + forwardErrorTo
            + "\" />\n");
        if (forwardVoidTo == null) {
            forwardVoidTo = request.getContext().getResourceFile();
        }
        forwardVoidTo = context.fullFilePath(forwardVoidTo);
        request.appendHtml("  <input type=\"hidden\" name=\"" + "_" + VOID + "\" value=\"" + forwardVoidTo + "\" />\n");
        if (variable != null) {
            request.appendHtml("  <input type=\"hidden\" name=\"" + "_" + RESULT_NAME + "\" value=\"" + variable
                + "\" />\n");
        }
View Full Code Here

        createForm(request, parameterObject, false);
    }

    protected static void createForm(final Request request, final CreateFormParameter parameterObject,
        final boolean withoutProcessing) {
        final RequestContext context = request.getContext();
        final ObjectAdapter object = MethodsUtils.findObject(context, parameterObject.objectId);
        final String version = request.getContext().mapVersion(object);
        final ObjectAction action = MethodsUtils.findAction(object, parameterObject.methodName);
        // TODO how do we distinguish between overloaded methods?

        // REVIEW Is this useful?
        if (action.getParameterCount() == 0) {
            throw new ScimpiException("Action form can only be used for actions with parameters");
        }
        if (parameterObject.showMessage && MethodsUtils.isVisible(object, action)) {
            final String notUsable = MethodsUtils.isUsable(object, action);
            if (notUsable != null) {
                if (!withoutProcessing) {
                    request.skipUntilClose();
                }
                request.appendHtml("<div class=\"" + parameterObject.className + "-message\" >");
                request.appendAsHtmlEncoded(notUsable);
                request.appendHtml("</div>");
                return;
            }
        }
        if (!MethodsUtils.isVisibleAndUsable(object, action)) {
            if (!withoutProcessing) {
                request.skipUntilClose();
            }
            return;
        }
        final String objectId = context.mapObject(object, Scope.INTERACTION);
        final String errorView =
            context.fullFilePath(parameterObject.forwardErrorTo == null ? context.getResourceFile()
                : parameterObject.forwardErrorTo);
        final String voidView =
            context.fullFilePath(parameterObject.forwardVoidTo == null ? context.getResourceFile()
                : parameterObject.forwardVoidTo);
        final HiddenInputField[] hiddenFields =
            new HiddenInputField[] {
                new HiddenInputField("_" + OBJECT, objectId),
                new HiddenInputField("_" + VERSION, version),
                new HiddenInputField("_" + FORM_ID, parameterObject.formId),
                new HiddenInputField("_" + METHOD, parameterObject.methodName),
                parameterObject.forwardResultTo == null ? null : new HiddenInputField("_" + VIEW,
                    context.fullFilePath(parameterObject.forwardResultTo)),
                new HiddenInputField("_" + VOID, voidView),
                new HiddenInputField("_" + ERRORS, errorView),
                parameterObject.completionMessage == null ? null : new HiddenInputField("_" + MESSAGE,
                    parameterObject.completionMessage),
                parameterObject.scope == null ? null : new HiddenInputField("_" + SCOPE, parameterObject.scope),
                parameterObject.resultOverride == null ? null : new HiddenInputField("_" + RESULT_OVERRIDE,
                    parameterObject.resultOverride),
                parameterObject.resultName == null ? null : new HiddenInputField("_" + RESULT_NAME,
                    parameterObject.resultName),
                parameterObject.resultName == null ? null : new HiddenInputField(RequestContext.RESULT,
                    (String) request.getContext().getVariable(RequestContext.RESULT)) };

        // TODO when the block contains a selector tag it doesn't disable it if the field cannot be edited!!!
        final FormFieldBlock containedBlock = new FormFieldBlock() {
            @Override
            public boolean isNullable(final String name) {
                final int index = Integer.parseInt(name.substring(5)) - 1;
                final ObjectActionParameter param = action.getParameters().get(index);
                return param.isOptional();
            }
        };
        request.setBlockContent(containedBlock);
        if (!withoutProcessing) {
            request.processUtilCloseTag();
        }

        final FormState entryState = (FormState) context.getVariable(ENTRY_FIELDS);

        // TODO the list of included fields should be considered in the next method (see EditObject)
        final InputField[] formFields = createFields(action, object);
        containedBlock.hideExcludedParameters(formFields);
        containedBlock.setUpValues(formFields);
View Full Code Here

public class EditObject extends AbstractElementProcessor {

    @Override
    public void process(final Request request) {
        final RequestContext context = request.getContext();

        final String objectId = request.getOptionalProperty(OBJECT);
        final String forwardEditedTo = request.getOptionalProperty(VIEW);
        final String forwardErrorTo = request.getOptionalProperty(ERRORS);
        final boolean hideNonEditableFields = request.isRequested(HIDE_UNEDITABLE, false);
        final boolean showIcon = request.isRequested(SHOW_ICON, true);
        String buttonTitle = request.getOptionalProperty(BUTTON_TITLE);
        String formTitle = request.getOptionalProperty(FORM_TITLE);
        final String formId = request.getOptionalProperty(FORM_ID, request.nextFormId());
        final String variable = request.getOptionalProperty(RESULT_NAME);
        final String resultOverride = request.getOptionalProperty(RESULT_OVERRIDE);
        final String scope = request.getOptionalProperty(SCOPE);
        final String className = request.getOptionalProperty(CLASS, "edit full");
        final String id = request.getOptionalProperty(ID);
        final String completionMessage = request.getOptionalProperty(MESSAGE);

        final ObjectAdapter object = context.getMappedObjectOrResult(objectId);
        final String actualObjectId = context.mapObject(object, Scope.INTERACTION);
        final String version = context.mapVersion(object);

        final FormState entryState = (FormState) context.getVariable(ENTRY_FIELDS);

        final ObjectSpecification specification = object.getSpecification();
        final FormFieldBlock containedBlock = new FormFieldBlock() {
            @Override
            public boolean isVisible(final String name) {
                final ObjectAssociation fld = specification.getAssociation(name);
                final boolean isVisible = fld.isVisible(IsisContext.getAuthenticationSession(), object).isAllowed();
                final boolean isUseable = fld.isUsable(IsisContext.getAuthenticationSession(), object).isAllowed();
                return isVisible && isUseable;
            }

            @Override
            public ObjectAdapter getCurrent(final String name) {
                ObjectAdapter value = null;
                if (entryState != null) {
                    final FieldEditState field2 = entryState.getField(name);
                    value = field2.getValue();
                }
                if (value == null) {
                    final ObjectAssociation fld = specification.getAssociation(name);
                    value = fld.get(object);
                }
                return value;
            }

            @Override
            public boolean isNullable(final String name) {
                final ObjectAssociation fld = specification.getAssociation(name);
                return !fld.isMandatory();
            }
        };

        request.setBlockContent(containedBlock);
        request.processUtilCloseTag();

        final AuthenticationSession session = IsisContext.getAuthenticationSession();
        List<ObjectAssociation> viewFields =
            specification.getAssociations(ObjectAssociationFilters.dynamicallyVisible(session, object));
        viewFields = containedBlock.includedFields(viewFields);
        final InputField[] formFields = createFields(viewFields);

        initializeFields(context, object, formFields, entryState, !hideNonEditableFields);
        setDefaults(context, object, formFields, entryState, showIcon);

        copyFieldContent(context, object, formFields, showIcon);
        overrideWithHtml(context, containedBlock, formFields);
        String errors = null;
        if (entryState != null && entryState.isForForm(formId)) {
            copyEntryState(context, object, formFields, entryState);
            errors = entryState.getError();
        }

        final String errorView =
            context.fullFilePath(forwardErrorTo == null ? context.getResourceFile() : forwardErrorTo);
        final List<HiddenInputField> hiddenFields = new ArrayList<HiddenInputField>();
        hiddenFields.add(new HiddenInputField("_" + OBJECT, actualObjectId));
        hiddenFields.add(new HiddenInputField("_" + VERSION, version));
        hiddenFields.add(new HiddenInputField("_" + FORM_ID, formId));
        hiddenFields.add(completionMessage == null ? null : new HiddenInputField("_" + MESSAGE, completionMessage));
        hiddenFields.add(forwardEditedTo == null ? null : new HiddenInputField("_" + VIEW, context
            .fullFilePath(forwardEditedTo)));
        hiddenFields.add(new HiddenInputField("_" + ERRORS, errorView));
        hiddenFields.add(variable == null ? null : new HiddenInputField("_" + RESULT_NAME, variable));
        hiddenFields.add(resultOverride == null ? null : new HiddenInputField("_" + RESULT_OVERRIDE, resultOverride));
        hiddenFields.add(scope == null ? null : new HiddenInputField("_" + SCOPE, scope));
View Full Code Here

            final String id = request.getRequiredProperty(COLLECTION);
            final String exclude = request.getOptionalProperty("exclude");

            final ObjectAdapter collection = request.getContext().getMappedObjectOrResult(id);

            final RequestContext context = request.getContext();
            final CollectionFacet facet = collection.getSpecification().getFacet(CollectionFacet.class);
            final Iterator<ObjectAdapter> iterator = facet.iterator(collection);

            final StringBuffer buffer = new StringBuffer();

            while (iterator.hasNext()) {
                final ObjectAdapter element = iterator.next();
                final Scope scope = Scope.INTERACTION;
                final String elementId = context.mapObject(element, scope);
                if (exclude != null && context.getMappedObject(exclude) == element) {
                    continue;
                }
                final String title = element.titleString();
                final String checked = "";
                buffer.append("<input type=\"radio\" name=\"" + field + "\" value=\"" + elementId + "\"" + checked
View Full Code Here

        }
    }

    private String onlyItem(final Request request, final String field, final ObjectAdapter collection,
        final CollectionFacet facet) {
        final RequestContext context = request.getContext();
        final Iterator<ObjectAdapter> iterator = facet.iterator(collection);
        final StringBuffer buffer = new StringBuffer();
        final ObjectAdapter element = iterator.next();
        final String elementId = context.mapObject(element, Scope.INTERACTION);
        buffer.append("<img class=\"small-icon\" src=\"" + request.getContext().imagePath(element) + "\" alt=\""
            + element.getSpecification().getShortIdentifier() + "\"/>" + element.titleString() + "\n");
        buffer.append("<input type=\"hidden\" name=\"" + field + "\" value=\"" + elementId + "\" />\n");
        return buffer.toString();
    }
View Full Code Here

        return buffer.toString();
    }

    private String radioButtonList(final Request request, final String field, final boolean allowNotSet,
        final ObjectAdapter collection, final ObjectAdapter selectedItem, final CollectionFacet facet) {
        final RequestContext context = request.getContext();
        final Iterator<ObjectAdapter> iterator = facet.iterator(collection);
        final StringBuffer buffer = new StringBuffer();
        if (allowNotSet) {
            buffer.append("<input type=\"radio\" name=\"" + field + "\" value=\"null\"></input><br/>\n");
        }
        while (iterator.hasNext()) {
            final ObjectAdapter element = iterator.next();
            final String elementId = context.mapObject(element, Scope.INTERACTION);
            final String title = element.titleString();
            final String checked = element == selectedItem ? "checked=\"checked\"" : "";
            buffer.append("<input type=\"radio\" name=\"" + field + "\" value=\"" + elementId + "\"" + checked + ">"
                + title + "</input><br/>\n");
        }
View Full Code Here

        return buffer.toString();
    }

    private String dropdownList(final Request request, final String field, final boolean allowNotSet,
        final ObjectAdapter collection, final ObjectAdapter selectedItem, String size, final CollectionFacet facet) {
        final RequestContext context = request.getContext();
        final Iterator<ObjectAdapter> iterator = facet.iterator(collection);
        final StringBuffer buffer = new StringBuffer();
        size = size == null ? "" : " size =\"" + size + "\"";
        buffer.append("<select name=\"" + field + "\"" + size + " >\n");
        if (allowNotSet) {
            buffer.append("  <option value=\"null\"></option>\n");
        }
        while (iterator.hasNext()) {
            final ObjectAdapter element = iterator.next();
            final String elementId = context.mapObject(element, Scope.INTERACTION);
            final String title = element.titleString();
            final String checked = element == selectedItem ? "selected=\"selected\"" : "";
            buffer.append("  <option value=\"" + elementId + "\"" + checked + ">" + title + "</option>\n");
        }
        buffer.append("</select>\n");
View Full Code Here

    public void process(final Request request) {
        final String title = request.getOptionalProperty(BUTTON_TITLE, "Remove From List");
        final String cls = request.getOptionalProperty(CLASS, "action in-line delete confirm");
        final String object = request.getOptionalProperty(OBJECT);
        final String resultOverride = request.getOptionalProperty(RESULT_OVERRIDE);
        final RequestContext context = request.getContext();
        final String objectId = object != null ? object : (String) context.getVariable(RequestContext.RESULT);
        final ObjectAdapter adapter = MethodsUtils.findObject(context, objectId);

        final String element = request.getOptionalProperty(ELEMENT, (String) context.getVariable(ELEMENT));
        final ObjectAdapter elementId = MethodsUtils.findObject(context, element);

        final String fieldName = request.getRequiredProperty(FIELD);

        String view = request.getOptionalProperty(VIEW);
        view = context.fullFilePath(view == null ? context.getResourceFile() : view);
        String error = request.getOptionalProperty(ERRORS);
        error = context.fullFilePath(error == null ? context.getResourceFile() : error);

        request.processUtilCloseTag();

        write(request, adapter, fieldName, elementId, resultOverride, view, error, title, cls);
    }
View Full Code Here

public abstract class AbstractTableView extends AbstractElementProcessor {

    @Override
    public void process(final Request request) {
        final RequestContext context = request.getContext();

        ObjectAdapter collection;
        String parentObjectId = null;
        boolean isFieldEditable = false;
        final String field = request.getOptionalProperty(FIELD);
        final String tableClass = request.getOptionalProperty(CLASS);
        ObjectSpecification elementSpec;
        if (field != null) {
            final String objectId = request.getOptionalProperty(OBJECT);
            final ObjectAdapter object = context.getMappedObjectOrResult(objectId);
            if (object == null) {
                throw new ScimpiException("No object for result or " + objectId);
            }
            final ObjectAssociation objectField = object.getSpecification().getAssociation(field);
            if (!objectField.isOneToManyAssociation()) {
                throw new ScimpiException("Field " + objectField.getId() + " is not a collection");
            }
            isFieldEditable = objectField.isUsable(IsisContext.getAuthenticationSession(), object).isAllowed();
            getPersistenceSession().resolveField(object, objectField);
            collection = objectField.get(object);
            final TypeOfFacet facet = objectField.getFacet(TypeOfFacet.class);
            elementSpec = facet.valueSpec();
            parentObjectId = objectId == null ? context.mapObject(object, Scope.REQUEST) : objectId;
        } else {
            final String id = request.getOptionalProperty(COLLECTION);
            collection = context.getMappedObjectOrResult(id);
            elementSpec = collection.getElementSpecification();
        }

        final String summary = request.getOptionalProperty("summary");
        final String rowClassesList = request.getOptionalProperty(ROW_CLASSES, ODD_ROW_CLASS + "|" + EVEN_ROW_CLASS);
View Full Code Here

TOP

Related Classes of org.apache.isis.viewer.scimpi.dispatcher.context.RequestContext

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.