【问题标题】:Why my menu doesn't work in RichFaces 4.3.4?为什么我的菜单在 RichFaces 4.3.4 中不起作用?
【发布时间】:2014-01-20 10:52:47
【问题描述】:

我是 jsf 和丰富面孔的新手。我正在关注现场演示并尝试创建一个简单的菜单。但它不工作。我正在使用 jboss7.1 和 jsf 2.1 和 ric 4.3.4

menu.xmhtl

<!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:a4j="http://richfaces.org/a4j"
    xmlns:rich="http://richfaces.org/rich">
<h:head></h:head>
<h:body>
    <ui:composition>
        <h:form>
            <rich:toolbar height="26px">
                <rich:dropDownMenu   mode="ajax">
                    <f:facet name="label">
                        <h:panelGroup>
                            <h:outputText value="File" />
                        </h:panelGroup>
                    </f:facet>
                    <rich:menuItem label="hello" action="hello" />
                    <rich:menuSeparator id="menuSeparator11" />
                    <rich:menuItem label="Open" action="AddStudent" />
                </rich:dropDownMenu>

                <rich:dropDownMenu mode="ajax">
                    <f:facet name="label">
                        <h:panelGroup>
                            <h:outputText value="File" />
                        </h:panelGroup>
                    </f:facet>
                    <rich:menuItem label="hello" action="hello" />
                    <rich:menuItem label="Open" action="AddStudent" />
                </rich:dropDownMenu>
            </rich:toolbar>
        </h:form>

    </ui:composition>
</h:body>
</html>

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_3_0.xsd"
    id="WebApp_ID" version="3.0">

    <display-name>helloRich</display-name>
    <welcome-file-list>
        <welcome-file>hello.xhtml</welcome-file>
    </welcome-file-list>

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

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

    <listener>
        <listener-class>com.sun.faces.config.ConfigureListener</listener-class>
    </listener>
</web-app>

这些是我在 lib 目录中的 jar

cssparser-0.9.5.jar
guava-r08.jar 
jstl-1.2.jar        
richfaces-components-api-4.3.4.Final.jar       
richfaces-components-ui-4.3.4.Final.jar      
richfaces-core-api-4.3.4.Final.jar          
richfaces-core-impl-4.3.4.Final.jar 
sac-1.3.jar

我不知道我在这里缺少什么..任何帮助都会有所帮助.. 我的输出

【问题讨论】:

  • 您缺少&lt;h:head&gt;&lt;h:body&gt; 标签。如果添加它们会发生什么?猜猜:你没有加载 RF javascript 文件?
  • no m 没有使用任何 javascript.. 只是一个简单的菜单..
  • Richfaces 广泛使用 javascript,检查您的页面是否加载了“packed.js”和“jsf.js”。即使不加载任何(自定义)javascript,这些文件也需要存在才能正常工作。

标签: jsf jsf-2 richfaces


【解决方案1】:

您需要删除页面上的&lt;ui:composition&gt;

根据定义,在 &lt;ui:composition&gt; 标记之外声明的所有内容都会被 JSF 运行时忽略。这包括您在那里的&lt;h:head&gt;&lt;h:body&gt; 标签。产生的问题是 &lt;h:head/&gt; 标签对于 JSF 能够包含正确呈现组件所需的 javascript 包是必需的。这是您遇到的问题。

由于您实际上并未使用 &lt;ui:composition/&gt; 的模板功能,因此您可以安全地删除它以获得结果。

相关:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-05-16
    • 2020-07-12
    • 2011-06-06
    • 1970-01-01
    • 2022-10-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多