Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Daniel M Scott
Liferay Portal Develppment 5.2 Chapter 7 & 8 - anyone know how to fix t
August 4, 2009 1:56 AM
Answer

Daniel M Scott

Rank: Junior Member

Posts: 51

Join Date: July 7, 2009

Recent Posts

Hi Guys

Im using liferay 5.2.3, eclipse and ms sql and i am using the portal development book by Jonas X Yaun, im new to liferay and JAVA, and i am experiecing the following issue.

I am on chapter 7/8 on pages 258 - Adding Velocity services.

I Created 3 packages in ext-impl/src
com.ext.portal.service
com.ext.portal.service.impl
com.ext.portal.util

Code for com.ext.portal.service

package com.ext.portal.service;
import java.util.List;
import com.liferay.portlet.journal.model.JournalArticle;
import com.liferay.portlet.tags.model.TagsAsset;
public interface ExtVelocityToolService {
public JournalArticle getJournalArticle(String groupId, String articleId);
public String getAssetId(String groupId, String articleId);
public List<JournalArticle> getRecentArticles(String companyId, String groupId, String type, int limit);
public List<TagsAsset> getRelatedArticles(String companyId, String groupId, String articleId, int limit);
}

Code for com.ext.portal.service.impl

package com.ext.portal.service.impl;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.OrderByComparator;
import com.liferay.portal.util.PortalUtil;
import com.liferay.portlet.journal.model.JournalArticle;
import com.liferay.portlet.journal.service.JournalArticleLocalServiceUtil;
import com.liferay.portlet.journal.service.JournalArticleResourceLocalServiceUtil;
import com.liferay.portlet.journal.util.comparator.ArticleDisplayDateComparator;
import com.liferay.portlet.journal.util.comparator.ArticleModifiedDateComparator;
import com.liferay.portlet.tags.model.TagsAsset;
import com.liferay.portlet.tags.service.TagsAssetLocalServiceUtil;
import com.liferay.portlet.tags.service.TagsEntryLocalServiceUtil;
public class ExtVelocityToolServiceImpl {
public String getAssetId(String groupId, String articleId) { String assetId = "";

try{
JournalArticle journalArticle = JournalArticleLocalServiceUtil.getArticle(new Long(groupId), articleId);
TagsAsset asset = TagsAssetLocalServiceUtil.getAsset(JournalArticle.class.getName(),
journalArticle.getResourcePrimKey());
assetId = String.valueOf(asset.getAssetId());
}
catch (Exception e){ return assetId; }
return assetId;
}
public JournalArticle getJournalArticle(String groupId, String articleId) {
JournalArticle journalArticle = null;
try{
journalArticle = JournalArticleLocalServiceUtil.getArticle(new Long(groupId).longValue(), articleId);
}
catch (Exception e){ return journalArticle; }
return journalArticle;
}
}

Code for com.ext.portal.util

package com.ext.portal.util;
import java.util.List;
import com.ext.portal.service.ExtVelocityToolService;
import com.liferay.portlet.journal.model.JournalArticle;
import com.liferay.portlet.tags.model.TagsAsset;
public class ExtVelocityToolUtil {

public String getAssetId(String groupId, String articleId){return _extVelocityToolService.getAssetId(groupId, articleId);}
public JournalArticle getJournalArticle(String groupId,String articleId){return _extVelocityToolService.getJournalArticle(groupId,articleId);}
public static ExtVelocityToolService getExtVelocityToolService(){return _extVelocityToolService;}
public void setExtVelocityToolService(ExtVelocityToolService extVelocityToolService){_extVelocityToolService = extVelocityToolService;}
private static ExtVelocityToolService _extVelocityToolService;
public List<JournalArticle> getRecentArticles(String companyId, String groupId, String articleId, int limit){
return _extVelocityToolService.getRecentArticles(companyId, groupId, articleId, limit);}

public List<TagsAsset> getRelatedArticles(String companyId, String groupId, String articleId, int limit){
return _extVelocityToolService.getRelatedArticles(companyId, groupId, articleId, limit); }
}

I then added this code to ext-spring.xml

