p:selectOneMenu渲染很奇怪

时间:2019-04-02 08:26:07

标签: primefaces

按照PrimeFaces getting-started page上给出的说明,我看到SelectOneMenu上出现了奇怪的渲染。看起来不像我期望的那样。有人知道为什么吗?

Rendering

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:f="http://xmlns.jcp.org/jsf/core"
      xmlns:p="http://primefaces.org/ui">

   <h:body>

      <h:form>
         <p:selectOneMenu id ="selectOneMenuCategorie" value="#{selectOneController.categorieSelected}" >
            <f:selectItem itemLabel="Select One" noSelectionOption="true"/>
            <f:selectItems value="#{selectOneController.categorieList}"
                           var = "c" itemLabel="#{c.libelle}" itemValue="#{c}"/>
            <f:ajax render="selected_item1"/>
         </p:selectOneMenu>

         <h:outputText id="selected_item1" value="#{selectOneController.categorieSelected.libelle}"></h:outputText>

      </h:form>
   </h:body>
</html>

1 个答案:

答案 0 :(得分:0)

您应该添加

 <h:head>
</h:head>

标记到您的xhtml页面。

<h:head>是一个JSF组件,它提供了一个钩子,以编程方式将JavaScript和CSS资源包括在生成的HTML <head>中。 PrimeFaces使用它来包含Ajax作品和花哨的外观所需的JS / CSS代码。

作为测试,创建一个包含<h:head>和一个PrimeFaces组件的页面,在Web浏览器中打开该页面,然后右键单击-查看源代码,检查生成的HTML源代码。 。您将看到已添加了几个特定于JSF和PrimeFaces的JS / CSS文件。现在,将<h:head>替换为<head>,并再次检查生成的HTML源,这次您什么也看不到。

相关问题