Example #1
0
 @Override
 public void process(final Request request) {
   final FormFieldBlock block = (FormFieldBlock) request.getBlockContent();
   final String field = request.getRequiredProperty(FIELD);
   if (block.isVisible(field)) {
     processElement(request, block, field);
   }
   request.skipUntilClose();
 }
Example #2
0
 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");
   return buffer.toString();
 }
Example #3
0
  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");
    }

    return buffer.toString();
  }
Example #4
0
  @Override
  protected TableContentWriter createRowBuilder(
      final Request request,
      final RequestContext context,
      final String parent,
      final List<ObjectAssociation> allFields,
      final ObjectAdapter collection) {

    final String title = request.getOptionalProperty(TABLE_TITLE);
    final String variable = request.getOptionalProperty(ELEMENT_NAME, ELEMENT);
    final String headerClass = request.getOptionalProperty("head-" + CLASS);

    final TableBlock block = new TableBlock();
    block.setCollection(collection);
    block.setElementName(variable);
    request.setBlockContent(block);
    request.pushNewBuffer();
    request.processUtilCloseTag();
    final String headers = request.popBuffer();
    return new TableContentWriter() {

      @Override
      public void writeFooters(final PageWriter writer) {}

      public void tidyUp() {
        request.popBlockContent();
      }

      @Override
      public void writeCaption(PageWriter writer) {
        if (title != null) {
          writer.appendHtml("<caption>");
          writer.appendHtml(title);
          writer.appendHtml("</thead>");
        }
      }

      @Override
      public void writeHeaders(final PageWriter writer) {
        final String headerSegment = headerClass == null ? "" : (" class=\"" + headerClass + "\"");
        writer.appendHtml("<thead" + headerSegment + ">");
        writer.appendHtml(headers);
        writer.appendHtml("</thead>");
      }

      @Override
      public void writeElement(
          final Request request, final RequestContext context, final ObjectAdapter element) {
        context.addVariable(variable, context.mapObject(element, Scope.REQUEST), Scope.REQUEST);
        final RepeatMarker end = request.createMarker();
        final RepeatMarker marker = block.getMarker();
        marker.repeat();
        request.processUtilCloseTag();
        end.repeat();
      }
    };
  }
Example #5
0
  private String showSelectionList(
      final Request request,
      final ObjectAdapter collection,
      final ObjectAdapter selectedItem,
      final boolean allowNotSet,
      final String type) {
    final String field = request.getRequiredProperty(FIELD);
    final CollectionFacet facet = collection.getSpecification().getFacet(CollectionFacet.class);

    if (type.equals("radio")) {
      return radioButtonList(request, field, allowNotSet, collection, selectedItem, facet);
    } else if (type.equals("list")) {
      final String size = request.getOptionalProperty("size", "5");
      return dropdownList(request, field, allowNotSet, collection, selectedItem, size, facet);
    } else if (type.equals("dropdown")) {
      return dropdownList(request, field, allowNotSet, collection, selectedItem, null, facet);
    } else {
      throw new UnknownTypeException(type);
    }
  }
