Search in sources :

Example 1 with WODynamicElementCreationException

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

the class AjaxFunctionLink method _appendAttributesToResponse.

public static void _appendAttributesToResponse(WOResponse response, WOContext context, WOAssociation actionAssociation, WOAssociation updateContainerIDAssociation) {
    WOComponent component = context.component();
    if (actionAssociation != null) {
        String action = (String) actionAssociation.valueInComponent(component);
        String updateContainerID;
        if (updateContainerIDAssociation != null) {
            updateContainerID = (String) updateContainerIDAssociation.valueInComponent(component);
        } else {
            updateContainerID = AjaxUpdateContainer.currentUpdateContainerID();
        }
        if (updateContainerID == null) {
            throw new WODynamicElementCreationException("You must either set the 'updateContainerID' binding or the link must be contained inside of an AjaxUpdateContainer.");
        }
        response.appendContentString(" onclick = \"");
        response.appendContentString(updateContainerID);
        if ("edit".equalsIgnoreCase(action)) {
            response.appendContentString("Edit");
        } else if ("cancel".equalsIgnoreCase(action)) {
            response.appendContentString("Cancel");
        } else if ("save".equalsIgnoreCase(action)) {
            response.appendContentString("Save");
        } else if ("update".equalsIgnoreCase(action)) {
            response.appendContentString("Update");
        } else {
            throw new WODynamicElementCreationException("Unknown AjaxInPlace action '" + action + "'.  Must be one of 'edit', 'cancel', 'save', or 'Update'.");
        }
        response.appendContentString("()\"");
    }
}
Also used : WOComponent(com.webobjects.appserver.WOComponent) WODynamicElementCreationException(com.webobjects.appserver._private.WODynamicElementCreationException)

Example 2 with WODynamicElementCreationException

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

the class AjaxSubmitButton method appendToResponse.

