2014-05-03 205 views
0

我正在處理Spring3/JSF2/Primefaces3.5應用程序: 我面臨的問題是一些Primefaces組件不在瀏覽器中呈現。 Spring框架 林初學者,這是我最前一頁試圖Primefaces融入我的webapp 這是index.html的:無法渲染primefaces組件?

<!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:ui="http://java.sun.com/jsf/facelets" 
      xmlns:p="http://primefaces.prime.com.tr/ui"> 

     <h:form> 

      <p:growl id="msg" /> 

      <h:panelGrid columns="2" style="margin-bottom:10px" cellpadding="5"> 

       <h:outputText value="I accept terms and conditions: " /> 
       <p:selectBooleanButton value="#{formBean.value1}" onLabel="Yes" offLabel="No"/> 

       <h:outputText value="Subscribe me to newsletter: " /> 
       <p:selectBooleanButton value="#{formBean.value2}" onLabel="Yes" offLabel="No" onIcon="ui-icon-check" offIcon="ui-icon-close"> 
        <p:ajax update="msg" listener="#{formBean.addMessage}"/> 
       </p:selectBooleanButton> 

      </h:panelGrid> 

      <p:commandButton value="Submit" update="display" oncomplete="PF('dlg').show()" /> 

      <p:dialog header="Selected Values" modal="true" showEffect="fade" hideEffect="fade" widgetVar="dlg"> 
       <h:panelGrid columns="1" id="display"> 
        <h:outputText value="Value 1: #{formBean.value1}" /> 

        <h:outputText value="Value 2: #{formBean.value2}" /> 
       </h:panelGrid> 
      </p:dialog> 

     </h:form> 

    </html> 

and this is project tree and web.xml: 
<?xml version="1.0" encoding="UTF-8"?> 
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> 

    <!-- The definition of the Root Spring Container shared by all Servlets and Filters --> 
    <!-- Chargement du contexte de l’application Web --> 
    <context-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value>classpath*:applicationContext.xml</param-value> 
    </context-param> 

    <!-- Creates the Spring Container shared by all Servlets and Filters --> 
    <listener> 
     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
    </listener> 
    <!-- Processes application requests --> 
    <listener> 
    <listener-class> 
     org.springframework.web.context.request.RequestContextListener 
    </listener-class> 
    </listener> 
    <!-- Welcome page --> 
    <welcome-file-list> 
    <welcome-file>index.xhtml</welcome-file> 
    </welcome-file-list> 

    <!-- 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>*.jsf</url-pattern> 
    </servlet-mapping> 
    <servlet-mapping> 
    <servlet-name>facesServlet</servlet-name> 
    <url-pattern>*.xhtml</url-pattern> 
    </servlet-mapping> 

</web-app> 

這是servlet的context.xml中

<?xml version="1.0" encoding="UTF-8"?> 
<beans:beans xmlns="http://www.springframework.org/schema/mvc" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:beans="http://www.springframework.org/schema/beans" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd 
     http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd 
     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> 

    <!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure --> 

    <!-- Enables the Spring MVC @Controller programming model --> 
    <annotation-driven /> 

    <!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory --> 
    <resources mapping="/resources/**" location="/resources/" /> 

    <!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory --> 
    <beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
     <beans:property name="prefix" value="/WEB-INF/views/" /> 
     <beans:property name="suffix" value=".jsp" /> 
    </beans:bean> 

    <context:component-scan base-package="com.gestion.projet" /> 


</beans:beans> 

的面孔,配置。 XML:

<faces-config 
    xmlns="http://java.sun.com/xml/ns/javaee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_1.xsd" 
    version="2.1"> 
    <application> 
     <el-resolver> 
       org.springframework.web.jsf.el.SpringBeanFacesELResolver 
     </el-resolver> 
    </application> 
</faces-config> 

回答

0

修復XHTML頁面上primefaces命名空間。

xmlns:p =「http://primefaces.org/ui」是正確的,你嘗試使用什麼版本的PF?

http://primefaces.org/gettingStarted - 試試這個基本的例子,看看它是否運行正常。你是如何訪問該頁面的?它需要被FacesServlet拾取。

+0

謝謝@VeenarM –