Example #6
0
 private String showSelectionList(
     final Request request,
     final String collectionId,
     final ObjectAdapter selectedItem,
     final boolean allowNotSet,
     final String type) {
   if (collectionId != null && !collectionId.equals("")) {
     final ObjectAdapter collection = request.getContext().getMappedObjectOrResult(collectionId);
     return showSelectionList(request, collection, selectedItem, allowNotSet, type);
   } else {
     return null;
   }
 }
  @Override
  public void process(final Request request) {
    final TableBlock tableBlock = (TableBlock) request.getBlockContent();
    final String id = request.getOptionalProperty(OBJECT);
    final String fieldName = request.getRequiredProperty(FIELD);
    final String linkView = request.getOptionalProperty(LINK_VIEW);
    String className = request.getOptionalProperty(CLASS);
    className = className == null ? "" : " class=\"" + className + "\"";
    RequestContext context = request.getContext();
    final ObjectAdapter object = context.getMappedObjectOrVariable(id, tableBlock.getElementName());
    final ObjectAssociation field = object.getSpecification().getAssociation(fieldName);
    if (field == null) {
      throw new ScimpiException(
          "No field " + fieldName + " in " + object.getSpecification().getFullIdentifier());
    }
    request.appendHtml("<td" + className + ">");
    if (field.isVisible(IsisContext.getAuthenticationSession(), object, where).isAllowed()) {
      final ObjectAdapter fieldReference = field.get(object);
      final String source =
          fieldReference == null ? "" : context.mapObject(fieldReference, Scope.REQUEST);
      final String name = request.getOptionalProperty(RESULT_NAME, fieldName);
      context.addVariable(name, Request.getEncoder().encoder(source), Scope.REQUEST);

      if (linkView != null) {
        final String linkId = context.mapObject(object, Scope.REQUEST);
        final String linkName = request.getOptionalProperty(LINK_NAME, RequestContext.RESULT);
        final String linkObject = request.getOptionalProperty(LINK_OBJECT, linkId);
        request.appendHtml(
            "<a href=\""
                + linkView
                + "?"
                + linkName
                + "="
                + linkObject
                + context.encodedInteractionParameters()
                + "\">");
      } else if (tableBlock.getlinkView() != null) {
        String linkObjectInVariable = tableBlock.getElementName();
        final String linkId = (String) context.getVariable(linkObjectInVariable);
        request.appendHtml(
            "<a href=\""
                + tableBlock.getlinkView()
                + "?"
                + tableBlock.getlinkName()
                + "="
                + linkId
                + context.encodedInteractionParameters()
                + "\">");
      }
      request.pushNewBuffer();
      request.processUtilCloseTag();
      final String buffer = request.popBuffer();
      if (buffer.trim().length() == 0) {
        request.appendAsHtmlEncoded(fieldReference == null ? "" : fieldReference.titleString());
      } else {
        request.appendHtml(buffer);
      }
      if (linkView != null) {
        request.appendHtml("</a>");
      }
    } else {
      request.skipUntilClose();
    }
    request.appendHtml("</td>");
  }
Example #8
0
 @Override
 public void process(final Request request) {
   request.getContext().startHttpSession();
 }
Example #9
0
  private void processElement(
      final Request request, final FormFieldBlock block, final String field) {
    final String type = request.getOptionalProperty(TYPE, "dropdown");
    if (!request.isPropertySpecified(METHOD) && request.isPropertySpecified(COLLECTION)) {
      final String id = request.getRequiredProperty(COLLECTION, Request.NO_VARIABLE_CHECKING);
      final String selector =
          showSelectionList(request, id, block.getCurrent(field), block.isNullable(field), type);
      block.replaceContent(field, selector);
    } else {
      final String objectId = request.getOptionalProperty(OBJECT);
      final String methodName = request.getRequiredProperty(METHOD);
      final ObjectAdapter object = MethodsUtils.findObject(request.getContext(), objectId);
      final ObjectAction action = MethodsUtils.findAction(object, methodName);
      if (action.getParameterCount() == 0) {
        final ObjectAdapter collection = action.execute(object, new ObjectAdapter[0]);
        final String selector =
            showSelectionList(
                request, collection, block.getCurrent(field), block.isNullable(field), type);
        block.replaceContent(field, selector);
      } else {
        final String id = "selector_options";
        final String id2 = (String) request.getContext().getVariable(id);
        final String selector =
            showSelectionList(request, id2, block.getCurrent(field), block.isNullable(field), type);

        final CreateFormParameter parameters = new CreateFormParameter();
        parameters.objectId = objectId;
        parameters.methodName = methodName;
        parameters.buttonTitle = request.getOptionalProperty(BUTTON_TITLE, "Search");
        parameters.formTitle = request.getOptionalProperty(FORM_TITLE);
        parameters.className = request.getOptionalProperty(CLASS, "selector");
        parameters.id = request.getOptionalProperty(ID);

        parameters.resultName = id;
        parameters.forwardResultTo = request.getContext().getResourceFile();
        parameters.forwardVoidTo = "error";
        parameters.forwardErrorTo = parameters.forwardResultTo;
        parameters.scope = Scope.REQUEST.name();
        request.pushNewBuffer();
        ActionForm.createForm(request, parameters);
        block.replaceContent(field, selector);

        request.appendHtml(request.popBuffer());
      }
    }
  }