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

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


    public static void createForm(final Request request, final CreateFormParameter parameterObject) {
        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, where)) {
            final String notUsable = MethodsUtils.isUsable(object, action, where);
            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, where)) {
            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);
        if (false /* action.isContributed() && !action.hasReturn() && parameterObject.resultOverride == null */) {
            parameterObject.resultOverride = objectId;
        }
        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("_" + ERROR, 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);
View Full Code Here


                continue;
            }
            headers[h++] = fields.get(i).getName();
        }
       
        final RequestContext context = request.getContext();
        final TableContentWriter rowBuilder = rowBuilder(request, context, null, context.mapObject(object, Scope.REQUEST), field.getIdentifier().getMemberName(), fields,
                showIconByDefault);
        write(request, collection, summary, rowBuilder, null, null, null);
    }
View Full Code Here

        if (request.getContext().isDebugDisabled()) {
            request.skipUntilClose();
            return;
        }

        final RequestContext context = request.getContext();
        final Object result = context.getVariable(RequestContext.RESULT);
        request.appendHtml("<div class=\"debug\">");
        request.appendHtml("<a class=\"debug-link\" href=\"/debug/debug.shtml\" target=\"debug\" title=\"debug\" >...</a>");
        if (result != null) {
            request.appendHtml(" <a href=\"/debug/object.shtml?_result=" + result + "\" target=\"debug\"  title=\"debug instance\">...</a>");
        }
View Full Code Here

    // TODO the return points should be pushed on to a stack so that there is
    // traceable history.
    @Override
    public void process(final Request request) {
        // String name = request.getOptionalProperty(NAME);
        final RequestContext context = request.getContext();
        context.addVariable("_return-to", context.getUri(), Scope.SESSION);
    }
View Full Code Here

        final String variableName = request.getRequiredProperty(NAME);
        final String defaultValue = request.getOptionalProperty(VALUE);
        final String scopeName = request.getOptionalProperty(SCOPE);
        final Scope scope = RequestContext.scope(scopeName, Scope.REQUEST);

        final RequestContext context = request.getContext();
        final Object currentValue = context.getVariable(variableName);
        if (currentValue == null) {
            request.appendDebug("     " + variableName + " set to " + defaultValue + " (" + scope + ")");
            context.addVariable(variableName, defaultValue, scope);
        } else {
            request.appendDebug("     " + variableName + " alreadt set to " + currentValue);
        }
    }
View Full Code Here

        }
        request.appendHtml("</div>");
    }

    private Crumbs getCrumbs(final Request request) {
        final RequestContext context = request.getContext();
        Crumbs crumbs = (Crumbs) context.getVariable(_HISTORY);
        if (crumbs == null) {
            crumbs = new Crumbs();
            context.addVariable(_HISTORY, crumbs, Scope.SESSION);
        }
        return crumbs;
    }
View Full Code Here

public class Collection extends AbstractElementProcessor {

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

        ObjectAdapter collection;

        final String field = request.getOptionalProperty(FIELD);
        if (field != null) {
            final String id = request.getOptionalProperty(OBJECT);
            final ObjectAdapter object = context.getMappedObjectOrResult(id);
            final ObjectAssociation objectField = object.getSpecification().getAssociation(field);
            if (!objectField.isOneToManyAssociation()) {
                throw new ScimpiException("Field " + objectField.getId() + " is not a collection");
            }
            IsisContext.getPersistenceSession().resolveField(object, objectField);
            collection = objectField.get(object);
        } else {
            final String id = request.getOptionalProperty(COLLECTION);
            collection = context.getMappedObjectOrResult(id);
        }

        final RepeatMarker marker = request.createMarker();

        final String variable = request.getOptionalProperty(ELEMENT_NAME);
        final String scopeName = request.getOptionalProperty(SCOPE);
        final Scope scope = RequestContext.scope(scopeName, Scope.REQUEST);
        final String rowClassesList = request.getOptionalProperty(ROW_CLASSES, ODD_ROW_CLASS + "|" + EVEN_ROW_CLASS);
        String[] rowClasses = new String[0];
        if (rowClassesList != null) {
            rowClasses = rowClassesList.split("[,|/]");
        }

        final CollectionFacet facet = collection.getSpecification().getFacet(CollectionFacet.class);
        if (facet.size(collection) == 0) {
            request.skipUntilClose();
        } else {
            final Iterator<ObjectAdapter> iterator = facet.iterator(collection);
            int row = 0;
            while (iterator.hasNext()) {
                final ObjectAdapter element = iterator.next();
                context.addVariable("row", "" + (row + 1), Scope.REQUEST);
                if (rowClassesList != null) {
                    context.addVariable("row-class", rowClasses[row % rowClasses.length], Scope.REQUEST);
                }
                context.addVariable(variable, context.mapObject(element, scope), scope);
                marker.repeat();
                request.processUtilCloseTag();
                row++;
            }
        }
View Full Code Here

public class Logon extends AbstractElementProcessor {

    @Override
    public void process(final Request request) {
        String view = request.getOptionalProperty(VIEW);
        RequestContext context = request.getContext();
        if (view == null) {
            view = (String) context.getVariable("login-path");
        }

        final boolean isNotLoggedIn = IsisContext.getSession().getAuthenticationSession() instanceof AnonymousSession;
        if (isNotLoggedIn) {           
            loginForm(request, view);
View Full Code Here

        final String labelDelimiter = request.getOptionalProperty(LABEL_DELIMITER, ":");

        // TODO error if all values are not set (not if use type is not set and all others are still defaults);

        if (object != null) {
            RequestContext context = request.getContext();
            context.addVariable(LOGON_OBJECT, object, Scope.SESSION);
            context.addVariable(LOGON_METHOD, method, Scope.SESSION);
            context.addVariable(LOGON_RESULT_NAME, result, Scope.SESSION);
            context.addVariable(LOGON_SCOPE, resultScope, Scope.SESSION);
            context.addVariable(PREFIX + "roles-field", role, Scope.SESSION);
//            context.addVariable(PREFIX + "isis-user", isisUser, Scope.SESSION);
            context.addVariable(LOGON_FORM_ID, formId, Scope.SESSION);
        }
       
        final String error = request.getOptionalProperty(ERROR, request.getContext().getRequestedFile());
        final List<HiddenInputField> hiddenFields = new ArrayList<HiddenInputField>();
        hiddenFields.add(new HiddenInputField(ERROR, error));
View Full Code Here

    // REVIEW: confirm this rendering context
    private final Where where = Where.OBJECT_FORMS;

    @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(ERROR);
        final String cancelTo = request.getOptionalProperty(CANCEL_TO);
        final boolean hideNonEditableFields = request.isRequested(HIDE_UNEDITABLE, false);
        final boolean showIcon = request.isRequested(SHOW_ICON, showIconByDefault());
        final String labelDelimiter = request.getOptionalProperty(LABEL_DELIMITER, ":");
        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 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 String id = request.getOptionalProperty(ID, object.getSpecification().getShortIdentifier());

        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, where).isAllowed();
                final boolean isUseable = fld.isUsable(IsisContext.getAuthenticationSession(), object, where).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(Contributed.EXCLUDED, ObjectAssociation.Filters.dynamicallyVisible(session, object, where));
        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("_" + ERROR, 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

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.