组合视图 统一视图 树状图
讨论主题 [ 上一个 | 下一个 ]
toggle
Alexey Melnikov
el-resolver not working with Spring and RichFaces (myfaces)
2012年11月27日 下午1:08
答复

Alexey Melnikov

等级: Junior Member

帖子: 91

加入日期: 2012年3月27日

最近的帖子

Hello everyone.

I'm trying to make working together spring beans and inject it as managed property to managed bean.

For that in faces-config.xml, I configured el-resolver, for getting spring beans in JSF context

 1<faces-config
 2    xmlns="http://java.sun.com/xml/ns/javaee"
 3    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
 5    version="2.0">
 6
 7    <application>
 8        <el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
 9    </application>
10</faces-config>


With spring I'm creating simple service bean:
Injection of bean inside of service is properly work.
 1@Service("testService")
 2public class TestServiceImpl implements TestService {
 3
 4    @Autowired
 5    private TestBean testBean;
 6    @Override
 7    public TestBean getTestBean() {
 8        return testBean;
 9    }
10    @Override
11    public void setTestBean(TestBean testBean {
12        this.testBean = testBean;
13    }
14    @PostConstruct
15    private void prepareData(){
16        System.out.println("Test service constructed");
17    }
18}


In a managed bean, injection not working:

1@ManagedBean(name="testCtrl")
2@SessionScoped
3public class TestController extends javax.portlet.faces.GenericFacesPortlet implements Serializable {
4........
5    @ManagedProperty("#{testService}")
6    private TestService testService;
7........
8}


Was trying to catch calling of org.springframework.web.jsf.el.SpringBeanFacesELResolver with debugger - no luck.
In a same jsf web application everything works fine.

Runtime Liferay 6.0.6 CE.
libs in portlet:
 1commons-codec-1.3.jar
 2commons-collections-3.1.jar
 3commons-collections-3.2.jar
 4commons-digester-1.8.jar
 5commons-discovery-0.4.jar
 6commons-logging-1.1.1.jar
 7dom4j-1.6.1.jar
 8javassist-3.12.0.GA.jar
 9jstl-api-1.2.jar
10jstl-impl-1.2.jar
11jta-1.1.jar
12liferay-faces-bridge-api-3.1.0-ga1.jar
13liferay-faces-bridge-impl-3.1.0-ga1.jar
14liferay-faces-portal-3.1.0-ga1.jar
15liferay-faces-util-3.1.0-ga1.jar
16log4j-1.2.16.jar
17myfaces-api-2.0.0.jar
18myfaces-impl-2.0.0.jar
19org.springframework.aop-3.0.5.RELEASE.jar
20org.springframework.asm-3.0.5.RELEASE.jar
21org.springframework.beans-3.0.5.RELEASE.jar
22org.springframework.context-3.0.5.RELEASE.jar
23org.springframework.context.support-3.0.5.RELEASE.jar
24org.springframework.core-3.0.5.RELEASE.jar
25org.springframework.expression-3.0.5.RELEASE.jar
26org.springframework.jdbc-3.0.5.RELEASE.jar
27org.springframework.orm-3.0.5.RELEASE.jar
28org.springframework.transaction-3.0.5.RELEASE.jar
29org.springframework.web-3.0.5.RELEASE.jar
30richfaces-components-api-4.2.0.Final.jar
31richfaces-components-ui-4.2.0.Final.jar
32richfaces-core-api-4.2.0.Final.jar
33richfaces-core-impl-4.2.0.Final.jar
34slf4j-api-1.6.1.jar
35slf4j-log4j12-1.6.1.jar
36spring-security-config-3.0.3.RELEASE.jar
37spring-security-core-3.0.3.RELEASE.jar
38spring-security-web-3.0.3.RELEASE.jar

and a little part from plugin-package, seems it is not important:
1    commons-lang.jar,\
2    commons-dbcp.jar,\
3    commons-pool.jar,\
4    aspectj-rt.jar


Maybe I forgot to configure something else?
Neil Griffin
RE: el-resolver not working with Spring and RichFaces (myfaces)
2012年11月27日 下午2:03
答复

Neil Griffin

LIFERAY STAFF

等级: Liferay Legend

帖子: 1986

加入日期: 2005年7月26日

最近的帖子

Do you have a setTestService method in TestController?

Also, I was surprised to see that your TestController (which is a JSF managed-bean) extends GenericFacesPortlet. What requirement are you trying to solve by doing that?
Alexey Melnikov
RE: el-resolver not working with Spring and RichFaces (myfaces)
2012年11月27日 下午2:18
答复

Alexey Melnikov

等级: Junior Member

帖子: 91

加入日期: 2012年3月27日

最近的帖子

Neil Griffin:
Do you have a setTestService method in TestController?

Yes, just ommited that

Neil Griffin:

Also, I was surprised to see that your TestController (which is a JSF managed-bean) extends GenericFacesPortlet. What requirement are you trying to solve by doing that?

This code got me to support and develop further. It overrides method doView and initialize one field. I think it can be moved to @PostConstruct. And if I get working @ManagedProperty, then I'll move this part.
Neil Griffin
RE: el-resolver not working with Spring and RichFaces (myfaces)
2012年11月27日 下午2:36
答复

Neil Griffin

LIFERAY STAFF

等级: Liferay Legend

帖子: 1986

加入日期: 2005年7月26日

最近的帖子

There are definitely some occasions, but it is very rare that developers need to extend GenericFacesPortlet. If you do need to extend it, then it should be a different class than your JSF managed-bean.

Are you sure that all of the appropriate phases of the JSF lifecycle are executing? It might be the case that your form is not validating, and the bean is not getting instantiated. You can use a class like the DebugPhaseListener to make sure.
Alexey Melnikov
RE: el-resolver not working with Spring and RichFaces (myfaces)
2012年11月27日 下午4:03
答复

Alexey Melnikov

等级: Junior Member

帖子: 91

加入日期: 2012年3月27日

最近的帖子

Neil Griffin:
There are definitely some occasions, but it is very rare that developers need to extend GenericFacesPortlet. If you do need to extend it, then it should be a different class than your JSF managed-bean.


Definitely this seems working.
I removed this extend, and moved code from doView, to preRerenderView event handler.

After that I've got error 'Unsupported context type com.liferay.portlet.PortletContextImpl' thrown from some class in richfaces library, with name something like *FileUpload*, lost console output, can't show stacktrace. This thing I fixed by replacing myfaces libs with version myfaces 2.1.9.

Thanks Neil.
Neil Griffin
RE: el-resolver not working with Spring and RichFaces (myfaces)
2012年11月27日 下午4:10
答复

Neil Griffin

LIFERAY STAFF

等级: Liferay Legend

帖子: 1986

加入日期: 2005年7月26日

最近的帖子

Hi Alexey,

Glad to hear that things are working now. Thanks for using Liferay Faces.

Neil