在xhtml页面中,不呈现jsf属性 [英] in xhtml page jsf attribute are not rendering

查看:35
本文介绍了在xhtml页面中,不呈现jsf属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何渲染xhtml页面,在springboot.中,xhtml文件应该放在哪里

这是我的项目结构..我应该点击哪个url来获取xhtml文件。 如何调用xhtml页面 这是我的xhtml页面

<?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>

即使http:localhost:8080/hello url也不呈现并提供索引页

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;
    }
}
这是userController类, 如何使用此功能

推荐答案

我已将其添加到Sprringboot主类

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

在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>

在我的index.xhtml文件中

<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">

现在,它正在工作

并使用此URLhttp://localhost:8080/index.xhtml

这篇关于在xhtml页面中,不呈现jsf属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