Home » Liferay Portal » English » x. Miscellaneous

Combination View Flat View Tree View
Threads [ Previous | Next ]
vinesh ranjan
how to define custom velocity variable in Journal template for custom class
May 18, 2012 9:27 AM

vinesh ranjan

Rank: New Member

Posts: 4

Join Date: March 25, 2012

Recent Posts


Is there any way to use intialized object (using spring ) of a custom java class in journal velocity template. Scenario is such as;

There is a custom class "". It has one method "m1()" it returns an object. This Class object has been initialized by spring dependency.

There is one more class "" this class set the object of "" in a variable "var1" like below.


abc obj1 = ((WebApplicationContext)WebUtil.getContext(request)).getBean(
Constants.SERVICE_LOCATOR, abc.class);

vars.put("var1", obj1.m1());

Here, WebUtil and getBean are classes used to get context and bean respectively.

After doing above code i am getting null pointer exception on browser using localhost:8080.

After doing R&D i found that "vars.put("var1", obj1.m1());" returns null pointer exception.

Can any one please suggest that how will i fetch the object in "var1" so that i could use it in journal template.