You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@turbine.apache.org by Johnny Quazar <qu...@bitblaster.com> on 2003/02/01 18:41:12 UTC

Re: migrating to 2.2 - trouble with extended user

Just thought I'd follow up in case somebody else stumbles here. I was 
getting the following error trying to add a new user:

    Error rendering Velocity template: screens/user/FluxUserForm.vm:
    Invocation of method 'getUserId' in  class cc.rnn.nh.om.NhUser
    threw exception class java.lang.NullPointerException : null

This would not have happened if I'd used Integer instead of int for 
my user key. The extend user howto says, in TurbineUserAdapter:

     /**
      * Gets the userId of the user.  This is also the primary key
      * of the TURBINE_USER table.  The return type of Integer is
      * valid only if the javaType for the ExtendedUser table
      * is "object".  If it is "primative", the return type
      * should be changed to int.
      * @return the user id
      */
     public Integer getUserId()
     {
         return new Integer(((NumberKey)getPrimaryKey()).intValue());
     }

So when I got to this point, I just slammed in some code:

     public int getUserId()
     {
        return ((NumberKey)getPrimaryKey()).intValue();
     }

Of course, this fails miserably if getPrimaryKey returns null, as the 
error above indicates. I am not happy with my current code but it 
does work to address this case:

    {
         NumberKey n = new NumberKey( (NumberKey) getPrimaryKey() );

         try {
            String willExceptIfNull = n.toString();
            return n.intValue();
         } catch (java.lang.NullPointerException j) {
            return -1;
         }
     }

I found testing (n == null) wasn't working for some reason. I don't 
know, the whole thing will be moot when my primary key is an object 
and not a primitive. Anyway that's what's up with that error, hope 
this helps if somebody else gets caught with this issue.

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org