我得到“无法解决变量'indexController'”错误。
我的xhtml文件;
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head>
<f:facet name="first">
<meta content='text/html; charset=UTF-8' http-equiv="Content-Type"/>
<title>Title Goes Here</title>
</f:facet>
</h:head>
<h:body>
<h:form>
<p:panel header="Send">
<p:inputText value="Hi"></p:inputText>
<p:commandButton value="Send" id="btnDisplay" actionListener="#{indexController}"/>
</p:panel>
</h:form>
</h:body>
我的控制器;
@Controller("indexController")
@Scope("session")
public class IndexController extends MainController {
private String name;
@Override
public void init() {
//To change body of implemented methods use File | Settings | File Templates.
}
@Override
public void destroy() {
//To change body of implemented methods use File | Settings | File Templates.
}
public void sayHello(String name){
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
我的applicationContext.xhtml文件;
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<context:component-scan base-package="tr.source.controllers"/>
<context:annotation-config/>
</beans>
我的web.xml文件;
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
答案 0 :(得分:0)
你的问题是JSF通过CDI或ManagedBeans解析bean,而不是Spring管理的bean。
解决方案是为Spring beans配置EL名称解析器:
将它放在faces-config.xml
中 <application>
...
<el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
</application>
有关详细信息,请参阅Spring SpringBeanFacesELResolver javadocs。