@Override
public void appendToResponse(WOResponse response, WOContext context) {
    WOComponent component = context.component();
    String functionName = (String) valueForBinding("functionName", null, component);
    String formName = (String) valueForBinding("formName", component);
    boolean showUI = (functionName == null || booleanValueForBinding("showUI", false, component));
    boolean showButton = showUI && booleanValueForBinding("button", true, component);
    boolean useButtonTagBinding = booleanValueForBinding("useButtonTag", false, component);
    String formReference;
    if ((!showButton || functionName != null) && formName == null) {
        formName = ERXWOForm.formName(context, null);
        if (formName == null) {
            throw new WODynamicElementCreationException("If button = false or functionName is not null, the containing form must have an explicit name.");
        }
    }
    if (formName == null) {
        formReference = "this.form";
    } else {
        formReference = "document." + formName;
    }
    StringBuilder onClickBuffer = new StringBuilder();
    String onClickBefore = (String) valueForBinding("onClickBefore", component);
    if (onClickBefore != null) {
        onClickBuffer.append("if (");
        onClickBuffer.append(onClickBefore);
        onClickBuffer.append(") {");
    }
    String updateContainerID = AjaxUpdateContainer.updateContainerID(this, component);
    // PROTOTYPE EFFECTS
    String beforeEffect = (String) valueForBinding("beforeEffect", component);
    if (beforeEffect != null) {
        onClickBuffer.append("new ");
        onClickBuffer.append(AjaxUpdateLink.fullEffectName(beforeEffect));
        onClickBuffer.append("('");
        String beforeEffectID = (String) valueForBinding("beforeEffectID", component);
        if (beforeEffectID == null) {
            beforeEffectID = AjaxUpdateContainer.currentUpdateContainerID();
            if (beforeEffectID == null) {
                beforeEffectID = updateContainerID;
            }
        }
        onClickBuffer.append(beforeEffectID);
        onClickBuffer.append("', { ");
        String beforeEffectDuration = (String) valueForBinding("beforeEffectDuration", component);
        if (beforeEffectDuration != null) {
            onClickBuffer.append("duration: ");
            onClickBuffer.append(beforeEffectDuration);
            onClickBuffer.append(", ");
        }
        onClickBuffer.append("queue:'end', afterFinish: function() {");
    }
    String replaceID = (String) valueForBinding("replaceID", component);
    String id = (updateContainerID == null) ? replaceID : updateContainerID;
    if (id != null) {
        onClickBuffer.append("ASB.update('" + id + "',");
    } else {
        onClickBuffer.append("ASB.request(");
    }
    onClickBuffer.append(formReference);
    if (valueForBinding("functionName", component) != null) {
        onClickBuffer.append(",additionalParams");
    } else {
        onClickBuffer.append(",null");
    }
    onClickBuffer.append(',');
    NSMutableDictionary options = createAjaxOptions(component);
    if (replaceID != null) {
        options.setObjectForKey("true", ERXAjaxApplication.KEY_REPLACED);
    }
    AjaxUpdateLink.addEffect(options, (String) valueForBinding("effect", component), id, (String) valueForBinding("effectDuration", component));
    String afterEffectID = (String) valueForBinding("afterEffectID", component);
    if (afterEffectID == null) {
        afterEffectID = AjaxUpdateContainer.currentUpdateContainerID();
        if (afterEffectID == null) {
            afterEffectID = id;
        }
    }
    AjaxUpdateLink.addEffect(options, (String) valueForBinding("afterEffect", component), afterEffectID, (String) valueForBinding("afterEffectDuration", component));
    AjaxOptions.appendToBuffer(options, onClickBuffer, context);
    onClickBuffer.append(')');
    String onClick = (String) valueForBinding("onClick", component);
    if (onClick != null) {
        onClickBuffer.append(';');
        onClickBuffer.append(onClick);
    }
    if (beforeEffect != null) {
        onClickBuffer.append("}});");
    }
    if (onClickBefore != null) {
        onClickBuffer.append('}');
    }
    if (functionName != null) {
        AjaxUtils.appendScriptHeader(response);
        response.appendContentString(functionName + " = function(additionalParams) { " + onClickBuffer + " }\n");
        AjaxUtils.appendScriptFooter(response);
    }
    if (showUI) {
        boolean disabled = disabledInComponent(component);
        String elementName = (String) valueForBinding("elementName", "a", component);
        boolean useButtonTag = useButtonTagBinding || ERXProperties.booleanForKeyWithDefault("er.extensions.foundation.ERXPatcher.DynamicElementsPatches.SubmitButton.useButtonTag", false);
        if (showButton) {
            elementName = useButtonTag ? "button" : "input";
            response.appendContentString("<" + elementName + " ");
            appendTagAttributeToResponse(response, "type", "button");
            String name = nameInContext(context, component);
            appendTagAttributeToResponse(response, "name", name);
            appendTagAttributeToResponse(response, "value", valueForBinding("value", component));
            appendTagAttributeToResponse(response, "accesskey", valueForBinding("accesskey", component));
            if (disabled) {
                appendTagAttributeToResponse(response, "disabled", "disabled");
            }
        } else {
            boolean isATag = "a".equalsIgnoreCase(elementName);
            if (isATag) {
                response.appendContentString("<a href = \"javascript:void(0)\" ");
            } else {
                response.appendContentString("<" + elementName + " ");
            }
        }
        appendTagAttributeToResponse(response, "class", valueForBinding("class", component));
        appendTagAttributeToResponse(response, "style", valueForBinding("style", component));
        appendTagAttributeToResponse(response, "id", valueForBinding("id", component));
        appendTagAttributeToResponse(response, "tabindex", valueForBinding("tabindex", component));
        appendTagAttributeToResponse(response, "title", valueForBinding("title", component));
        if (functionName == null) {
            appendTagAttributeToResponse(response, "onclick", onClickBuffer.toString());
        } else {
            appendTagAttributeToResponse(response, "onclick", functionName + "()");
        }
        if (showButton && !useButtonTag) {
            response.appendContentString(" />");
        } else {
            response.appendContentString(">");
            if (hasChildrenElements()) {
                appendChildrenToResponse(response, context);
            } else {
                response.appendContentString((String) valueForBinding("value", component));
            }
            response.appendContentString("</" + elementName + ">");
        }
    }
    super.appendToResponse(response, context);
}
Also used : WOComponent(com.webobjects.appserver.WOComponent) WODynamicElementCreationException(com.webobjects.appserver._private.WODynamicElementCreationException) NSMutableDictionary(com.webobjects.foundation.NSMutableDictionary)

