2013-10-20 24 views
0

我得到“无法解决变量'indexController'”错误。从XHTML文件看不到弹簧控制器

我的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

您的问题在于JSF通过CDI或ManagedBeans解析bean,而不是Spring管理的bean。

解决的办法是配置一个EL名解析为春豆:

在faces-config.xml中将这个

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

见春SpringBeanFacesELResolver javadoc,了解更多信息。

+0

我已经把它放在我的faces-config.xml中。 – hellzone