【问题标题】:Primefaces hello worldPrimefaces你好世界
【发布时间】:2015-01-13 02:11:55
【问题描述】:

我正在尝试将 primefaces 集成到我的应用程序中,因此我关注 the primefaces user guide。我没有任何依赖问题,但是在进入指南的第一个示例时,除了空白页之外我什么也没得到。

<!DOCTYPE html>
<html xmlns="http://www.w3c.org/1999/xhtml" xmlns:p="http://primefaces.org/ui"><head id="j_idt2"></head><body>
    <p:editor></p:editor></body>
</html>

根据指南,我希望获得一个富文本编辑器,但没有显示任何内容。在我的html代码下面。你能看出有什么错误吗?

<!DOCTYPE html>
<html xmlns="http://www.w3c.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:p="http://primefaces.org/ui">
<h:head></h:head>
<h:body>
    <p:editor />
</h:body>
</html>

P.E.:我还添加了 primefaces 和 myfaces 作为依赖项to my pom.xml

<dependencies>
    <dependency>
        <groupId>org.primefaces</groupId>
        <artifactId>primefaces</artifactId>
        <version>5.1</version>
    </dependency>
    <dependency>
        <groupId>org.apache.myfaces.core</groupId>
        <artifactId>myfaces-api</artifactId>
        <version>2.2.3</version>
    </dependency>
    <dependency>
        <groupId>org.apache.myfaces.core</groupId>
        <artifactId>myfaces-impl</artifactId>
        <version>2.2.3</version>
    </dependency>
</dependencies>

web.xml 中的配置似乎也不错:

<?xml version="1.0" encoding="UTF-8"?>
<web-app 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-app_3_1.xsd"
         version="3.1">
    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.xhtml</url-pattern>
    </servlet-mapping>
    <context-param>
        <param-name>primefaces.THEME</param-name>
        <param-value>bootstrap</param-value>
    </context-param>
</web-app>

【问题讨论】:

  • 您是否将 primefaces jar 添加到类路径或 pom 中?显示你的 web.xml
  • 尝试使用简单的 PrimeFaces 组件,例如 &lt;p:inputText /&gt;
  • @JaqenH'ghar:是的,我的 pom.xml 中有 primefaces 和 myfaces
  • @Omar 相同的结果 :-( w3c.org/1999/xhtml" xmlns:p="primefaces.org/ui"><head id="j_idt2">

标签: maven jsf jakarta-ee jsf-2 primefaces


【解决方案1】:

根据bootstrap主题需要bootstrap.jar,所以你的pom.xml应该是

<dependencies>
    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-web-api</artifactId>
        <version>6.0</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.primefaces</groupId>
        <artifactId>primefaces</artifactId>
        <version>5.1</version>
    </dependency>
    <dependency>  
        <groupId>org.primefaces.themes</groupId>  
        <artifactId>bootstrap</artifactId>  
        <version>1.0.10</version>  
    </dependency> 
    <dependency>
        <groupId>org.apache.myfaces.core</groupId>
        <artifactId>myfaces-api</artifactId>
        <version>2.2.3</version>
    </dependency>
    <dependency>
        <groupId>org.apache.myfaces.core</groupId>
        <artifactId>myfaces-impl</artifactId>
        <version>2.2.3</version>
    </dependency>
</dependencies>

【讨论】:

  • 感谢您的建议,但这并不能解决这里的主要问题:如果我不手动将这些 jar 添加到 web-inf/lib 中,为什么 primefaces 和引导样式不起作用跨度>
  • @sogeking 每个主题都打包为一个 jar 文件,下载您要使用的主题,将其添加到应用程序的类路径中,然后在部署描述符 (web.xml) 中定义 primefaces.THEME 上下文参数。 xml) 以主题名称作为值。请阅读primefaces.org/themes
  • 谢谢,我已经到了。但是我不明白为什么当我已经在 pom.xml 中有这些 jar 文件时,我需要 web-inf/lib 中的那些 jar 文件......无论如何,它可以工作:-)
  • @sogeking 您确定您的项目是作为 maven 项目创建的吗?基本上,如果你添加到你的 pom 中,你不会在你的 web-inf/lib 中添加任何 jar。
  • 是的,它是作为 maven 项目创建的。所有其他依赖项都是从 pom.xml 导入的,没有问题
【解决方案2】:

你能添加 h:form

<!DOCTYPE html>
<html xmlns="http://www.w3c.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:p="http://primefaces.org/ui">
<h:head></h:head>
<h:body>
<h:form>
    <p:editor />
</h:form>
</h:body>
</html>

【讨论】:

  • 谢谢,但这并没有太大区别。我的最后一个疑问是为什么我需要将 bootstrap.jar 和 primefaces.jar 添加到 web-inf/lib 中,即使我的 pom.xml 中已经有了它们...... :-)