3

I try to have a project with Spring Boot and JSF. I add a servlet mapping like this :

@ComponentScan()
@EnableAutoConfiguration
public class Application {

public static void main(String[] args) {
    SpringApplication app = new SpringApplication(Application.class);
    app.setShowBanner(false);
    app.run(args);
}

@Bean
public ServletRegistrationBean servletRegistrationBean() {
    FacesServlet servlet = new javax.faces.webapp.FacesServlet();
    return new ServletRegistrationBean(servlet, "/faces/*");
}
}

This is my index.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:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">

<h:head>
</h:head>
<h:body>
<h1>Hello World</h1>

<h:form>
    <p><h:outputText value="#{userView.value}"/></p>
</h:form>

</h:body>
</html>

My JSF bean :

@ViewScoped
@ManagedBean(name = "userView")
public class UserView {

private String  value   = "This editor is provided by PrimeFaces";

public UserView() {
    super();
    System.out.println("userView");
}

@PostConstruct
public void init() {
    System.out.println("---------");
}

public String getValue() {
    return value;
}

public void setValue(String value) {
    this.value = value;
}

}

I have added the faces-config.xml :

<?xml version="1.0" encoding="UTF-8"?>
<faces-config xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd"
version="2.2">
<application>
    <el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
</application>
</faces-config>

But spring don't managed my JSF bean, can you help me ?

Thanks

louvelg
  • 31
  • 1
  • 3
  • Your JSF bean is a JSF managed bean not a spring bean. So spring will never manage it. I would map the `FacesServlet` to `*.xhtml`. What is the problem you are experiencing? Please add the imports to the `UserView`. Finally annotate your class with `@Configuration`. – M. Deinum Feb 25 '14 at 19:50
  • You are right, spring will not managed my bean, but my issue is that my is not interpreted, and my userView is not created (my System.out.println are not printed). So my JSF page don't have jsf backing bean. This is my import of userView import javax.annotation.PostConstruct; import javax.faces.bean.ManagedBean; import javax.faces.bean.ViewScoped; – louvelg Feb 26 '14 at 16:02
  • As I mentioned try to map your `FacesServlet` to `*.xhtml` instead of `/faces/*`. Your xhtml pages have to pass through/have to be rendered by the `FacesServlet`. So if you directly access them (and it isn't under `/faces/` it will not be processed but printed as is. – M. Deinum Feb 27 '14 at 07:03
  • And as also mentioned add `@Configuration` to your class, I would expect your current config for your `FacesServlet` to be ignored. – M. Deinum Feb 27 '14 at 08:53

0 Answers0