<bean id="com.ext.portal.service.ExtVelocityToolService"
class="com.ext.portal.service.impl.ExtVelocityToolServiceImpl" />
<bean id="com.ext.portal.util.ExtVelocityToolUtil"
class="com.ext.portal.util.ExtVelocityToolUtil">
<property name="extVelocityToolService"
ref="com.ext.portal.service.ExtVelocityToolService" />
</bean>
<bean id="com.ext.portal.util.ExtVelocityToolUtil.velocity"
class="org.springframework.aop.framework.ProxyFactoryBean"
parent="baseVelocityUtil">
<property name="target"
ref="com.ext.portal.service.ExtVelocityToolService" />
</bean>

But when i run tomcat i get this error.
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.ext.portal.util.ExtVelocityToolUtil' defined in class path resource [META-INF/ext-spring.xml]: Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type [com.ext.portal.service.impl.ExtVelocityToolServiceImpl] to required type [com.ext.portal.service.ExtVelocityToolService] for property 'extVelocityToolService'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [com.ext.portal.service.impl.ExtVelocityToolServiceImpl] to required type [com.ext.portal.service.ExtVelocityToolService] for property 'extVelocityToolService': no matching editors or conversion strategy found at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:480) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)

I dont know how to fix this as i lack the experience, does anyone know why this is happening.

I have also attached a screen shot of the expanded package explorer so you can see the class/interfaces. that i created as per the books instructions.

Any help would be greatly appreciated,

Thanks in advance

Dan
Attachment

Attachments: Untitled-1.gif (12.8k)
Tomas Polesovsky
RE: Liferay Portal Develppment 5.2 Chapter 7 & 8 - anyone know how to f
August 4, 2009 4:52 AM
Answer

Tomas Polesovsky

LIFERAY STAFF

Rank: Liferay Master

Posts: 641

Join Date: February 13, 2009

Recent Posts

Hi,

I noticed that your ExtVelocityToolServiceImpl doesn't implement ExtVelocityToolService. I suppose that is should.

-- tom
Daniel M Scott
RE: Liferay Portal Develppment 5.2 Chapter 7 & 8 - anyone know how to f
August 4, 2009 5:31 AM
Answer

Daniel M Scott

Rank: Junior Member

Posts: 51

Join Date: July 7, 2009

Recent Posts

Hi tom

Thanks for the reply, could you elaborate a little more please, as i have limited understanding of JAVA and liferay - how do i get ExtVelocityToolServiceImpl to implement ExtVelocityToolService . From my understanding from the book, this was done by hooking up all 3 via the ext-spring.xml using this code below

<bean id="com.ext.portal.service.ExtVelocityToolService"
class="com.ext.portal.service.impl.ExtVelocityToolServiceImpl" />
<bean id="com.ext.portal.util.ExtVelocityToolUtil"
class="com.ext.portal.util.ExtVelocityToolUtil">
<property name="extVelocityToolService"
ref="com.ext.portal.service.ExtVelocityToolService" />
</bean>
<bean id="com.ext.portal.util.ExtVelocityToolUtil.velocity"
class="org.springframework.aop.framework.ProxyFactoryBean"
parent="baseVelocityUtil">
<property name="target"
ref="com.ext.portal.service.ExtVelocityToolService" />
</bean>

Any help, much appecriated,

thanks

dan
Tomas Polesovsky
RE: Liferay Portal Develppment 5.2 Chapter 7 & 8 - anyone know how to f
August 4, 2009 5:45 AM
Answer

Tomas Polesovsky

LIFERAY STAFF

Rank: Liferay Master

Posts: 641

Join Date: February 13, 2009

Recent Posts

The problem is that Spring is trying to associate property extVelocityToolService (which is type of ExtVelocityToolService) with instance of your class ExtVelocityToolServiceImpl. Although Spring is very clever, in this case it doesn't know, how to bind ExtVelocityToolServiceImpl to extVelocityToolService.

The simplest way (the most usual) is that ExtVelocityToolServiceImpl class implements your ExtVelocityToolService.

