0

该应用程序获取我的标签并向我显示页面。但是在视图中,我看不到 CSS 和 JS。这是我的代码:

pom.xml

    <repositories>
        <repository>
            <id>prime-repo</id>
            <name>PrimeFaces Maven Repository</name>
            <url>http://repository.primefaces.org</url>
            <layout>default</layout>
        </repository>
    </repositories>


    <dependencies>
        <!-- JSF -->

        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-web-api</artifactId>
            <version>6.0</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>com.sun.faces</groupId>
            <artifactId>jsf-api</artifactId>
            <version>2.1.13</version>
        </dependency>

        <dependency>
            <groupId>com.sun.faces</groupId>
            <artifactId>jsf-impl</artifactId>
            <version>2.1.13</version>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
        </dependency>

        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.1</version>
        </dependency>

        <!-- PrimeFaces -->
        <dependency>
            <groupId>org.primefaces</groupId>
            <artifactId>primefaces</artifactId>
            <version>3.5</version>
        </dependency>

        <dependency>
            <groupId>org.primefaces.themes</groupId>
            <artifactId>afterdark</artifactId>
            <version>1.0.9</version>
        </dependency>

    </dependencies>
</project>

web.xml

<!-- faces-confg -->
<context-param>
    <param-name>javax.faces.CONFIG_FILES</param-name>
    <param-value>
    WEB-INF/faces-config.xml,
        WEB-INF/manage-beans.xml,
        WEB-INF/navigation-rule.xml
    </param-value>
</context-param>

<context-param>
    <param-name>javax.faces.PROJECT_STAGE</param-name>
    <param-value>Production</param-value>
</context-param>

<!-- JSF THEME -->
<context-param>
    <param-name>primefaces.THEME</param-name>
    <param-value>afterdark</param-value>
</context-param>

<!-- JSF Mapping -->

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

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>WEB-INF/application-context.xml</param-value>
</context-param>

<context-param>
    <description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
    <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
    <param-value>client</param-value>
</context-param>

<context-param>
    <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
    <param-value>resources.application</param-value>
</context-param>

<!-- Servlet de recursos de Primefaces -->
<servlet>
    <servlet-name>Resource Servlet</servlet-name>
    <servlet-class>org.primefaces.resource.ResourceServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>Resource Servlet</servlet-name>
    <url-pattern>/primefaces_resource/*</url-pattern>
</servlet-mapping>

索引.xhtml

    <?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:c="http://java.sun.com/jsp/jstl/core"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.org/ui">


<h:form>
    <f:loadBundle var="text" basename="i18n.applicationResources" />

    <ui:composition template="WEB-INF/xhtml/includes/mainLayout.xhtml">
        <ui:define name="content">
            Leerroo lerro 


<p:panel header="Colors">  
        <h:panelGrid columns="2" cellpadding="10">  
            <h:outputText value="Inline: " />  
            <p:colorPicker id="inlineCP" value="#{colorBean.color1}" mode="inline" />  

            <h:outputText value="Popup: " />  
            <p:colorPicker id="popupCP" value="#{colorBean.color2}" widgetVar="picker"/>  
        </h:panelGrid>
        </ui:define>
    </ui:composition>
</h:form>
</html>
4

1 回答 1

1
  1. 您需要知道<ui:composition/>在页面呈现期间您的标签之外的所有内容都将被忽略。这意味着如果您的模板页面包含在另一个页面中,则不会处理您的<h:form/>and标记。<f:loadBundle/>这会导致您当前的样式表问题:

  2. 从您正在注册的事实来看,您似乎正在使用旧版的 primefaces

     org.primefaces.resource.ResourceServlet
    

    如果是这种情况,您的页面也应该有一个 <h:head/>标签,以允许资源 servlet 在视图中注入必要的样式表和脚本。

因此,将所有这些放在一起,您将拥有:

<h:head/>
<ui:composition template="WEB-INF/xhtml/includes/mainLayout.xhtml">
<f:loadBundle var="text" basename="i18n.applicationResources" />
    <ui:define name="content">
        Leerroo lerro 
   <p:panel header="Colors">  
    <h:panelGrid columns="2" cellpadding="10">  
      <h:form>
        <h:outputText value="Inline: " />  
        <p:colorPicker id="inlineCP" value="#{colorBean.color1}" mode="inline" />  

        <h:outputText value="Popup: " />  
        <p:colorPicker id="popupCP" value="#{colorBean.color2}" widgetVar="picker"/>  
       <h:form>
    </h:panelGrid>

    </p:panel>
    </ui:define>
  </ui:composition>
 </html>
于 2013-05-25T19:20:22.550 回答