Home > other >  in xhtml page jsf attribute are not rendering
in xhtml page jsf attribute are not rendering

Time:02-21

how to render xhtml page , in springboot...,where should i put xhtml fileproject structure

this is my project structure..what url should i hit for getting xhtml file. how to call xhtml page this is my xhtml page

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"
    xmlns:f="http://xmlns.jcp.org/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
    xmlns:p="http://primefaces.org/ui">
<body>
    <form>
        <p:panel header="Login Page">
            <h:outputText value="id" />
            <h:inputText id="id" value="#{a.id}" required="true"></h:inputText>
            <h:message for="id" style="color:blue"></h:message>
            <br></br>
            <br></br>

            <h:outputText value="name" />
            <h:inputText id="name" value="#{a.name}" required="true"></h:inputText>
            <h:message for="name" style="color:blue"></h:message>
            <p:commandButton
                action="#{a.validate()}"
                value="login"></p:commandButton>
        </p:panel>
        <br></br>
        <br></br>
    </form>
</body>
</html>

even http:localhost:8080/hello url does not render and give index page

package login.example;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@Controller
@ComponentScan
public class UserController {

    @RequestMapping("/hello")
    @ResponseBody
    public String sayhii() {
        return "index";
    }

    @Autowired
    UserService userService;
    
    @GetMapping("login-register/index")
    public String index() {
        return "index";
    }
    
    
    @GetMapping("/users")
    public List<User> getAllUsers() {
        return userService.getAllUsers();
    }

    @GetMapping("/user/{id}")
    private User getUser(@PathVariable("id") long id) {
        return userService.getUserById(id);
    }

    @DeleteMapping("/user/{id}")
    public void deleteUser(@PathVariable("id") long id) {
        userService.delete(id);
    }

    @PostMapping("/users")
    public long saveUser(@RequestBody User user) {
        userService.saveOrUpdate(user);
        return user.getId();
    }

    @PutMapping("/users")
    public User Update(@RequestBody User users) {
        userService.saveOrUpdate(users);
        return users;
    }
}

this is usercontroller class, how to work with this

CodePudding user response:

i have added this in springboot main class

@Bean
    public ServletRegistrationBean servletRegistrationBean() {
        FacesServlet servlet = new FacesServlet();
        return new ServletRegistrationBean(servlet, "*.xhtml");
    }

added this in web.xml

<servlet>
        <servlet-name>facesServlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
         <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>facesServlet</servlet-name>
        <url-pattern>*.xhtml</url-pattern>
    </servlet-mapping>
    <listener>
  <listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
</listener>
     <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <listener>
        <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
    </listener>

    <welcome-file-list>
        <welcome-file>index.xhtml</welcome-file>
                <welcome-file>faces/index.xhtml</welcome-file>
        
    </welcome-file-list>

and this in my index.xhtml file

<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:f="http://xmlns.jcp.org/jsf/core"
      xmlns:p="http://primefaces.org/ui">

now,it is working

and using this url http://localhost:8080/index.xhtml

  • Related