Passing complex types to NVelocity Plugin

Passing complex types to NVelocity Plugin

This question is answered

Hi, I have a method in my plugin which takes a number of options (postid, category, userid and options of a custom type) like so:

public string GetButton(int postId, string category, int userId, MyOptions myOptions)

{

     return "test";

}

However I don't get anything returned from the method when accessing it from nVelocity:

#set ($myoptions = "%{Name = 'test', ButtonType = 'Link'}")

#set($stringResponse = $myplugin_links_v1.GetButton(5120, 'web', 2100, $myoptions ))

$stringResponse

Any ideas on what I am doing wrong

Thanks

Adam

Verified Answer
  • Here is an example:
     
    public string GetButton(int postId, string category, int userId, IDictionary options)
            {
                MyOptions myOptions = new MyOptions();
     
                if (options["SomeValue"] != null)
                    myOptions.SomeValue = options["SomeValue"].ToString();
     
                //etc...
                return "test";
            }
     
    Patrick Mason
    Development Lead- Extensibility
    o: 214.420.1329
    telligent.com
     
    From: Patrick Mason [mailto:bounce-pmason@communities.telligent.com]
    Sent: Monday, April 23, 2012 4:34 PM
    To: bugsandissues@communities.telligent.com
    Subject: RE: [Bugs and Issues - Telligent Community] Passing complex types to NVelocity Plugin
     
    Velocity and complex types do not work well together.  In fact you really are saying the MyOptions is a Dictionary. 
     
    If you are wrapping a larger call that involves a complex type called MyOptions then you should pass it in as a dictionary and build the MyOptions object from that dictionary in the method(This is how our widget apis translate to the public Apis).  If not, just use a Dictionary instead of an object or if there are only a couple options, individual parameters.
     
     
     
    Patrick Mason
    Development Lead- Extensibility
    o: 214.420.1329
    telligent.com
     
    From: Adam Seabridge [mailto:bounce-aseabridgethebuildingblockscouk@communities.telligent.com]
    Sent: Monday, April 23, 2012 4:25 PM
    To: bugsandissues@communities.telligent.com
    Subject: [Bugs and Issues - Telligent Community] Passing complex types to NVelocity Plugin
     

    Hi, I have a method in my plugin which takes a number of options (postid, category, userid and options of a custom type) like so:

    public string GetButton(int postId, string category, int userId, MyOptions myOptions)

    {

         return "test";

    }

    However I don't get anything returned from the method when accessing it from nVelocity:

    #set ($myoptions = "%{Name = 'test', ButtonType = 'Link'}")

    #set($stringResponse = $myplugin_links_v1.GetButton(5120, 'web', 2100, $myoptions ))

    $stringResponse

    Any ideas on what I am doing wrong

    Thanks

    Adam

All Replies
  • Velocity and complex types do not work well together.  In fact you really are saying the MyOptions is a Dictionary. 
     
    If you are wrapping a larger call that involves a complex type called MyOptions then you should pass it in as a dictionary and build the MyOptions object from that dictionary in the method(This is how our widget apis translate to the public Apis).  If not, just use a Dictionary instead of an object or if there are only a couple options, individual parameters.
     
     
     
    Patrick Mason
    Development Lead- Extensibility
    o: 214.420.1329
    telligent.com
     
    From: Adam Seabridge [mailto:bounce-aseabridgethebuildingblockscouk@communities.telligent.com]
    Sent: Monday, April 23, 2012 4:25 PM
    To: bugsandissues@communities.telligent.com
    Subject: [Bugs and Issues - Telligent Community] Passing complex types to NVelocity Plugin
     

    Hi, I have a method in my plugin which takes a number of options (postid, category, userid and options of a custom type) like so:

    public string GetButton(int postId, string category, int userId, MyOptions myOptions)

    {

         return "test";

    }

    However I don't get anything returned from the method when accessing it from nVelocity:

    #set ($myoptions = "%{Name = 'test', ButtonType = 'Link'}")

    #set($stringResponse = $myplugin_links_v1.GetButton(5120, 'web', 2100, $myoptions ))

    $stringResponse

    Any ideas on what I am doing wrong

    Thanks

    Adam

  • Here is an example:
     
    public string GetButton(int postId, string category, int userId, IDictionary options)
            {
                MyOptions myOptions = new MyOptions();
     
                if (options["SomeValue"] != null)
                    myOptions.SomeValue = options["SomeValue"].ToString();
     
                //etc...
                return "test";
            }
     
    Patrick Mason
    Development Lead- Extensibility
    o: 214.420.1329
    telligent.com
     
    From: Patrick Mason [mailto:bounce-pmason@communities.telligent.com]
    Sent: Monday, April 23, 2012 4:34 PM
    To: bugsandissues@communities.telligent.com
    Subject: RE: [Bugs and Issues - Telligent Community] Passing complex types to NVelocity Plugin
     
    Velocity and complex types do not work well together.  In fact you really are saying the MyOptions is a Dictionary. 
     
    If you are wrapping a larger call that involves a complex type called MyOptions then you should pass it in as a dictionary and build the MyOptions object from that dictionary in the method(This is how our widget apis translate to the public Apis).  If not, just use a Dictionary instead of an object or if there are only a couple options, individual parameters.
     
     
     
    Patrick Mason
    Development Lead- Extensibility
    o: 214.420.1329
    telligent.com
     
    From: Adam Seabridge [mailto:bounce-aseabridgethebuildingblockscouk@communities.telligent.com]
    Sent: Monday, April 23, 2012 4:25 PM
    To: bugsandissues@communities.telligent.com
    Subject: [Bugs and Issues - Telligent Community] Passing complex types to NVelocity Plugin
     

    Hi, I have a method in my plugin which takes a number of options (postid, category, userid and options of a custom type) like so:

    public string GetButton(int postId, string category, int userId, MyOptions myOptions)

    {

         return "test";

    }

    However I don't get anything returned from the method when accessing it from nVelocity:

    #set ($myoptions = "%{Name = 'test', ButtonType = 'Link'}")

    #set($stringResponse = $myplugin_links_v1.GetButton(5120, 'web', 2100, $myoptions ))

    $stringResponse

    Any ideas on what I am doing wrong

    Thanks

    Adam

  • Great, thanks Patrick. I had tried that but got the wrong type of dictionary. Go it all working now.

    thanks

    Adam