eclipse 尽管存在依赖关系,但 PrimeFaces 组件不会在浏览器中呈现
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18462568/
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
PrimeFaces components are not rendered in browser in spite of dependency being present
提问by kark
I'm developing a JSF web application with PrimeFaces 3.5 on Eclipse 4.3. There are no compiletime or runtime errors and the application deploys successfully. However, I cannot get the desired output in browser. The PrimeFaces components do not show up, while the standard JSF components do.
我正在 Eclipse 4.3 上使用 PrimeFaces 3.5 开发 JSF Web 应用程序。没有编译时或运行时错误,应用程序部署成功。但是,我无法在浏览器中获得所需的输出。PrimeFaces 组件不显示,而标准 JSF 组件显示。
I'm not sure if I configured everything right. The PrimeFaces JAR is at least inside /WEB-INF/lib
:
我不确定我是否配置正确。PrimeFaces JAR 至少在里面/WEB-INF/lib
:
And the PrimeFaces XML namespace is declared as xmlns:p="http:\\primefaces.org\ui"
并且 PrimeFaces XML 命名空间被声明为 xmlns:p="http:\\primefaces.org\ui"
And I mapped the FacesServlet
on *.xhtml
:
我映射FacesServlet
上*.xhtml
:
Here's the full source code of login.xhtml
:
这是完整的源代码login.xhtml
:
<!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:p=" http://primefaces.org/ui" >
<h:body>
<h:head ><title>Login Page !!</title></h:head>
<h:form>
<p:panel id="panel" header="Login Panel" style="margin-bottom:10px;">
<h:panelGrid columns="3">
<h:outputLabel value="User Id:" />
<p:inputText id="id" value="loginBean.id" required="true" requiredMessage="ID required"/>
<p:message for="id" />
<p:outputLabel value="User Name:" />
<p:inputText id="name" value="loginBean.name" required="true" requiredMessage="Name required" />
<p:message for="name" />
</h:panelGrid>
</p:panel>
<p:commandButton type="Submit" value="Submit" action="#" style="margin-right:20px;" />
`
`
The output looks like this:
输出如下所示:
As you see, <h:outputText>
did its job, but none of <p:xxx>
show up. How is this caused and how can I solve it?
如您所见,<h:outputText>
完成了它的工作,但没有<p:xxx>
出现。这是怎么引起的,我该如何解决?
回答by akelec
This is not directly answer on this question, but it's related to it. I want to share my experience with the problem "PrimeFaces tags not rendering". I am developing JSF 2.2 app on WildFly, and here is my index.xhtml:
这不是对这个问题的直接回答,但与之相关。我想分享我对“PrimeFaces 标签未呈现”问题的经验。我正在 WildFly 上开发 JSF 2.2 应用程序,这是我的 index.xhtml:
<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.org/ui">
<h:body>
<h:form>
<p:editor value="#{mDb.newMessage.content}"></p:editor>
</h:form>
</h:body>
</html>
When an app is running, the editor doesn't appear, and this was very strange to me, because PrimeFaces was configured correctly in project.
当应用程序运行时,编辑器没有出现,这对我来说很奇怪,因为在项目中正确配置了 PrimeFaces。
I accidentally discovered cause of problem. There was not a h:head
tag in index.xhtml. When I put head tag, PrimeFaces components rendered successfully!!
我无意中发现了问题的原因。h:head
index.xhtml 中没有标签。当我放置 head 标签时,PrimeFaces 组件渲染成功!!
I hope this could help someone.
我希望这可以帮助某人。
回答by BalusC
As to the cause of your concrete problem of PrimeFaces components not being rendered, as per the screenshot, you have a leading blank space in PrimeFaces taglib URI:
至于您的 PrimeFaces 组件未呈现的具体问题的原因,根据屏幕截图,您在 PrimeFaces taglib URI 中有一个前导空格:
xmlns:p=" http://primefaces.org/ui"
This is significant and thus wrong. Get rid of it:
这很重要,因此是错误的。摆脱它:
xmlns:p="http://primefaces.org/ui"
This way the PrimeFaces components must be parsed and appear in the HTML output.
这样 PrimeFaces 组件必须被解析并出现在 HTML 输出中。
For the remainder I strongly recommend you to go through a sane JSF2 tutorial first. You're making several conceptual mistakes which are already covered by a decent Hello World example. Start at our JSF wiki page. Those mistakes do however nothave this "blank page" as consequence. They will cause different problems (e.g. CSS/JS not functioning and form submit not working). If you still stucks on that, you should essentially be asking a new question.
对于剩下的部分,我强烈建议您先阅读一个健全的 JSF2 教程。您正在犯一些概念性错误,这些错误已经被一个体面的 Hello World 示例所涵盖。从我们的 JSF wiki 页面开始。然而,这些错误不会导致这个“空白页”。它们会导致不同的问题(例如 CSS/JS 不起作用和表单提交不起作用)。如果您仍然坚持这一点,那么您本质上应该是在问一个新问题。
回答by Kishor Prakash
1.
When ever you are referring to Managed Bean properties from JSF components, use correct syntax for JSF EL statements.
1.
当您从 JSF 组件引用托管 Bean 属性时,请为 JSF EL 语句使用正确的语法。
#{bean_name.property}
In your code you are forgetting to provide #{}
.
For example at line #15in login.xhtmluse :
在您的代码中,您忘记提供#{}
.
例如在login.xhtml 中的第 15行使用:
<h:inputText id="id" value="#{loginBean.id}" required="true" requiredMessage="ID required"/>
2.
You are keeping <h:head>
inside <h:body>
. Its not a good practice.
Keep <h:head>
out side <h:body>
.
Actual structure would be:
2.
你一直<h:head>
在里面<h:body>
。这不是一个好习惯。
保持<h:head>
在一边<h:body>
。
实际结构是:
<!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: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.org/ui">
<h:head>
<title></title>
<h:head>
<h:body>
<!-- Your Code -->
</h:body>
</html>
3.
You may be getting exception in ManagedBean LoginBean.javaclass.
Please post the code instead of screenshots.
3.
您可能在 ManagedBean LoginBean.java类中遇到异常。
请发布代码而不是屏幕截图。
回答by marco
if you build your proeject mit maven remember to include a dependency of primefaces lib into pom.xml
如果您构建项目 mit maven,请记住将 primefaces lib 的依赖项包含到 pom.xml 中
best regards
此致