フォーラム

ホーム » Liferay Faces » Liferay Faces - English

構造的に表示 平面上に表示 ツリー上に表示
スレッド [ 前へ | 次へ ]
Alexey Melnikov
el-resolver not working with Spring and RichFaces (myfaces)
2012/11/27 13:08
答え

Alexey Melnikov

ランク: Junior Member

投稿: 98

参加年月日: 2012/03/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 14:03
答え

Neil Griffin

LIFERAY STAFF

ランク: Liferay Legend

投稿: 2097

参加年月日: 2005/07/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 14:18
答え

Alexey Melnikov

ランク: Junior Member

投稿: 98

参加年月日: 2012/03/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 14:36
答え

Neil Griffin

LIFERAY STAFF

ランク: Liferay Legend

投稿: 2097

参加年月日: 2005/07/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 16:03
答え

Alexey Melnikov

ランク: Junior Member

投稿: 98

参加年月日: 2012/03/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 16:10
答え

Neil Griffin

LIFERAY STAFF

ランク: Liferay Legend

投稿: 2097

参加年月日: 2005/07/26

最近の投稿

Hi Alexey,

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

Neil