Пример #1
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());
      }
    }
  }
Пример #2
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();
 }
Пример #3
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);
    }
  }
Пример #4
0
  @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>");
  }