2013-05-25 63 views
0

該應用程序需要我的標籤並向我顯示頁面。 但在視圖中,我看不到CSS和JS。 這是我的代碼:Primefaces不顯示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> 

的index.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> 

回答

1
  1. 您需要知道,在頁面呈現期間,您的<ui:composition/>標記之外的所有內容都將被忽略。這意味着如果您的模板頁面包含在其他頁面中,則您的<h:form/><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> 
+0

我也喜歡猜測它自己的回答非常感謝!好樣的! +1 :) – skuntsel

+0

Lol @skuntsel!我實際上最終會添加代碼。先看其他問題。 – kolossus