Search in sources :

Example 11 with WOComponent

use of com.webobjects.appserver.WOComponent in project wonder-slim by undur.

the class AjaxOptions method _appendToBuffer.

/**
 * Adds JSON formatted key-value pairs from options to end of response content.  Does not adds the surrounding "{" and "}" signifying a dictionary / object.
 *
 * @param options dictionary of key-value pairs, intended to have come from AjaxOption
 * @param appendable appendable to add JSON formatted key-value pairs to
 * @param context WOContext to provide WOComponent to resolve binding values in
 */
public static void _appendToBuffer(NSDictionary options, Appendable appendable, WOContext context) {
    if (options != null) {
        WOComponent component = context.component();
        boolean hasPreviousOptions = false;
        Enumeration bindingsEnum = options.keyEnumerator();
        while (bindingsEnum.hasMoreElements()) {
            String bindingName = (String) bindingsEnum.nextElement();
            if (!"options".equals(bindingName)) {
                Object bindingValue = options.objectForKey(bindingName);
                // This is needed for the double step to resolve the value for ^ notation
                if (bindingValue instanceof WOAssociation) {
                    WOAssociation association = (WOAssociation) bindingValue;
                    bindingValue = association.valueInComponent(component);
                }
                if (bindingValue != null) {
                    try {
                        if (hasPreviousOptions) {
                            appendable.append(", ");
                        }
                        appendable.append(bindingName);
                        appendable.append(':');
                        appendable.append(bindingValue.toString());
                        hasPreviousOptions = true;
                    } catch (IOException e) {
                    // ignore
                    }
                }
            }
        }
    }
}
Also used : WOAssociation(com.webobjects.appserver.WOAssociation) Enumeration(java.util.Enumeration) WOComponent(com.webobjects.appserver.WOComponent) IOException(java.io.IOException)

Example 12 with WOComponent

use of com.webobjects.appserver.WOComponent in project wonder-slim by undur.

the class AjaxDraggable method appendToResponse.

@Override
@SuppressWarnings("unchecked")
public void appendToResponse(WOResponse res, WOContext ctx) {
    if (canGetValueForBinding("draggableObject")) {
        Object draggableObject = valueForBinding("draggableObject");
        WOComponent page = context().page();
        Map<WOComponent, Map<String, Object>> componentDraggablesMap = (Map<WOComponent, Map<String, Object>>) ctx.session().objectForKey(AjaxDraggable.COMPONENT_DRAGGABLES_MAP_KEY);
        if (componentDraggablesMap == null) {
            componentDraggablesMap = new WeakHashMap<WOComponent, Map<String, Object>>();
            ctx.session().setObjectForKey(componentDraggablesMap, AjaxDraggable.COMPONENT_DRAGGABLES_MAP_KEY);
        }
        Map<String, Object> draggablesMap = componentDraggablesMap.get(page);
        if (draggablesMap == null) {
            draggablesMap = new HashMap<>();
            componentDraggablesMap.put(page, draggablesMap);
        }
        String id = draggableID();
        if (draggableObject == null) {
            draggablesMap.remove(id);
        } else {
            draggablesMap.put(id, draggableObject);
        }
    }
    super.appendToResponse(res, ctx);
}
Also used : WOComponent(com.webobjects.appserver.WOComponent) Map(java.util.Map) HashMap(java.util.HashMap) WeakHashMap(java.util.WeakHashMap)

Example 13 with WOComponent

use of com.webobjects.appserver.WOComponent in project wonder-slim by undur.

the class AjaxDroppable method handleRequest.

@Override
public WOActionResults handleRequest(WORequest request, WOContext context) {
    AjaxUpdateContainer.setUpdateContainerID(request, (String) valueForBinding("updateContainerID"));
    String droppedDraggableID = request.stringFormValueForKey(_draggableIDKeyName);
    if (canSetValueForBinding("droppedDraggableID")) {
        setValueForBinding(droppedDraggableID, "droppedDraggableID");
    }
    if (canSetValueForBinding("droppedObject")) {
        WOComponent page = context.page();
        Object droppedObject = AjaxDraggable.draggableObjectForPage(page, droppedDraggableID);
        setValueForBinding(droppedObject, "droppedObject");
    }
    if (canGetValueForBinding("action")) {
        WOActionResults results = (WOActionResults) valueForBinding("action");
        if (results != null) {
            System.out.println("AjaxDroppable.handleRequest: Not quite sure what to do with non-null results yet ...");
        }
    }
    return null;
}
Also used : WOActionResults(com.webobjects.appserver.WOActionResults) WOComponent(com.webobjects.appserver.WOComponent)

Example 14 with WOComponent

use of com.webobjects.appserver.WOComponent in project wonder-slim by undur.

the class AjaxUpdateContainer method handleRequest.

