【问题标题】:p:selectOneMenu Rendering Weirdp:selectOneMenu 渲染奇怪
【发布时间】:2019-04-02 08:26:07
【问题描述】:

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

<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>

【问题讨论】:

  • 您的 primefaces 似乎尚未安装。因为我已经在我的项目中运行了您的代码并且它可以工作。显示您的控制台。

标签: primefaces


【解决方案1】:

你应该添加

 <h:head>
</h:head>

标记到您的 xhtml 页面。

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-07-13
    • 2017-02-17
    • 2015-09-05
    • 2014-02-15
    • 2023-03-21
    • 2020-04-25
    • 2023-03-16
    • 2015-11-03
    相关资源
    最近更新 更多