Re: Practical WO Book Demos

From: Kieran Kelleher (kieran_list..ac.com)
Date: Wed Oct 24 2007 - 13:21:18 EDT

  • Next message: David Scheck (JIRA): "[OS-JIRA] Created: (WOL-620) Should match selection between Preview and Component view"

    Just copy/paste this code below into your Application class and
    assuming your Session class is in the same package as your
    Application class, this will solve the WebObjects bad implementation
    for identifying the Session class

            private Class _ourSessionClass;

            /* (non-Javadoc)
             *..ee com.webobjects.appserver.WOApplication#_sessionClass()
             * WebObjects searches the classpath and uses the first class it
    finds with
             * the name Session ... crazy huh? This ensures that Session from
    the same package as the
             * Application class is used
             */
    ..verride
            protected Class _sessionClass()
            {
                    if (_ourSessionClass == null) {
                            String ourSessionClassName = null;
                            try {
                                    ourSessionClassName = getClass().getPackage().getName() +
    ".Session";
                                    System.out.println("Using " + ourSessionClassName + " as the
    application's Session class.");
                                    _ourSessionClass = Class.forName( ourSessionClassName );
                            } catch ( Exception e ) {
                                    System.err.println( "What have you done with your " +
    ourSessionClassName + " class?!\n" + e.getStackTrace() );
                            }
                    } //~ if (_ourSessionClass == null)
                    return _ourSessionClass;
            }

    HTH, Kieran

    On Oct 24, 2007, at 12:51 PM, Chuck Hill wrote:

    > It sounds like you may have a classpath issue and that the Session
    > class getting loaded is something like java.mail.Session instead of
    > the Session class in this project.
    >
    > Try adding this to the constructor in Main:
    >
    > NSLog.out.appendln("Session class is " + session().getClass
    > ().getName());
    >
    > Chuck
    >
    >
    > On Oct 3, 2007, at 9:02 AM, Fred Shurtleff wrote:
    >
    >> Thanks for your suggestions, but unfortunately, deleting unused
    >> projects did NOT have any effect. I deleted all projects EXCEPT
    >> PracticalUtilities, EOJDBCPrototypes, and PWOExampleApp, which are
    >> all companion apps specified in the PWO Book setup instructions.
    >> And furthermore, I checked each of these projects and there is no
    >> Session.java file - so this leaves only 1 Session file in all of
    >> Eclipse - that being in the Chap4App project.
    >>
    >> Regards the bindings tip, I do NOT see a proper validation
    >> performed in this case - Main.wod. I actually changed the binding
    >> > condition = session.isUserAuthenticated; to an erroneous method
    >> (isUserAuthenticatedX) and changed the title in the HTML file to
    >> trigger a re-validation, but this validated OK - there was no red
    >> X indicating a problem.
    >>
    >> And as previously mentioned, I changed the session syntax to
    >> Session(with a capital S), but this triggered an error re no
    >> 'Session' class found. So I interpret this to mean that it is
    >> finding the session class, but for some reason cannot find any of
    >> the class methods (ie. generates an NSKeyValueCoding exception >
    >> UnknownKeyException > lookup for unknown key: isUserAuthenticated).
    >>
    >> This is very puzzling in that something about this particular
    >> project fails, whereas the other demos run/build Ok.
    >>
    >> Fred
    >>
    >> D Tim Cummings wrote:
    >>> On 29/09/2007, at 7:59 AM, Fred Shurtleff wrote:
    >>>
    >>>> Actually each chapter is a separate project which gets imported
    >>>> into Eclipse, and, of course, contains only 1 Session class.
    >>>> Furthermore I have not made ANY change to the project files ie.
    >>>> Main or Session.java, nor the Main.wod files. I simple want to
    >>>> demo their technique of managing security using a few methods in
    >>>> the session class to control access to various public/secure
    >>>> areas in the application.
    >>>>
    >>> I find sometimes if I have several projects open in eclipse, WO
    >>> Component Editor validates against the wrong Session or
    >>> Application class. Closing the unused projects fixes the problem.
    >>>
    >>>> WOComponentEditor does not complain about the bindings - that is
    >>>> there are no red X's or other symbols indicating a problem.
    >>>> Matter of fact, I did change the binding to
    >>>> 'Session.isUserAuthenticated'(with a capital S since WOLips does
    >>>> create a default Session.java file), and when I ran the app it
    >>>> did complain that there was no 'Session' class. So I interpret
    >>>> this to mean the session class is referenced Ok, but none of the
    >>>> session class methods or variables are accessible. But I can't
    >>>> see why!
    >>>>
    >>>
    >>> You need to make a small change, eg add a space to the html, to
    >>> the WOComponent and save it to trigger WO Component Editor to
    >>> revalidate the bindings.
    >>>
    >>> Session.isUserAuthenticated will be looking first for a method in
    >>> your component called Session() or getSession() which won't work
    >>>
    >>> session.isUserAuthenticated will be looking first for a method
    >>> session() which exists in WOComponent which your component
    >>> extends. WOComponentEditor must do some funky stuff to determine
    >>> that session() returns an object of type Session rather than type
    >>> WOSession to complete the validation.
    >>>
    >>> Tim
    >>>
    >>>> I am totally stumped on this one.
    >>>>
    >>>> Jean Pierre Malrieu wrote:
    >>>>> My guess is that there are several "Session" classes
    >>>>> corresponding to different chapters in the book, and that
    >>>>> somehow, you are using the wrong "Session" (from a previous
    >>>>> chapter?) which does not have the required variables and
    >>>>> functions.
    >>>>> What does WOComponentEditor say about the bindings? Does it
    >>>>> complain?
    >>>>>
    >>>>> jpm
    >>>>>
    >>>>>
    >>>>>
    >>>>> Le 28 sept. 07 à 19:56, Fred Shurtleff a écrit :
    >>>>>
    >>>>>> Yes - this is the conditional causing the exception. So I
    >>>>>> changed the condition = true (to get around this problem), and
    >>>>>> then another 'unknown key' exception is triggered:
    >>>>>> authenticatedUser is unknown(but is in fact a public method in
    >>>>>> session.java).
    >>>>>>
    >>>>>> So for some reason none of the bindings on Main.wod using
    >>>>>> session PUBLIC methods/vars are recognizable eg. they trigger
    >>>>>> exception errors. Can anyone see what might be the problem here?
    >>>>>>
    >>>>>> Jean Pierre Malrieu wrote:
    >>>>>>> Without taking a look at the book, or the code, so just a
    >>>>>>> guess: Did you try changing the wod to
    >>>>>>>
    >>>>>>> Conditional: WOConditional {
    >>>>>>> condition = session.isUserAuthenticated;
    >>>>>>> }
    >>>>>>>
    >>>>>>> ?
    >>>>>>>
    >>>>>>>
    >>>>>>> jpm
    >>>>>>>
    >>>>>>> Le 27 sept. 07 à 21:49, Fred Shurtleff a écrit :
    >>>>>>>
    >>>>>>>> Has anyone been able to run the Chapter4App demo from the
    >>>>>>>> Practical WebObjects Book by Hill & Mallais?
    >>>>>>>>
    >>>>>>>> I am unable to get this project to run - it raises an
    >>>>>>>> Exception > An instance variable or method of the name
    >>>>>>>> 'isUserAuthenticated' is not found(this is a WOConditional
    >>>>>>>> binding on the Main page). But 'isUserAuthenticated' is, in
    >>>>>>>> fact, a method in Session.java. So I am now at a dead end.
    >>>>>>>>
    >>>>>>>> Thanks for any ideas or suggestions.
    >>>>>>>>
    >>>>>>>>
    >>>>>>>
    >>>>>>>
    >>>>>>>
    >>>>>>
    >>>>>>
    >>>>>>
    >>>>>
    >>>>>
    >>>>>
    >>>>
    >>>>
    >>>>
    >>>
    >>>
    >>>
    >>
    >>
    >>
    >
    > --
    >
    > Practical WebObjects - for developers who want to increase their
    > overall knowledge of WebObjects or who are trying to solve specific
    > problems.
    > http://www.global-village.net/products/practical_webobjects
    >
    >
    >
    >
    >



    This archive was generated by hypermail 2.0.0 : Wed Oct 24 2007 - 13:22:53 EDT