我有一个带有Spring框架和primefaces的Java项目。一开始我使用primefaces的主题有一些问题,因为建议的解决方案不起作用(我没有收到错误消息,主题没有显示)。
建议的解决方案是添加以下行:
<dependency>
<groupId>org.primefaces.themes</groupId>
<artifactId>all-themes</artifactId>
<version>1.0.10</version>
</dependency>
<repository>
<id>prime-repo</id>
<name>Prime Repo</name>
<url>http://repository.primefaces.org</url>
</repository>
到pom.xml和:
<context-param>
<param-name>primefaces.THEME</param-name>
<param-value>afterdark</param-value>
</context-param>
到web.xml。我还尝试手动下载主题的.jar文件并将它们添加到类路径中,但这也无效。我找到了以下链接: Combine hardcoded PrimeFaces resources using CombinedResourceHandler解决了我的问题,现在我可以为我的UI添加主题了。但是,由于我将这些行添加到我的代码中,因此模式对话框不再显示。我没有收到任何错误或其他错误,不会像往常一样弹出。 这是解决方案中的代码片段:
package com.example;
import java.io.IOException;
import javax.faces.application.ResourceDependencies;
import javax.faces.application.ResourceDependency;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.render.Renderer;
@ResourceDependencies({
@ResourceDependency(library="primefaces-aristo", name="theme.css"),
@ResourceDependency(library="primefaces", name="primefaces.js"), // Only necessary when at least one validation JS files needs to be included.
@ResourceDependency(library="primefaces", name="validation/validation.js"), // Only necessary when you need <p:clientValidator>.
@ResourceDependency(library="primefaces", name="validation/beanvalidation.js") // Only necessary when you use JSR303 bean validation.
})
public class HeadRenderer extends Renderer {
@Override
public void encodeBegin(FacesContext context, UIComponent component) throws IOException {
context.getResponseWriter().startElement("head", component);
}
@Override
public void encodeChildren(FacesContext context, UIComponent component) throws IOException {
// NOOP.
}
@Override
public void encodeEnd(FacesContext context, UIComponent component) throws IOException {
for (UIComponent resource : context.getViewRoot().getComponentResources(context, "head")) {
resource.encodeAll(context);
}
context.getResponseWriter().endElement("head");
}
}
以及faces-config.xml中的以下内容:
<render-kit>
<renderer>
<component-family>javax.faces.Output</component-family>
<renderer-type>javax.faces.Head</renderer-type>
<renderer-class>com.example.HeadRenderer</renderer-class>
</renderer>