Having used to use velocity, I encountered a problem in Porting previous Turbine-based programs to liferay4.0rc, which had plagued me for many days. Today, I finally completely solved the problem, which is summarized as follows: 1. liferay uses COM. liferay. util. velocity. multipleresourceloader to load VM files. The setting of this loader is in COM. liferay. portal. events. initaction. The system calls the setlisteners () method of multipleresourceloader before setting to add a group of listeners in the system. configuration of the last line of the properties file: COM. liferay. util. velocity. velocityresourcelistener = com. liferay. portal. velocity. servletvelocityresourcelistener,/COM. liferay. portal. velocity. journaltemplatevelocityresourcelistener,/COM. liferay. portal. velocity. defaultvelocityresourcelistener2. to allow the system to find the specified VM file Specify the VM path using the following methods: _ portletcontextname + COM. liferay. util. Velocity. velocityresourcelistener. servlet_separator + vm_path; the name of the Portlet application corresponding to _ portletcontextname, such as CMS and bdsjour. It is worth noting that this name does not include "/"; velocityresourcelistener. the value of servlet_separator is _ servlet_context _. vm_path corresponds to the relative address of the VM file in the Portlet application and must start. For example, the name of a Portlet application is bdsjournal. The VM file to be specified is located in the VM/viewitem directory of the application, and the file name is viewitemtree. the template application address is bdsjournal_servlet_context _/Vm/viewitem/viewitemtree. VM; 3. if you directly use Org. apache. velocity. servlet. the Child class of velocityservlet. That is, you must call a display or edit method of the Portlet before using gettemplate () to ensure that the VM file is located. This is because, in general, multipleresourceloader uses COM. liferay. portal. velocity. servletvelocityresourcelistener is used to load VM files. When loading VM files, this listener finds the corresponding files based on the cached Portlet context, calling a display or editing method of a Portlet ensures that the context of the Portlet is loaded into the cache. 4. question about encoding: If garbled characters appear on the page displayed by velocityservlet because the servlet output character encoding method is incorrect, you only need to override the choosecharacterencoding method of velocityservlet. Example: protected string choosecharacterencoding (httpservletrequest request) {return "UTF-8 ";}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.