RE: @RequestScoped JSF Bean exception

Pavle Milić, modified 6 Years ago. New Member Posts: 8 Join Date: 12/9/18 Recent Posts

I tried using  <span style="">javax.enterprise.context.RequestScoped</span> in combination with javax.inject.Named annotation on my backing bean but I get the following exception:

WELD-001303: No active contexts for scope type javax.enterprise.context.RequestScoped

There is no way I can get it to work. It works just fine with javax.faces.view.ViewScoped , but this scope is unnecessary for most of my portlets and is only wasting memory. Could it be that Liferay JSF doesn't support CDI RequestScoped beans at all? I investigated and searched for this info, but couldn't find the answer.

thumbnail
Neil Griffin, modified 6 Years ago. Liferay Legend Posts: 2655 Join Date: 7/27/05 Recent Posts

Hi Pavle,

I'm the developer that is working on integration of CDI scopes within Liferay's portlet container implementation. What version of Liferay Portal are you using? Also, do you have WEB-INF/weld-servlet.jar embedded in your JSF portlet WAR?

Thanks,

Neil

Pavle Milić, modified 6 Years ago. New Member Posts: 8 Join Date: 12/9/18 Recent Posts
Hi Neil,
thank you for replying and sorry for my late reply. I still have this problem.
I'm using Liferay v7.1, and yes, I do have weld-servlet dependency jar inside my generated.war/WEB-INF/lib. The maven dependency:

<dependency>
	<groupid>org.jboss.weld.servlet</groupid>
	<artifactid>weld-servlet</artifactid>
	<version>2.3.3.Final</version>
</dependency>

Could it be the version, or do I need some additional configuration to make it work?
Abraham Duffidall, modified 6 Years ago. New Member Posts: 4 Join Date: 6/19/14 Recent Posts
Hi Pavle,

I got the same error, because I forgot to set the appropriate config in web.xml.
However ViewScoped beans were still working....

    <filter>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<filter-name>WeldCrossContextFilter</filter-name>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<filter-class>org.jboss.weld.servlet.WeldCrossContextFilter</filter-class>
&nbsp;&nbsp; &nbsp;</filter>
&nbsp;&nbsp; &nbsp;<filter-mapping>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<filter-name>WeldCrossContextFilter</filter-name>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<url-pattern>/*</url-pattern>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<dispatcher>INCLUDE</dispatcher>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<dispatcher>FORWARD</dispatcher>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<dispatcher>ERROR</dispatcher>
&nbsp;&nbsp; &nbsp;</filter-mapping>
&nbsp;&nbsp; &nbsp;<listener>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<listener-class>org.jboss.weld.environment.servlet.Listener</listener-class>
&nbsp;&nbsp; &nbsp;</listener>


Cheers
Abraham
Pavle Milić, modified 6 Years ago. New Member Posts: 8 Join Date: 12/9/18 Recent Posts
Thank you Abraham!

This solved the problem, and now I can use RequestScoped beans. Turns I had this configuration before in web.xml but I deleted it because I was thinking it was not necessary since my ViewScoped beans worked.