Search code examples
javapropertiesvelocitygetter

Can I access by property names in Velocity?


I got an example

#set($organizationId = $layout.getGroup().getOrganizationId())

can I rewrite it as

#set($organizationId = $layout.group.organizationId)

?

Will it be exactly the same?


Solution

  • Yes. See here: Velocity User Guide - Property Lookup Rules which states:

    As an example, $customer.address, the sequence is

    1. getaddress()
    2. getAddress()
    3. get("address")
    4. isAddress()

    To be more precise, Velocity User Guide - Case Substitution:

    $data.getRequest().getServerName()
    ## is the same as
    $data.Request.ServerName