On 21/11/2007, at 5:57 AM, Fred Shurtleff wrote:

I am having a number of problems with Eclipse not being able to find Variables/Components/Methods, etc sporadically over several projects, and wanted see if others have run into this issue.

Have you tried Project > Clean... 'all'?

For example, one page throws up a dialogue window - 'Buggy key in WoComponent' > Reason: This WOComponent does not have an instance variable of the name testObject or _testObject, nor a method named.... (It also gives a the same message in the console window) But the component java file does in fact contain this var.

I assume testObject is public?
Are any child components also trying to reference testObject?

Another example, I have a link with an action class & directActionName binding (DirectAction & Page1Action), and Eclipse reports: Error: java.lang.NoSuchMethodException: com.webobjects.appserver.WODirectAction.page1Action()
But this action is in fact in the DirectAction class.

Yeah this is a problem with the normal Direct action request handler's class resolving being a bit dumb. It doesn't resolve DirectAction to your.apps.DirectAction class... and so defaults to com.webobjects.appserver.WODirectAction which is your superclass.

The solution for this involves assisting WO in finding /your/ direct action classes by adjusting the request path when needed... similar to how I offered a fix for finding the session class you mentioned below which Keiran had reposted...

So, the way I've gone around this one is to subclass com.webobjects.appserver._private.WODirectActionRequestHandler (or er.extensions.ERXDirectActionRequestHandler... either will do) so now AnyActionClass.withSomeAction resolves to your.app.AnyActionClass etc. Not sure how others are solving this, but this works reliably and is in production apps if that helps.

(perhaps some of this is a candidate for being pushed down into ERXDirectActionRequestHandler)

/**
 * In app constructor do:
 * <code>
* registerRequestHandler( new ISHDirectActionRequestHandler(), directActionRequestHandlerKey() ); * setDefaultRequestHandler( requestHandlerForKey ( directActionRequestHandlerKey() ) ); // optional
 * </code>
 *
 * @author ldeck
 */
public class ISHDirectActionRequestHandler extends ERXDirectActionRequestHandler
{

        /**
         [EMAIL PROTECTED] path -
         *            the request path
         [EMAIL PROTECTED] full package direct action class name and direct 
action.
         */
public static NSArray getDirectActionClassAndNameForPath( NSArray path )
        {
                NSMutableArray adjustedPath;
                String actionClassName;
                
adjustedPath = path == null ? new NSMutableArray() : path.mutableClone(); actionClassName = adjustedPath.count() > 0 ? ( String ) adjustedPath.objectAtIndex( 0 ) : "";
                
                // 1. Do we have a legit actionClass already?
if ( actionClassName.length() > 0 && Character.isUpperCase ( actionClassName.charAt( 0 ) ) )
                {
                        if ( adjustedPath.count() == 1 )
                                adjustedPath.addObject( "default" );
                }
                else if ( "".equals( actionClassName ) )
                {
                        actionClassName = "DirectAction";
                        if ( adjustedPath.count() == 0 )
                                adjustedPath.addObject( actionClassName );
                        else
                                adjustedPath.replaceObjectAtIndex( 
actionClassName, 0 );
                        
                        if ( adjustedPath.count() == 1 )
                                adjustedPath.addObject( "default" );
                }
                else if ( "null".equals( actionClassName ) )
                {
                        actionClassName = "DirectAction";
                        adjustedPath.replaceObjectAtIndex( actionClassName, 0 );
                        if ( adjustedPath.count() == 1 )
                                adjustedPath.addObject( "default" );
                }
                else if ( path.count() == 1 && !modRewriteEnabled() )
                {
                        actionClassName = "DirectAction";
                        adjustedPath.insertObjectAtIndex( actionClassName, 0 );
                }
                else
                {
                        // Snipping custom mod-unrewrite compatibility as this
                        // involves extended action paths that rely on app 
logic.
                        // Come back to me if you want this.
// e.g., could be achieved by creating ERXApplication.erxApplication()._unrewriteURL( ... );
                }

// finally, adjust package of direct action class to your app's package if ( actionClassName.indexOf( '.' ) < 0 && Character.isUpperCase ( actionClassName.charAt( 0 ) ) )
                {
String pkg = WOApplication.application().getClass().getPackage ().getName();
                        adjustedPath.replaceObjectAtIndex( pkg + "." + 
actionClassName, 0 );
                }
                return adjustedPath;
        }
        
        /**
         [EMAIL PROTECTED] path -
         *            the request path
[EMAIL PROTECTED] an array of user friendly action class and action names. i.e., without the package.
         */
        public static NSArray getUserActionClassAndNameForPath( NSArray path )
        {
NSMutableArray fixed = getDirectActionClassAndNameForPath ( path ).mutableClone();
                if ( fixed.count() > 0 )
                {
                        String actionClass = ( String )fixed.objectAtIndex( 0 );
                        int index = actionClass.lastIndexOf( '.' );
                        if ( index >= 0 )
                        {
                                actionClass = actionClass.substring( index + 1 
);
                                fixed.replaceObjectAtIndex( actionClass, 0 );
                        }
                }
                // mod-unwrite snippet follows... (optional)
                if ( fixed.count() > 1 )
                {
String userActionPath = fixed.removeObjectAtIndex( 1 ).toString ().replaceAll( "\\s", "+" ); fixed.addObjectsFromArray( NSArray.componentsSeparatedByString ( userActionPath, ModUnwriteDelimiter ) );
                }
                return fixed;
        }

        public ISHDirectActionRequestHandler()
        {
                super();
        }

public ISHDirectActionRequestHandler( String actionClassName, String defaultActionName, boolean shouldAddToStatistics )
        {
                super( actionClassName, defaultActionName, 
shouldAddToStatistics );
        }

        /**
*Overrides super to adjust the direct action class name to the full class name.
         *
[EMAIL PROTECTED] com.webobjects.appserver._private.WOActionRequestHandler#getRequestActio nClassAndNameForPath(com.webobjects.foundation.NSArray)
         */
        public Object[] getRequestActionClassAndNameForPath( NSArray path )
        {
                NSArray fixedPath = getDirectActionClassAndNameForPath( path );
                return super.getRequestActionClassAndNameForPath( fixedPath );
        }       
}

These errors are a real 'show stopper'- how do you proceed from here?

A while back I ran into a similar problem where the project could not find a variable in the session class(that was in fact there), and Keiran K offered a snippet of code to use the project's session class. But now this problem seems to have plagued other places in the project.

Right. The above is a similar problem where WO doesn't find your classes (now that everyone's using packages these days)... but a little oil, and it's fixed :-)

with regards,
--

Lachlan Deck



_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to