Hi, 

I am trying to get Velocity to work as the template engine for 
http://melati.org/ which uses WebMacro by default.

I have run up against problems as it seems that 
InvalidReferenceEventHandler.invalidMethod is 
invoked when a method returns null. 

I have ended up working around it with the most horrific hack 
(which ignores method signatures) : 

  public Object invalidMethod(Context context, String reference, 
                                         Object object, String method, 
                                          Info info) {
    if(object != null) { 
      Method[] methods = object.getClass().getMethods();
      for (int i = 0; i < methods.length; i++)
        if (methods[i].getName().equals(method)) 
          return null;
    }
    String message = "Invalid method ";
    message += (method == null) ? "(null)" : method;
    message += " called ";
    message += (reference == null) ? "(null reference)" : reference;
    message += (object == null) ? " (null object)" : " on object " + object;
    message += " at " + info;
    throw new TemplateEngineException(message);
  }

The javadoc states: 
     * Called when object is null or the given method does not exist.
     * invalidMethod() will be called in sequence for each link in 
     * the chain until the first non-null value is returned. 

but in fact it is called when object is not null, when the method is valid 
but the return value of the method call is null.


It maybe that I am not using idiomatic VTL

#if( !$field.getRaw() )
 #if( $c )
  // ($field.getName() = null)
 #end
#end

what is the normal way to tackle this?

thanks in advance
TimP


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to