コード例 #1
0
ファイル: Selector.java プロジェクト: coffeefoam/isis
 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();
 }
コード例 #2
0
ファイル: Selector.java プロジェクト: coffeefoam/isis
  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();
  }
コード例 #3
0
ファイル: Selector.java プロジェクト: coffeefoam/isis
  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());
      }
    }
  }
コード例 #4
0
ファイル: Selector.java プロジェクト: coffeefoam/isis
 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;
   }
 }
コード例 #5
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>");
  }
コード例 #6
0
ファイル: StartSession.java プロジェクト: coffeefoam/isis
 @Override
 public void process(final Request request) {
   request.getContext().startHttpSession();
 }