JSF 2.2
和Spring Boot 1.2.1
+其嵌入式Tomcat 8.0.5
服务器。此问题中列出的所有其他内容只是为了提供有关我所使用的技术的上下文。更新#2:遵循BalusC的想法,我将示例自定义组件移植到准系统
Servlet 3.1
+JSF 2.2
应用程序中。您可以在Github上找到它的代码。这个简单的案例不会出现我在此描述的问题。在
@FacesComponent
注释工作。这很大程度上意味着问题是由要么造成Spring 4.1.2
或Spring Boot
本身。天色已经晚了,所以明天我将进一步调查。
TL; DR:我想使用@FacesComponent
及其属性来替换foundation-components-html.taglib.xml
和<component>
输入faces-config.xml
我目前使用XML定义在我的项目中使用自定义组件。我最近了解到,JSF 2.2引入了一项功能,该功能完全消除了对XML的需求。我很想使用它,但是当我纯粹使用注释时,JSF将忽略它们。原始标签显示在我的HTML中。
(即<custom:paragraph></custom:paragraph>
)
我已经在Github上托管的我的沙箱中演示了此问题。如果您想对此进行破解,我将在这篇文章的底部解释如何进行。
您所需要做的就是delete foundation-components-html.taglib.xml
,并注释掉>的faces-config.xml
条目,<component
然后运行应用程序以解决此问题。我将其保留为“正常运行”状态,以便任何希望提供帮助的人都可以轻松地,从根本上正确地起点。只需点击http:// localhost:8080
使用的技术:
Spring Boot 1.2.1
通过Mojarra 2.2.6的JSF 2.2
嵌入式Tomcat 8.0.5
注意:请记住,此设置当前有效,但它正在taglib和faces-config条目上运行!我的问题是如何使用中的最新功能删除这些依赖项JSF 2.2
package foundation.components;
import java.io.IOException;
import javax.faces.component.FacesComponent;
import javax.faces.component.UIComponentBase;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
/**
* The Paragraph Component
* @author Seth Ellison
*/
@FacesComponent(value=UIParagraph.COMPONENT_TYPE, createTag=true, tagName="paragraph", namespace="http://www.blah.com/components/html")
public class UIParagraph extends UIComponentBase {
public static final String COMPONENT_TYPE = "foundation.components.Paragraph";
private String value;
private String styleClass;
@Override
public void encodeBegin(final FacesContext facesContext) throws IOException {
// Encode Implementation Omitted for Brevity.
}
@Override
public String getFamily() {
return "blah.components.family";
}
// Getters/Setters...
}
<facelet-taglib version="2.2"
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 http://xmlns.jcp.org/xml/ns/javaee/web-facelettaglibrary_2_2.xsd">
<namespace>http://www.blah.com/components/html</namespace>
<tag>
<tag-name>paragraph</tag-name>
<component>
<component-type>foundation.components.Paragraph</component-type>
</component>
</tag>
</facelet-taglib>
<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 http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd"
version="2.2" metadata-complete="false">
<component>
<component-type>foundation.components.Paragraph</component-type>
<component-class>foundation.components.UIParagraph</component-class>
</component>
</faces-config>
XHTML模板(为清晰起见,将其分解)
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:jsf="http://xmlns.jcp.org/jsf"
xmlns:custom="http://www.blah.com/components/html">
<head jsf:id="head"></head>
<body jsf:id="body">
<custom:paragraph value="This is a template for a simple marketing or informational website. It includes a large callout called a jumbotron and three supporting pieces of content. Use it as a starting point to create something more unique." />
</body>
</html>
如果您想运行此程序,最简单的方法是下载Spring Tool Suite,从Github中获取代码,右键单击该项目,然后将其作为Spring Boot App运行。启动JPA配置时,您会收到连接错误,因为您(可能)未运行本地MySQL服务器。不用担心 完全不需要访问索引页面并查看标签状态。我经常在运行和不运行DB的情况下都运行该应用程序,不会造成不良影响。最后,要使PrettyFaces与Spring Boot配合使用,您必须创建从目标/类到WEB-INF /的符号链接或硬链接-PrettyFaces编码为在WEB-INF / classs或WEB-INF中查找/ lib扫描注释时。
该函数存在于标有@Configuration
和实现的类中ServletContextAware
@Bean
public ServletListenerRegistrationBean<ConfigureListener> jsfConfigureListener() {
return new ServletListenerRegistrationBean<ConfigureListener>(
new ConfigureListener());
}
好吧,我知道是什么引起了问题。
今天早上,我坐下来考虑我Servlet 3.1
的代码的工作版本与残破Spring Boot
版本之间的区别。主要区别在于代码的运行方式。嵌入式服务器与独立服务器。
Spring Boot
的嵌入式Tomcat
服务器就是原因。
当我按照此答案切换沙箱时,一切正常打开,并且我的自定义组件完全脱离@FacesComponent
注释工作!
我认为这与在嵌入式服务器上启动后组织类的方式有关,而与向Pivotal Tomcat服务器的离散部署有关。在这种情况下,JSF的注释扫描器似乎只是忽略注释。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句