@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(); } }; }
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); } }
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()); } } }
@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>"); }