eclipse 简单的primefaces应用程序不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7219372/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Simple primefaces application not working
提问by Shekhar
I am trying to build simple JSF application using primefaces but somehow primefaces components are not getting rendered properly. I dont understand what is going wrong.
我正在尝试使用 primefaces 构建简单的 JSF 应用程序,但不知何故,primefaces 组件无法正确呈现。我不明白出了什么问题。
I am trying to display following Facelet file :
我正在尝试显示以下 Facelet 文件:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.prime.com.tr/ui">
<h:head>
<link type="text/css"
rel="stylesheet"
href="/Themes/primefaces-dot-luv/theme.css" />
</h:head>
<h:body>
<p:spinner value="100" style="height: 10px" />
<br/>
<p:button value="Navigate"></p:button>
</h:body>
</html>
I am using eclipse to run the app on tomcat server. When I run the application and view the page source in browser(firefox) I get following source :
我正在使用 eclipse 在 tomcat 服务器上运行该应用程序。当我运行应用程序并在浏览器(firefox)中查看页面源代码时,我得到以下源代码:
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:p="http://primefaces.prime.com.tr/ui">
<head>
<link type="text/css" rel="stylesheet" href="Themes/primefaces-dot-luv/theme.css" />
</head>
<body>
<p:spinner value="100" style="height: 10px"></p:spinner>
<br />
<p:button value="Navigate"></p:button>
</body>
</html>
I think PrimeFaces components are not getting rendered properly. Other JSF tags like <h:head>
and <h:body>
are converted correctly to <head>
and <body>
elements respectively. Only tags starting with <p:>
are not converted.
我认为 PrimeFaces 组件没有正确渲染。其他 JSF 标记如<h:head>
和<h:body>
分别正确转换为<head>
和<body>
元素。只有以 开头的标签<p:>
不会被转换。
Following is my project structure :
以下是我的项目结构:
My web.xml
looks like this:
我的web.xml
看起来像这样:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>HelloJSF</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<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>/faces/*</url-pattern>
</servlet-mapping>
<context-param>
<param-name>primefaces.THEME</param-name>
<param-value>none</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>
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.faces</url-pattern>
</servlet-mapping>
</web-app>
I am using eclipse , tomcat server. JSF 2 and primefaces 3 library.
我正在使用 eclipse ,tomcat 服务器。JSF 2 和 primefaces 3 库。
Hi, After some close inspection of entire project I found out that primefaces jar dowlonaded from site did not had any classes. Jar itself was corrupt. I downloaded same jar thrice then also jar was getting corrupt. So I downloaded zip file containing source and binaries and my application started working.
嗨,经过对整个项目的仔细检查,我发现从站点下载的 primefaces jar 没有任何课程。Jar 本身已损坏。我下载了相同的 jar 三次,然后 jar 也损坏了。所以我下载了包含源代码和二进制文件的 zip 文件,我的应用程序开始工作。
回答by AlanObject
Try changing your web.xml servlet mapping:
尝试更改您的 web.xml servlet 映射:
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
The way to tell if the Facelets Servlet is processing your xhtml is to look at what the browser receives. If it looks like your xhtml file then you have something mis-configured.
判断 Facelets Servlet 是否正在处理您的 xhtml 的方法是查看浏览器接收到的内容。如果它看起来像您的 xhtml 文件,那么您的配置有误。
回答by ratking
Your need change
你的需要改变
xmlns:p="http://primefaces.prime.com.tr/ui"
to
到
xmlns:p="http://primefaces.org/ui"
回答by ratking
You should change your namespace into xmlns:p="http://primefaces.org/ui"
您应该将命名空间更改为 xmlns:p="http://primefaces.org/ui"
and implement button like this way
并像这样实现按钮
<p:commandButton value="Home" process="@this" action="actionMethod()" immediate="true" rendered="true or renderingMethod()" />