掲示板

RE: el-resolver not working with Spring and RichFaces (myfaces)

thumbnail
11年前 に Alexey Melnikov によって更新されました。

el-resolver not working with Spring and RichFaces (myfaces)

Regular Member 投稿: 108 参加年月日: 12/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

<faces-config xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemalocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd" version="2.0">

	<application>
		<el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
	</application>
</faces-config>


With spring I'm creating simple service bean:
Injection of bean inside of service is properly work.
@Service("testService")
public class TestServiceImpl implements TestService {

    @Autowired
    private TestBean testBean;
	@Override
	public TestBean getTestBean() {
		return testBean;
	}
	@Override
	public void setTestBean(TestBean testBean {
		this.testBean = testBean;
	}
	@PostConstruct
	private void prepareData(){
		System.out.println("Test service constructed");
	} 
}


In a managed bean, injection not working:

@ManagedBean(name="testCtrl")
@SessionScoped
public class TestController extends javax.portlet.faces.GenericFacesPortlet implements Serializable {
........
	@ManagedProperty("#{testService}")
	private TestService testService; 
........
}


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:
commons-codec-1.3.jar
commons-collections-3.1.jar
commons-collections-3.2.jar
commons-digester-1.8.jar
commons-discovery-0.4.jar
commons-logging-1.1.1.jar
dom4j-1.6.1.jar
javassist-3.12.0.GA.jar
jstl-api-1.2.jar
jstl-impl-1.2.jar
jta-1.1.jar
liferay-faces-bridge-api-3.1.0-ga1.jar
liferay-faces-bridge-impl-3.1.0-ga1.jar
liferay-faces-portal-3.1.0-ga1.jar
liferay-faces-util-3.1.0-ga1.jar
log4j-1.2.16.jar
myfaces-api-2.0.0.jar
myfaces-impl-2.0.0.jar
org.springframework.aop-3.0.5.RELEASE.jar
org.springframework.asm-3.0.5.RELEASE.jar
org.springframework.beans-3.0.5.RELEASE.jar
org.springframework.context-3.0.5.RELEASE.jar
org.springframework.context.support-3.0.5.RELEASE.jar
org.springframework.core-3.0.5.RELEASE.jar
org.springframework.expression-3.0.5.RELEASE.jar
org.springframework.jdbc-3.0.5.RELEASE.jar
org.springframework.orm-3.0.5.RELEASE.jar
org.springframework.transaction-3.0.5.RELEASE.jar
org.springframework.web-3.0.5.RELEASE.jar
richfaces-components-api-4.2.0.Final.jar
richfaces-components-ui-4.2.0.Final.jar
richfaces-core-api-4.2.0.Final.jar
richfaces-core-impl-4.2.0.Final.jar
slf4j-api-1.6.1.jar
slf4j-log4j12-1.6.1.jar
spring-security-config-3.0.3.RELEASE.jar
spring-security-core-3.0.3.RELEASE.jar
spring-security-web-3.0.3.RELEASE.jar

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


Maybe I forgot to configure something else?
thumbnail
11年前 に Neil Griffin によって更新されました。

RE: el-resolver not working with Spring and RichFaces (myfaces)

Liferay Legend 投稿: 2655 参加年月日: 05/07/27 最新の投稿
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?
thumbnail
11年前 に Alexey Melnikov によって更新されました。

RE: el-resolver not working with Spring and RichFaces (myfaces)

Regular Member 投稿: 108 参加年月日: 12/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.
thumbnail
11年前 に Neil Griffin によって更新されました。

RE: el-resolver not working with Spring and RichFaces (myfaces) (回答)

Liferay Legend 投稿: 2655 参加年月日: 05/07/27 最新の投稿
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.
thumbnail
11年前 に Alexey Melnikov によって更新されました。

RE: el-resolver not working with Spring and RichFaces (myfaces)

Regular Member 投稿: 108 参加年月日: 12/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.
thumbnail
11年前 に Neil Griffin によって更新されました。

RE: el-resolver not working with Spring and RichFaces (myfaces)

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

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

Neil