In the ExtVelocityToolServiceImpl.java's code you can write:
1
2...
3public class ExtVelocityToolServiceImpl implements ExtVelocityToolService {
4...


And that's it emoticon

-- tom
Daniel M Scott
RE: Liferay Portal Develppment 5.2 Chapter 7 & 8 - anyone know how to f
August 4, 2009 6:20 AM
Answer

Daniel M Scott

Rank: Junior Member

Posts: 51

Join Date: July 7, 2009

Recent Posts

Hi Tom

Your a genius that solved my problem and tomcat now starts with no issues thanks for the help you saved me pulling more of my hair out in frustration emoticon

Thanks

Dan
Tomas Polesovsky
RE: Liferay Portal Develppment 5.2 Chapter 7 & 8 - anyone know how to f
August 4, 2009 8:15 AM
Answer

Tomas Polesovsky

LIFERAY STAFF

Rank: Liferay Master

Posts: 641

Join Date: February 13, 2009

Recent Posts

NP ;)

I am glad to save your hair emoticon
maryam maryam masoudy
RE: Liferay Portal Develppment 5.2 Chapter 7 & 8 - anyone know how to f
September 23, 2012 4:51 AM
Answer

maryam maryam masoudy

Rank: Regular Member

Posts: 149

Join Date: October 30, 2011

Recent Posts

hi
i have same problem and read this page but i didnot understand really what shold i do?
i add
#set ($extVelocityToolUtil = $utilLocator.findUtil('com.ext.portal.util.ExtVelocityToolUtil'))
to velocity but my content shows error and do not show anything
how i can use extVelocityToolUtil or ExtVelocityToolServiceImpl
thanks
Tomas Polesovsky
RE: Liferay Portal Develppment 5.2 Chapter 7 & 8 - anyone know how to f
September 27, 2012 6:01 AM
Answer

Tomas Polesovsky

LIFERAY STAFF

Rank: Liferay Master

Posts: 641

Join Date: February 13, 2009

Recent Posts

Hi,

Daniel's class ExtVelocityToolServiceImpl didn't implement ExtVelocityToolService interface. so he had following exception:
java.lang.IllegalArgumentException: Cannot convert value of type [com.ext.portal.service.impl.ExtVelocityToolServiceImpl] to required type [com.ext.portal.service.ExtVelocityToolService]


The solution was to change ExtVelocityToolServiceImpl class definition to implement ExtVelocityToolService interface.

If you have the same exception try to change the class declaration as well.

-- tom +
maryam maryam masoudy
RE: Liferay Portal Develppment 5.2 Chapter 7 & 8 - anyone know how to f
September 29, 2012 11:28 PM
Answer

maryam maryam masoudy

Rank: Regular Member

Posts: 149

Join Date: October 30, 2011

Recent Posts

Hi, Tomáš Polešovský
thank you for reply
could you explain more?
i want to use ExtVelocityToolService in velocity tempalate how can i?
i could use other classs in velocity template but i cannot use ExtVelocityToolService
please help me more
thank you
should i write one implement for ExtVelocityToolService ?
Tomas Polesovsky
RE: Liferay Portal Develppment 5.2 Chapter 7 & 8 - anyone know how to f
October 2, 2012 7:10 AM
Answer

Tomas Polesovsky

LIFERAY STAFF

Rank: Liferay Master

Posts: 641

Join Date: February 13, 2009

Recent Posts

Hi,

you can use ExtVelocityToolService using $serviceLocator.findService("...").

But ExtVelocityToolService is not part of standard Liferay distribution and you can't use it by default. Daniel followed the book and wrote the class by himself and then he got the error.

-- tom +
maryam maryam masoudy
RE: Liferay Portal Develppment 5.2 Chapter 7 & 8 - anyone know how to f
October 2, 2012 11:59 AM
Answer

maryam maryam masoudy

Rank: Regular Member

Posts: 149

Join Date: October 30, 2011

Recent Posts

Hi Tomáš Polešovský
thanks for reply
i think ExtVelocityToolService is for liferay emoticon)))
i have a lot of problem in velocity template can u tell me more i ask my question
http://www.liferay.com/community/forums/-/message_boards/message/16795698