掲示板

Usage of @Inject or @EJB within AssetRendererFactory

9年前 に Martin Jonik によって更新されました。

Usage of @Inject or @EJB within AssetRendererFactory

Junior Member 投稿: 69 参加年月日: 12/08/14 最新の投稿
Hi all.

I developed a custom JSF Portlet and now I want to make use of Liferays Kaleo Worklflow Engine.
I added my own AssetRendererFactory and my own WorkflowHandler to liferay-portlet.xml.

The problem is I cannot use my own Services from these classes. Neither EJB nor CDI works.
Any hints?

public class CustomAssetRendererFactory extends BasesAssetRendererFactory {

@EJB
private CustomService ejbService;

@Inject
private CustomService cdiService;

}
thumbnail
9年前 に Juan Gonzalez によって更新されました。

RE: Usage of @Inject or @EJB within AssetRendererFactory

Liferay Legend 投稿: 3089 参加年月日: 08/10/28 最新の投稿
Hi Martin,

did you try reading this Wiki entry about developing CDI portlets?

https://www.liferay.com/community/wiki/-/wiki/Main/Developing+JSF+Portlets+with+CDI
thumbnail
9年前 に Neil Griffin によって更新されました。

RE: Usage of @Inject or @EJB within AssetRendererFactory (回答)

Liferay Legend 投稿: 2655 参加年月日: 05/07/27 最新の投稿
Also, please refer to my comment about CDIBeanManagerUtil in the thread titled CDI injection in 6.2 CE Tomcat.
9年前 に Martin Jonik によって更新されました。

RE: Usage of @Inject or @EJB within AssetRendererFactory

Junior Member 投稿: 69 参加年月日: 12/08/14 最新の投稿
Thank you, Neil. Works brilliant after I wrapped the EJB into a CDI bean.
It is also possible to make a normal InitialContext().lookup() call but anyway it would be nice to make use of all the annotations.
thumbnail
9年前 に Neil Griffin によって更新されました。

RE: Usage of @Inject or @EJB within AssetRendererFactory

Liferay Legend 投稿: 2655 参加年月日: 05/07/27 最新の投稿
Hi Martin,

When you get a chance, could you provide updated code that shows how you wrapped the EJB into a CDI bean? I would be interested to see that.

Thank you,

Neil
9年前 に Martin Jonik によって更新されました。

RE: Usage of @Inject or @EJB within AssetRendererFactory

Junior Member 投稿: 69 参加年月日: 12/08/14 最新の投稿
it's nothing special. just that way:


@ApplicationScoped
public class CustomCdiBean {

@EJB
private CustomService;

public CustomService getService() {
return service;
}

}

public class CustomAssetRendererFactory extends BasesAssetRendererFactory {

public void anyMethod() {
 CustomCdiBean bean = CDIBeanManagerUtil.getManagedBeanReference(CustomCdiBean.class);
 CustomService service = bean.getService(); 
}

}



Maybe it would work that way as well...


@Stateless
@Local
@ApplicationScoped
public class CustomService() {

}
thumbnail
9年前 に Neil Griffin によって更新されました。

RE: Usage of @Inject or @EJB within AssetRendererFactory

Liferay Legend 投稿: 2655 参加年月日: 05/07/27 最新の投稿
Hi Martin,

Thanks for posting the code.

Kind Regards,

Neil