Search in sources :

Example 16 with WOActionResults

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

the class ERXElse method invokeAction.

@Override
public WOActionResults invokeAction(WORequest worequest, WOContext wocontext) {
    WOActionResults results = null;
    if (!ERXElse.lastConditionChecked()) {
        results = super.invokeAction(worequest, wocontext);
        ERXWOConditional.setLastCondition(null);
    }
    return results;
}
Also used : WOActionResults(com.webobjects.appserver.WOActionResults)

Example 17 with WOActionResults

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

the class AjaxSortableList method handleRequest.

@SuppressWarnings("unchecked")
@Override
public WOActionResults handleRequest(WORequest request, WOContext context) {
    if (!canGetValueForBinding("list")) {
        throw new IllegalArgumentException("You must specify a readable 'list'.");
    }
    if (!canGetValueForBinding("listItemIDKeyPath")) {
        throw new IllegalArgumentException("You must specify 'listItemIDKeyPath' if you specify 'list'.");
    }
    String listItemIDKeyPath = (String) valueForBinding("listItemIDKeyPath");
    Object listItemIDArrayObj = request.formValues().objectForKey(_sortOrderKeyName + "[]");
    NSArray<String> listItemIDArray;
    if (listItemIDArrayObj instanceof NSArray) {
        listItemIDArray = (NSArray<String>) listItemIDArrayObj;
    } else if (listItemIDArrayObj instanceof String) {
        String listItemIDStr = (String) listItemIDArrayObj;
        listItemIDArray = new NSArray<>(listItemIDStr);
    } else {
        throw new IllegalArgumentException("Unknown list item ID array " + listItemIDArrayObj);
    }
    NSArray<Object> list = (NSArray<Object>) valueForBinding("list");
    boolean mutableList = (list instanceof NSMutableArray);
    NSMutableArray<Object> reorderedList;
    if (mutableList) {
        reorderedList = (NSMutableArray<Object>) list;
    } else {
        reorderedList = new NSMutableArray<>();
    }
    int startIndex = 0;
    // If we're starting at an index > 0, add the initial objects
    if (canGetValueForBinding("startIndex")) {
        Number startIndexNumber = (Number) valueForBinding("startIndex");
        startIndex = startIndexNumber.intValue();
        if (!mutableList) {
            for (int i = 0; i < startIndex; i++) {
                reorderedList.addObject(list.objectAtIndex(i));
            }
        }
    }
    // Add the reordered objects
    int listItemIDCount = listItemIDArray.count();
    for (int listItemIDIndex = 0; listItemIDIndex < listItemIDCount; listItemIDIndex++) {
        String itemID = (String) listItemIDArray.objectAtIndex(listItemIDIndex);
        NSRange itemPageRange;
        if (mutableList) {
            itemPageRange = new NSRange(startIndex + listItemIDIndex, listItemIDCount - listItemIDIndex);
        } else {
            itemPageRange = new NSRange(startIndex, listItemIDCount);
        }
        NSArray<Object> itemPageArray = list.subarrayWithRange(itemPageRange);
        try {
            // FIXME: This is disabled because we no longer have EOControl (and thus not EOQualifier) // Hugi 2021-11-13
            throw new RuntimeException("Fisabled forJavaEOControl reasons");
        } catch (Exception e) {
            e.printStackTrace();
        }
        // EOQualifier itemIDQualifier = new EOKeyValueQualifier(listItemIDKeyPath, EOQualifier.QualifierOperatorEqual, itemID);
        // NSArray<Object> matchingItems = EOQualifier.filteredArrayWithQualifier(itemPageArray, itemIDQualifier);
        NSArray<Object> matchingItems = null;
        if (matchingItems.count() == 0) {
            throw new NoSuchElementException("There was no item that matched the ID '" + itemID + "' in " + list + ".");
        } else if (matchingItems.count() > 1) {
            throw new IllegalStateException("There was more than one item that matched the ID '" + itemID + "' in " + list + ".");
        }
        Object replacingItem = matchingItems.objectAtIndex(0);
        if (mutableList) {
            int replacedItemIndex = itemPageRange.location();
            Object replacedItem = reorderedList.objectAtIndex(replacedItemIndex);
            if (replacedItem != replacingItem) {
                int replacingItemIndex = replacedItemIndex + itemPageArray.indexOfObject(replacingItem);
                reorderedList.replaceObjectAtIndex(replacingItem, replacedItemIndex);
                reorderedList.replaceObjectAtIndex(replacedItem, replacingItemIndex);
            }
        } else {
            reorderedList.addObject(replacingItem);
        }
    }
    // If we're just looking at a page, add all the objects AFTER the page
    if (!mutableList) {
        int listCount = list.count();
        for (int i = startIndex + reorderedList.count(); i < listCount; i++) {
            reorderedList.addObject(list.objectAtIndex(i));
        }
        setValueForBinding(reorderedList, "list");
    }
    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 : NSRange(com.webobjects.foundation.NSRange) WOActionResults(com.webobjects.appserver.WOActionResults) NSArray(com.webobjects.foundation.NSArray) NoSuchElementException(java.util.NoSuchElementException) NSMutableArray(com.webobjects.foundation.NSMutableArray) NoSuchElementException(java.util.NoSuchElementException)

Example 18 with WOActionResults

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

the class AjaxSubmitButton method invokeAction.

@Override
public WOActionResults invokeAction(WORequest worequest, WOContext wocontext) {
    WOActionResults result = null;
    WOComponent wocomponent = wocontext.component();
    String nameInContext = nameInContext(wocontext, wocomponent);
    boolean shouldHandleRequest = (!disabledInComponent(wocomponent) && wocontext.wasFormSubmitted()) && ((wocontext.isMultipleSubmitForm() && nameInContext.equals(worequest.formValueForKey(KEY_AJAX_SUBMIT_BUTTON_NAME))) || !wocontext.isMultipleSubmitForm());
    if (shouldHandleRequest) {
        String updateContainerID = AjaxUpdateContainer.updateContainerID(this, wocomponent);
        AjaxUpdateContainer.setUpdateContainerID(worequest, updateContainerID);
        wocontext.setActionInvoked(true);
        result = handleRequest(worequest, wocontext);
        ERXAjaxApplication.enableShouldNotStorePage();
    }
    return result;
}
Also used : WOActionResults(com.webobjects.appserver.WOActionResults) WOComponent(com.webobjects.appserver.WOComponent)

Example 19 with WOActionResults

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

the class AjaxModalDialog method handleRequest.

/**
 * Handles the open and close dialog actions.
 *
 * @see er.ajax.AjaxComponent#handleRequest(com.webobjects.appserver.WORequest, com.webobjects.appserver.WOContext)
 *
 * @return null or dialog contents
 */
@Override
public WOActionResults handleRequest(WORequest request, WOContext context) {
    WOActionResults response = null;
    String modalBoxAction = NSPathUtilities.pathExtension(context.senderID());
    if ("close".equals(modalBoxAction)) {
        // This update can't be done in the closeDialog() method as that also gets called from close(WOContext) and
        // and Ajax update is not taking place.  If the page structure changes, this update will not take place,
        // but the correct container ID is on the URL and the update will still happen thanks to the magic in
        // AjaxResponse.AjaxResponseDelegate
        String closeUpdateContainerID = AjaxUpdateContainer.updateContainerID((String) valueForBinding("closeUpdateContainerID"));
        if (closeUpdateContainerID != null) {
            AjaxUpdateContainer.setUpdateContainerID(request, closeUpdateContainerID);
        }
        // This needs to happen AFTER setting up for an update so that AjaxUtils.appendScriptHeaderIfNecessary
        // knows if the script header is needed or not.  Doing this before and setting up a JS response in
        // the onClose callback, resulted in plain text getting injected into the page.
        closeDialog();
    } else if ("open".equals(modalBoxAction) && !isOpen()) {
        openDialog();
        // the awake, takeValues, etc. messages can get passed onto it
        if (hasBinding("action")) {
            _actionResults = (WOComponent) valueForBinding("action");
            _actionResults._awakeInContext(context);
        } else if (hasBinding("pageName")) {
            _actionResults = pageWithName((String) valueForBinding("pageName"));
            _actionResults._awakeInContext(context);
        }
        // wrong and can correct it.
        if (_actionResults != null && (_actionResults.template() instanceof WOForm || _actionResults.template() instanceof ERXWOForm)) {
            throw new RuntimeException(_actionResults.name() + " is used as contents of AjaxModalDialog, but starts with WOForm tag.  " + "Action elements inside the dialog will not function.  Add a space at the start or end of " + _actionResults.name() + ".html");
        }
    }
    if (isOpen()) {
        response = AjaxUtils.createResponse(request, context);
        // Register the id of this component on the page in the request so that when
        // it comes time to cache the context, it knows that this area is an Ajax updating area
        AjaxUtils.setPageReplacementCacheKey(context, _containerID(context));
        if (_actionResults != null) {
            pushActionResultsIntoContext(context);
            try {
                _actionResults.appendToResponse((WOResponse) response, context);
            } finally {
                popActionResultsFromContext(context);
            }
        } else {
            // This loads the content from the default ERWOTemplate (our component contents that are not
            // in the "link" template.
            super.appendToResponse((WOResponse) response, context);
        }
    }
    return response;
}
Also used : ERXWOForm(er.extensions.components._private.ERXWOForm) WOActionResults(com.webobjects.appserver.WOActionResults) WOComponent(com.webobjects.appserver.WOComponent) WOForm(com.webobjects.appserver._private.WOForm) ERXWOForm(er.extensions.components._private.ERXWOForm)

Example 20 with WOActionResults

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

the class AjaxObserveField method invokeAction.

@Override
public WOActionResults invokeAction(WORequest request, WOContext context) {
    WOActionResults result = null;
    WOComponent component = context.component();
    String nameInContext = nameInContext(context, component, this);
    boolean shouldHandleRequest = !context.wasActionInvoked() && context.wasFormSubmitted() && nameInContext.equals(ERXAjaxApplication.ajaxSubmitButtonName(request));
    if (shouldHandleRequest) {
        String updateContainerID = AjaxUpdateContainer.updateContainerID(this, component);
        AjaxUpdateContainer.setUpdateContainerID(request, updateContainerID);
        context.setActionInvoked(true);
        result = (WOActionResults) valueForBinding("action", component);
        if (result == null) {
            result = handleRequest(request, context);
        }
        ERXAjaxApplication.enableShouldNotStorePage();
    } else {
        result = invokeChildrenAction(request, context);
    }
    return result;
}
Also used : WOActionResults(com.webobjects.appserver.WOActionResults) WOComponent(com.webobjects.appserver.WOComponent)

Aggregations

WOActionResults (com.webobjects.appserver.WOActionResults)31 WOComponent (com.webobjects.appserver.WOComponent)11 WOResponse (com.webobjects.appserver.WOResponse)6 WOElement (com.webobjects.appserver.WOElement)2 WOApplication (com.webobjects.appserver.WOApplication)1 WOContext (com.webobjects.appserver.WOContext)1 WORequest (com.webobjects.appserver.WORequest)1 WOForm (com.webobjects.appserver._private.WOForm)1 WONoContentElement (com.webobjects.appserver._private.WONoContentElement)1 NSArray (com.webobjects.foundation.NSArray)1 NSData (com.webobjects.foundation.NSData)1 NSMutableArray (com.webobjects.foundation.NSMutableArray)1 NSMutableDictionary (com.webobjects.foundation.NSMutableDictionary)1 NSRange (com.webobjects.foundation.NSRange)1 ERXWOContext (er.extensions.appserver.ERXWOContext)1 ERXWOForm (er.extensions.components._private.ERXWOForm)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1