概述
这里主要用两个primefaces官网案例来介绍与SpringBoot的整合
官网:https://www.primefaces.org/
项目结构
Maven依赖
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.primefaces/primefaces -->
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>10.0.0-RC1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.sun.faces/jsf-api -->
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.2.20</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.sun.faces/jsf-impl -->
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.2.20</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.tomcat.embed/tomcat-embed-jasper -->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<version>8.5.20</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.sonatype.sisu/sisu-inject-bean -->
<dependency>
<groupId>org.sonatype.sisu</groupId>
<artifactId>sisu-inject-bean</artifactId>
<version>2.3.0</version>
</dependency>
</dependencies>
chart包中的代码:https://www.primefaces.org/showcase/ui/chartjs/bar/bar.xhtml?jfwid=a6efa
menu包中的代码:https://www.primefaces.org/showcase/ui/data/datatable/contextMenu.xhtml?jfwid=a6efa
InventoryStatus.java
package com.daniel.model.menu;
/**
* @Author Daniel
* @Description 库存状态
**/
public enum InventoryStatus {
INSTOCK("In Stock"),
OUTOFSTOCK("Out of Stock"),
LOWSTOCK("Low Stock");
private String text;
InventoryStatus(String text) {
this.text = text;
}
public String getText() {
return text;
}
}
PrimeFacesApplication.java
package com.daniel;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import javax.faces.webapp.FacesServlet;
import javax.servlet.ServletContext;
import java.util.Collections;
/**
* @Author Daniel
* @Description 启动类,初始化JSF
**/
@SpringBootApplication
public class PrimeFacesApplication {
public static void main(String[] args) {
SpringApplication.run(PrimeFacesApplication.class, args);
}
@Bean
public ServletRegistrationBean<FacesServlet> jsfServletRegistration(ServletContext servletContext) {
// JSF的配置
servletContext.setInitParameter("com.sun.faces.forceLoadConfiguration", Boolean.TRUE.toString());
// 注册FacesServlet
ServletRegistrationBean<FacesServlet> srb = new ServletRegistrationBean<>();
srb.setServlet(new FacesServlet());
srb.setUrlMappings(Collections.singletonList("*.xhtml"));
srb.setLoadOnStartup(1);
return srb;
}
}
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>
<!--SpringBoot整合JSF框架的管理Bean对象 EL表达式-->
<el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
</application>
</faces-config>
效果展示:
http://localhost:8080/bar.xhtml
http://localhost:8080/contextMenu.xhtml
完整项目代码下载
最后
以上就是追寻钢笔为你收集整理的SpringBoot整合PrimeFaces的全部内容,希望文章能够帮你解决SpringBoot整合PrimeFaces所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复