Example 3 with WODynamicElementCreationException

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

the class ERXJavaScript method appendChildrenToResponse.

@Override
public void appendChildrenToResponse(WOResponse woresponse, WOContext wocontext) {
    String script = "";
    boolean hideInComment = ERXProperties.booleanForKeyWithDefault("er.extensions.ERXJavaScript.hideInComment", true);
    WOComponent wocomponent = wocontext.component();
    if (_hideInComment != null) {
        hideInComment = _hideInComment.booleanValueInComponent(wocomponent);
    }
    if (hideInComment) {
        woresponse._appendContentAsciiString("<!--");
    }
    woresponse.appendContentCharacter('\n');
    if (_scriptFile != null) {
        String filename = (String) _scriptFile.valueInComponent(wocomponent);
        if (filename != null) {
            String framework = null;
            if (_scriptFramework != null) {
                framework = (String) _scriptFramework.valueInComponent(wocomponent);
            } else if (_framework != null) {
                framework = (String) _framework.valueInComponent(wocomponent);
            }
            java.net.URL url = WOApplication.application().resourceManager().pathURLForResourceNamed(filename, framework, wocontext._languages());
            if (url == null) {
                url = wocontext.component()._componentDefinition().pathURLForResourceNamed(filename, framework, wocontext._languages());
            }
            if (url == null) {
                throw new WODynamicElementCreationException("<" + getClass().getName() + "> : cannot find script file '" + filename + "'");
            }
            script = _NSStringUtilities.stringFromPathURL(url);
            if (ERXResourceManager._shouldGenerateCompleteResourceURL(wocontext)) {
                script = ERXResourceManager._completeURLForResource(script, null, wocontext);
            }
        }
        woresponse.appendContentString(script);
    } else if (_scriptString != null) {
        Object obj1 = _scriptString.valueInComponent(wocomponent);
        if (obj1 != null) {
            script = obj1.toString();
        }
        woresponse.appendContentString(script);
    } else {
        super.appendChildrenToResponse(woresponse, wocontext);
    }
    woresponse.appendContentCharacter('\n');
    if (hideInComment) {
        woresponse._appendContentAsciiString("//-->");
    }
}
Also used : WOComponent(com.webobjects.appserver.WOComponent) WODynamicElementCreationException(com.webobjects.appserver._private.WODynamicElementCreationException)

Example 4 with WODynamicElementCreationException

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

the class ERXWOSwitchComponent method _realComponentWithName.

public WOElement _realComponentWithName(String name, String elementID, WOContext paramWOContext) {
    WOElement localWOElement;
    synchronized (this) {
        localWOElement = (WOElement) componentCache.objectForKey(elementID);
        if (localWOElement == null) {
            localWOElement = WOApplication.application().dynamicElementWithName(name, componentAttributes, template, paramWOContext._languages());
            if (localWOElement == null) {
                throw new WODynamicElementCreationException("<" + getClass().getName() + "> : cannot find component or dynamic element named " + name);
            }
            componentCache.setObjectForKey(localWOElement, elementID);
        }
    }
    return localWOElement;
}
Also used : WODynamicElementCreationException(com.webobjects.appserver._private.WODynamicElementCreationException) WOElement(com.webobjects.appserver.WOElement)

Aggregations

WODynamicElementCreationException (com.webobjects.appserver._private.WODynamicElementCreationException)4 WOComponent (com.webobjects.appserver.WOComponent)3 WOElement (com.webobjects.appserver.WOElement)1 NSMutableDictionary (com.webobjects.foundation.NSMutableDictionary)1