0

I'm trying to get Spring project to work with jsf views, I followed http://www.beyondjava.net/blog/jsf-2-2-primefaces-5-spring-boot/

but for some reason, my root controller is returning raw text instead of the page. basically the views aren't loading.

@SpringBootApplication
public class MySpringAppApplication extends SpringBootServletInitializer {
    private static final Logger logger = LoggerFactory.getLogger(MySpringAppApplication.class);

    public static void main(String[] args)  {
         SpringApplication.run(MySpringAppApplication.class, args);
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(MySpringAppApplication.class, JsfInitializer.class);
    }

    // servlet to run jsf stuff
    @Bean
    public ServletRegistrationBean servletRegistrationBean() {
        FacesServlet servlet = new FacesServlet();
        ServletRegistrationBean servletRegistrationBean = new  ServletRegistrationBean(servlet, "*.jsf");

        return servletRegistrationBean;
    }

}

and in my root controller, return "index" just returns that string

@RestController
public class RootController {
    private MailSender mailSender;

    @Autowired
    RootController(MailSender mailSender) {
        this.mailSender = mailSender;
    }

    // @ResponseBody --not needed with @RestController
    @RequestMapping("/")
    public String home() throws MessagingException {

    //  mailSender.send("franklin@gmail.com", "programming", "how are you on that project?");
        return "index";
    }

}

index.xhtml in in the WebContent dir





public class JsfInitializer implements ServletContextInitializer{

    @Override
    public void onStartup(ServletContext servletContext) throws ServletException {
        servletContext.setInitParameter("primefaces.CLIENT_SIDE_VALIDATION", "true");
        servletContext.setInitParameter("javax.faces.PROJECT_STAGE", "Development");

    }

}

and in faces.config:

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

no web.xml file

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
franklinexpress
  • 1,149
  • 14
  • 44
  • Spring Boot != Spring MVC. Spring IoC != Spring MVC. Yet you're trying to throw Spring MVC in the very same box too. This makes no sense when using JSF. Choose one or other. – BalusC Jun 10 '15 at 20:47
  • Instead of `@RestController` use `@Controller`. – M. Deinum Jun 11 '15 at 06:05

0 Answers0