Re: Error verbosity increase?

From: Kieran Kelleher (kieran_list..ac.com)
Date: Sat Mar 31 2007 - 23:40:37 EDT

  • Next message: Mike Schrag: "undo/redo"

    Got it.

    I had an auto generated style attribute with a back-ground image url
    and for some eo's I was returning null for an absolute image url when
    no image existed. This combined with the Pierce Wetter's WO on Rails
    direct action url scheme was generating a relative URL for the image
    that was triggering my page DA handler
    http://localhost/cgi-bin/WebObjects/Omega.woa/-52041/wa/Show/null

    on a page with URL
    http://localhost/cgi-bin/WebObjects/Omega.woa/-52041/wa/Show/
    BrowseResorts

    By the way, here is an initial "work in progress" implementation of
    Pierce Wetter's WO on Rails strategy that I am using in a new app I'm
    working on. I like it. If you have secure pages requiring
    authentication, then you need to think of that here too.

    import com.webobjects.appserver.WOActionResults;
    import com.webobjects.appserver.WOComponent;
    import com.webobjects.appserver.WODirectAction;
    import com.webobjects.appserver.WORequest;

    public class Show extends WODirectAction {
            private static final org.apache.log4j.Logger log =
    org.apache.log4j.Logger
                            .getLogger(Show.class);
            /**
             *..aram aRequest
             */
            public Show(WORequest aRequest) {
                    super(aRequest);
                    
            }
            
            
            /**
             *..ee com.webobjects.appserver.WODirectAction#performActionNamed
    (java.lang.String)
             *..verride we override this to actually return pages named 'name'
    instead of the usual
             * behavior of this method which is to determine a action method
    name by adding 'Action'
             * and invoking through reflection
             * Now we can have URLs like
             * /wa/Show/MyPage
             * We also pull all the form values and stuff them into the target
    component
             * assuming it implements the EOKeyValueCodingAdditions interface
             */
            public WOActionResults performActionNamed(String name){
                    WOComponent page = null;
                    
                    if (log.isDebugEnabled())
                            log.debug("name = "
                                            + (name == null ? "a null object" : name.toString()));
                    
                    if (name != null && !name.equals("null")) {
                            // Create the page
                            page = pageWithName(name);
                                                    
                            if (page instanceof RailsBehaviour && request().formValues() !=
    null && request().formValues().count() > 0){
                                    if (log.isDebugEnabled())
                                            log.debug("Pushing formValues = " + request().formValues
    ().toString());
                                    
                                    ((RailsBehaviour)page).takeValuesFromDictionary(request
    ().formValues());
                            }
                    }
                    
                    
                    return page;
            }

    }

    And here is the RailsBehaviour interface:

    import com.webobjects.appserver.WOComponent;
    import com.webobjects.foundation.NSArray;
    import com.webobjects.foundation.NSDictionary;

    /**
    * An interface that WO pages can implement to work with the
    WODirectAction subclass "Show"
    * so that they can have dictionaries of values pushed in using key-
    value coding
    */
    public interface RailsBehaviour {
            
            public void takeValuesFromDictionary(NSDictionary dictionary);
            
            public static class DefaultImplementation{
                    /**
                     *..aram page
                     *..aram dictionary
                     * Iterates through each dictionary element invoking take value for
    key on the target WOComponent
                     */
                    public static void takeValuesFromDictionary(WOComponent page,
    NSDictionary dictionary){
                            final org.apache.log4j.Logger log = org.apache.log4j.Logger
                                            .getLogger(DefaultImplementation.class);

                            if (log.isDebugEnabled())
                                    log.debug("page = " + page.name() + "; dictionary = " + dictionary);
                            
                            for (java.util.Enumeration enumerator = dictionary
                                            .keyEnumerator(); enumerator.hasMoreElements();) {
                                    boolean isSkippingValue = false;
                                    
                                    String key = (String) enumerator.nextElement();
                                    
                                    Object value = dictionary.valueForKey(key);
                                    
                                    // Since WO usually makes an array of values associated with a
    key in request().formValues(), we want to break out and pick the
    first one
                                    if (value instanceof NSArray) {
                                            value = ((NSArray)value).objectAtIndex(0);
                                    }
                                    
                                    // TODO: Convert the value into appropriate type (Integer, etc.)
    using reflection
                                    
                                    // Since we expect oid to be integer, check for that
                                    if(key.equals("oid")){
                                            // Convert to Integer
                                            value = Integer.valueOf(value.toString());
                                    }
                                    
                                    if (key.equals("wosid")) {
                                            isSkippingValue = true;
                                    }
                                    
                                    if (!isSkippingValue) {
                                            page.takeValueForKey(value, key);
                                    }
                                    
                                    
                            }
                    }
            }
    }

    Post about Pierce's method:
    http://homepage.mac.com/kelleherk/iblog/C1216817469/E20060427090217/
    index.html

    On Mar 31, 2007, at 5:24 PM, Mike Schrag wrote:

    > Either you have a malformed URL calling the direct action, or
    > literally something is attempting to call /wa/null (as a result of
    > an error somewhere else). Definitely look on the calling side,
    > though.



    This archive was generated by hypermail 2.0.0 : Sat Mar 31 2007 - 23:40:59 EDT