@Override
public WOActionResults handleRequest(WORequest request, WOContext context) {
    WOComponent component = context.component();
    String id = _containerID(context);
    if (associations().objectForKey("action") != null) {
        @SuppressWarnings("unused") WOActionResults results = (WOActionResults) valueForBinding("action", component);
    // ignore results
    }
    WOResponse response = AjaxUtils.createResponse(request, context);
    AjaxUtils.setPageReplacementCacheKey(context, id);
    if (hasChildrenElements()) {
        appendChildrenToResponse(response, context);
    }
    String onRefreshComplete = (String) valueForBinding("onRefreshComplete", component);
    if (onRefreshComplete != null) {
        AjaxUtils.appendScriptHeader(response);
        response.appendContentString(onRefreshComplete);
        AjaxUtils.appendScriptFooter(response);
    }
    if (AjaxModalDialog.isInDialog(context)) {
        AjaxUtils.appendScriptHeader(response);
        response.appendContentString("AMD.contentUpdated();");
        AjaxUtils.appendScriptFooter(response);
    }
    return null;
}
Also used : WOActionResults(com.webobjects.appserver.WOActionResults) WOComponent(com.webobjects.appserver.WOComponent) WOResponse(com.webobjects.appserver.WOResponse)

Example 15 with WOComponent

use of com.webobjects.appserver.WOComponent in project wonder-slim by undur.

the class AjaxUpdateLink method appendToResponse.

@Override
public void appendToResponse(WOResponse response, WOContext context) {
    WOComponent component = context.component();
    boolean disabled = booleanValueForBinding("disabled", false, component);
    Object stringValue = valueForBinding("string", component);
    String functionName = (String) valueForBinding("functionName", component);
    if (functionName == null) {
        String elementName;
        boolean button = booleanValueForBinding("button", false, component);
        if (button) {
            elementName = "input";
        } else {
            elementName = (String) valueForBinding("elementName", "a", component);
        }
        boolean isATag = "a".equalsIgnoreCase(elementName);
        boolean renderTags = (!disabled || !isATag);
        if (renderTags) {
            response.appendContentString("<");
            response.appendContentString(elementName);
            response.appendContentString(" ");
            if (button) {
                appendTagAttributeToResponse(response, "type", "button");
            }
            if (isATag) {
                appendTagAttributeToResponse(response, "href", "javascript:void(0);");
            }
            if (!disabled) {
                appendTagAttributeToResponse(response, "onclick", onClick(context, false));
            }
            appendTagAttributeToResponse(response, "title", valueForBinding("title", component));
            appendTagAttributeToResponse(response, "value", valueForBinding("value", component));
            appendTagAttributeToResponse(response, "class", valueForBinding("class", component));
            appendTagAttributeToResponse(response, "style", valueForBinding("style", component));
            appendTagAttributeToResponse(response, "id", valueForBinding("id", component));
            appendTagAttributeToResponse(response, "accesskey", valueForBinding("accesskey", component));
            if (button) {
                if (stringValue != null) {
                    appendTagAttributeToResponse(response, "value", stringValue);
                }
                if (disabled) {
                    response.appendContentString(" disabled");
                }
            }
            // appendTagAttributeToResponse(response, "onclick",
            // onClick(context));
            response.appendContentString(">");
        }
        if (stringValue != null && !button) {
            response.appendContentHTMLString(stringValue.toString());
        }
        appendChildrenToResponse(response, context);
        if (renderTags) {
            response.appendContentString("</");
            response.appendContentString(elementName);
            response.appendContentString(">");
        }
    } else {
        AjaxUtils.appendScriptHeader(response);
        response.appendContentString(functionName);
        response.appendContentString(" = ");
        response.appendContentString(onClick(context, true));
        AjaxUtils.appendScriptFooter(response);
    }
    super.appendToResponse(response, context);
}
Also used : WOComponent(com.webobjects.appserver.WOComponent)

Aggregations

WOComponent (com.webobjects.appserver.WOComponent)68 WOActionResults (com.webobjects.appserver.WOActionResults)11 WOResponse (com.webobjects.appserver.WOResponse)10 WOContext (com.webobjects.appserver.WOContext)8 NSMutableDictionary (com.webobjects.foundation.NSMutableDictionary)8 NSDictionary (com.webobjects.foundation.NSDictionary)7 Format (java.text.Format)5 WOApplication (com.webobjects.appserver.WOApplication)4 WOAssociation (com.webobjects.appserver.WOAssociation)4 NSMutableArray (com.webobjects.foundation.NSMutableArray)4 ERXWOContext (er.extensions.appserver.ERXWOContext)4 ParseException (java.text.ParseException)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 WOElement (com.webobjects.appserver.WOElement)3 WORequest (com.webobjects.appserver.WORequest)3 WODynamicElementCreationException (com.webobjects.appserver._private.WODynamicElementCreationException)3 NSArray (com.webobjects.foundation.NSArray)3 WOSession (com.webobjects.appserver.WOSession)2 ERXMutableURL (er.extensions.foundation.ERXMutableURL)2