Richfaces 4 组件不渲染
Posted
技术标签:
【中文标题】Richfaces 4 组件不渲染【英文标题】:Richfaces 4 components don't render 【发布时间】:2011-12-23 07:34:25 【问题描述】:我遇到的问题是 jsf 标签没有被解析,所以我没有在我的页面中看到richfaces 组件。我正在使用 Richfaces 4、tomcat 7 和 jsf 2.0
这是我的 faces-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<faces-config
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
version="2.0">
</faces-config>
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" version="3.0">
<display-name>bisis-please-work</display-name>
<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>*.jsf</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
<param-value>resources.application</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>
<description>
This parameter tells MyFaces if javascript code should be allowed in
the rendered HTML output.
If javascript is allowed, command_link anchors will have javascript code
that submits the corresponding form.
If javascript is not allowed, the state saving info and nested parameters
will be added as url parameters.
Default is 'true'</description>
<param-name>org.apache.myfaces.ALLOW_JAVASCRIPT</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<description>
If true, rendered HTML code will be formatted, so that it is 'human-readable'
i.e. additional line separators and whitespace will be written, that do not
influence the HTML code.
Default is 'true'</description>
<param-name>org.apache.myfaces.PRETTY_HTML</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.DETECT_JAVASCRIPT</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<description>
If true, a javascript function will be rendered that is able to restore the
former vertical scroll on every request. Convenient feature if you have pages
with long lists and you do not want the browser page to always jump to the top
if you trigger a link or button action that stays on the same page.
Default is 'false'
</description>
<param-name>org.apache.myfaces.AUTO_SCROLL</param-name>
<param-value>true</param-value>
</context-param>
<listener>
<listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
</listener>
</web-app>
这就是我在启动 Tomcat 7 时得到的结果
Nov 7, 2011 1:33:45 AM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jre6\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files/Java/jre6/bin/client;C:/Program Files/Java/jre6/bin;C:/Program Files/Java/jre6/lib/i386;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files\TortoiseSVN\bin;C:\Program Files\Java\jdk1.6.0_25\bin;D:\svn\My\GAE\_sdk_python\;C:\Users\Brankica\Desktop\eclipse;;.
Nov 7, 2011 1:33:46 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]Server/Service/Engine/Host/Context Setting property 'source' to 'org.eclipse.jst.jee.server:bisis-please-work' did not find a matching property.
Nov 7, 2011 1:33:46 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
Nov 7, 2011 1:33:46 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
Nov 7, 2011 1:33:46 AM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 1896 ms
Nov 7, 2011 1:33:46 AM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Nov 7, 2011 1:33:46 AM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.22
Nov 7, 2011 1:33:58 AM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jstl/core is already defined
Nov 7, 2011 1:33:58 AM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jstl/sql_rt is already defined
Nov 7, 2011 1:33:58 AM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jsp/jstl/sql is already defined
Nov 7, 2011 1:33:58 AM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jstl/core_rt is already defined
Nov 7, 2011 1:33:58 AM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jsp/jstl/core is already defined
Nov 7, 2011 1:33:58 AM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jsp/jstl/functions is already defined
Nov 7, 2011 1:33:58 AM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jstl/fmt is already defined
Nov 7, 2011 1:33:58 AM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://jakarta.apache.org/taglibs/standard/permittedTaglibs is already defined
Nov 7, 2011 1:33:58 AM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jstl/xml is already defined
Nov 7, 2011 1:33:58 AM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://jakarta.apache.org/taglibs/standard/scriptfree is already defined
Nov 7, 2011 1:33:58 AM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jstl/fmt_rt is already defined
Nov 7, 2011 1:33:58 AM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jsp/jstl/fmt is already defined
Nov 7, 2011 1:33:58 AM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jsp/jstl/xml is already defined
Nov 7, 2011 1:33:58 AM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jstl/xml_rt is already defined
Nov 7, 2011 1:33:58 AM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jstl/sql is already defined
Nov 7, 2011 1:33:58 AM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jsf/core is already defined
Nov 7, 2011 1:33:58 AM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jsf/html is already defined
Nov 7, 2011 1:33:58 AM org.apache.catalina.core.StandardContext addApplicationListener
INFO: The listener "org.apache.myfaces.webapp.StartupServletContextListener" is already configured for this context. The duplicate definition has been ignored.
Nov 7, 2011 1:33:58 AM org.apache.myfaces.shared.config.MyfacesConfig getBooleanInitParameter
INFO: No context init parameter 'org.apache.myfaces.RENDER_CLEAR_JAVASCRIPT_FOR_BUTTON' found, using default value false
Nov 7, 2011 1:33:58 AM org.apache.myfaces.shared.config.MyfacesConfig getBooleanInitParameter
INFO: No context init parameter 'org.apache.myfaces.RENDER_HIDDEN_FIELDS_FOR_LINK_PARAMS' found, using default value false
Nov 7, 2011 1:33:58 AM org.apache.myfaces.shared.config.MyfacesConfig getBooleanInitParameter
INFO: No context init parameter 'org.apache.myfaces.SAVE_FORM_SUBMIT_LINK_IE' found, using default value false
Nov 7, 2011 1:33:58 AM org.apache.myfaces.shared.config.MyfacesConfig getBooleanInitParameter
INFO: No context init parameter 'org.apache.myfaces.READONLY_AS_DISABLED_FOR_SELECTS' found, using default value true
Nov 7, 2011 1:33:58 AM org.apache.myfaces.shared.config.MyfacesConfig getBooleanInitParameter
INFO: No context init parameter 'org.apache.myfaces.RENDER_VIEWSTATE_ID' found, using default value true
Nov 7, 2011 1:33:58 AM org.apache.myfaces.shared.config.MyfacesConfig getBooleanInitParameter
INFO: No context init parameter 'org.apache.myfaces.STRICT_XHTML_LINKS' found, using default value true
Nov 7, 2011 1:33:58 AM org.apache.myfaces.shared.config.MyfacesConfig getBooleanInitParameter
INFO: No context init parameter 'org.apache.myfaces.RENDER_FORM_SUBMIT_SCRIPT_INLINE' found, using default value false
Nov 7, 2011 1:33:58 AM org.apache.myfaces.shared.config.MyfacesConfig getLongInitParameter
INFO: No context init parameter 'org.apache.myfaces.CONFIG_REFRESH_PERIOD' found, using default value 2
Nov 7, 2011 1:33:58 AM org.apache.myfaces.shared.config.MyfacesConfig getBooleanInitParameter
INFO: No context init parameter 'org.apache.myfaces.VIEWSTATE_JAVASCRIPT' found, using default value false
Nov 7, 2011 1:33:58 AM org.apache.myfaces.shared.config.MyfacesConfig getStringInitParameter
INFO: No context init parameter 'org.apache.myfaces.REFRESH_TRANSIENT_BUILD_ON_PSS' found, using default value auto
Nov 7, 2011 1:33:58 AM org.apache.myfaces.shared.config.MyfacesConfig getBooleanInitParameter
INFO: No context init parameter 'org.apache.myfaces.REFRESH_TRANSIENT_BUILD_ON_PSS_PRESERVE_STATE' found, using default value false
Nov 7, 2011 1:33:58 AM org.apache.myfaces.shared.config.MyfacesConfig getBooleanInitParameter
INFO: No context init parameter 'org.apache.myfaces.VALIDATE_XML' found, using default value false
Nov 7, 2011 1:33:58 AM org.apache.myfaces.shared.config.MyfacesConfig getBooleanInitParameter
INFO: No context init parameter 'org.apache.myfaces.WRAP_SCRIPT_CONTENT_WITH_XML_COMMENT_TAG' found, using default value true
Nov 7, 2011 1:33:58 AM org.apache.myfaces.shared.config.MyfacesConfig getBooleanInitParameter
INFO: No context init parameter 'org.apache.myfaces.DEBUG_PHASE_LISTENER' found, using default value false
Nov 7, 2011 1:33:58 AM org.apache.myfaces.shared.config.MyfacesConfig createAndInitializeMyFacesConfig
INFO: Tomahawk jar not available. Autoscrolling, DetectJavascript, AddResourceClass and CheckExtensionsFilter are disabled now.
Nov 7, 2011 1:33:58 AM org.apache.myfaces.config.DefaultFacesConfigurationProvider getStandardFacesConfig
INFO: Reading standard config META-INF/standard-faces-config.xml
Nov 7, 2011 1:33:58 AM org.apache.myfaces.config.DefaultFacesConfigurationProvider getWebAppFacesConfig
INFO: Reading config /WEB-INF/faces-config.xml
Nov 7, 2011 1:33:58 AM org.apache.myfaces.config.annotation.DefaultAnnotationProvider webClasses
WARNING: AnnotationConfigurator does not found classes for annotations in /WEB-INF/classes/ . This could happen because maven jetty plugin is used (goal jetty:run). Try configure org.apache.myfaces.annotation.SCAN_PACKAGES init parameter or use jetty:run-exploded instead.
Nov 7, 2011 1:34:00 AM org.apache.myfaces.config.DefaultFacesConfigurationProvider getClassloaderFacesConfig
INFO: Reading config : jar:file:/D:/informaticki%20projekat/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/bisis-please-work/WEB-INF/lib/richfaces-components-ui-4.0.0.Final.jar!/META-INF/faces-config.xml
Nov 7, 2011 1:34:00 AM org.apache.myfaces.config.DefaultFacesConfigurationProvider getClassloaderFacesConfig
INFO: Reading config : jar:file:/D:/informaticki%20projekat/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/bisis-please-work/WEB-INF/lib/richfaces-core-impl-4.0.0.Final.jar!/META-INF/faces-config.xml
Nov 7, 2011 1:34:00 AM org.apache.myfaces.config.LogMetaInfUtils logArtifact
INFO: Artifact 'myfaces-api' was found in version '2.1.3' from path 'file:/D:/informaticki%20projekat/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/bisis-please-work/WEB-INF/lib/myfaces-api-2.1.3.jar'
Nov 7, 2011 1:34:00 AM org.apache.myfaces.config.LogMetaInfUtils logArtifact
INFO: Artifact 'myfaces-bundle' was found in version '2.1.3' from path 'file:/D:/informaticki%20projekat/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/bisis-please-work/WEB-INF/lib/myfaces-bundle-2.1.3.jar'
Nov 7, 2011 1:34:00 AM org.apache.myfaces.config.LogMetaInfUtils logArtifact
INFO: Artifact 'myfaces-impl' was found in version '2.1.3' from path 'file:/D:/informaticki%20projekat/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/bisis-please-work/WEB-INF/lib/myfaces-impl-2.1.3.jar'
Nov 7, 2011 1:34:00 AM org.apache.myfaces.util.ExternalSpecifications isBeanValidationAvailable
INFO: MyFaces Bean Validation support disabled
Nov 7, 2011 1:34:00 AM org.apache.myfaces.application.ApplicationImpl getProjectStage
INFO: Couldn't discover the current project stage, using Production
Nov 7, 2011 1:34:00 AM org.apache.myfaces.config.FacesConfigurator handleSerialFactory
INFO: Serialization provider : class org.apache.myfaces.shared_impl.util.serial.DefaultSerialFactory
Nov 7, 2011 1:34:00 AM org.apache.myfaces.config.annotation.DefaultLifecycleProviderFactory getLifecycleProvider
INFO: Using LifecycleProvider org.apache.myfaces.config.annotation.Tomcat7AnnotationLifecycleProvider
Nov 7, 2011 1:34:01 AM org.apache.myfaces.webapp.AbstractFacesInitializer initFaces
INFO: ServletContext 'D:\informaticki projekat\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\bisis-please-work\' initialized.
Nov 7, 2011 1:34:01 AM org.richfaces.javascript.ClientServiceConfigParser parse
WARNING: Found JavaScript function definition for class org.hibernate.validator.constraints.NotEmpty, but that class is not presented
Nov 7, 2011 1:34:01 AM org.richfaces.cache.CacheManager getCacheFactory
INFO: Selected fallback cache factory
Nov 7, 2011 1:34:01 AM org.richfaces.cache.lru.LRUMapCacheFactory createCache
INFO: Creating LRUMap cache instance using parameters: org.apache.myfaces.DETECT_JAVASCRIPT=false, org.apache.myfaces.PRETTY_HTML=true, org.apache.myfaces.AUTO_SCROLL=true, org.apache.myfaces.ALLOW_JAVASCRIPT=true, javax.servlet.jsp.jstl.fmt.localizationContext=resources.application, javax.faces.STATE_SAVING_METHOD=client
Nov 7, 2011 1:34:01 AM org.richfaces.cache.lru.LRUMapCacheFactory createCache
INFO: Creating LRUMap cache instance of 512 items capacity
Nov 7, 2011 1:34:01 AM org.richfaces.application.InitializationListener onStart
INFO: RichFaces Core Implementation by JBoss, a division of Red Hat, Inc., version v.4.0.0.Final SVN r.22269
Nov 7, 2011 1:34:01 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
Nov 7, 2011 1:34:02 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Nov 7, 2011 1:34:02 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 15218 ms
我用于测试的示例(我从浏览器得到的源代码是相同的):
<!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:rich="http://richfaces.org/rich">
<f:view contentType="text/html">
<h:head>
<title>Calendar</title>
</h:head>
<h:body>
<rich:calendar datePattern="dd/MM/yyyy hh:mm:ss" />
</h:body>
如果有人有一些建议,请写..提前谢谢
【问题讨论】:
XHTML 文件的源代码是什么? (您不需要发布 1000 行代码;只需尽可能最小的仍然重现此问题的代码就足够了,例如,只有一个 Richfaces 组件)。您在浏览器地址栏中使用的 URL 是什么?浏览器检索到的生成的 HTML 代码是什么? (在浏览器中右键单击页面,查看源代码)。请编辑您的问题以包含此信息。 感谢您的建议,但我发布了所有内容,因为我真的不知道问题出在哪里。我使用正确的网址(我可以在浏览器中打开页面)。现在我在我的问题中包含了 xHTML 文件。因此,如果您有任何进一步的建议,请告诉我。 【参考方案1】:我从浏览器得到的源代码是一样的
换句话说,FacesServlet
没有被调用,因此无法完成它的工作。这只能意味着请求 URL 与 FacesServlet
中定义的 URL 模式不匹配 web.xml
。也许您是通过 http://localhost:8080/bisis-please-work/somepage.xhtml 而不是 http://localhost:8080/bisis-please-work/somepage.jsf 打开页面,这将匹配您在 web.xml
中定义的 <url-pattern>*.jsf</url-pattern>
。
或者,您也可以将*.jsf
替换为*.xhtml
,这样您就不必再摆弄URL,也不必担心客户端能够看到原始JSF 源代码。唯一的缺点是,如果不调用 FacesServlet
,您将无法提供“普通的”XHTML 文件,但这没关系,这些文件无论如何都应该具有 .html
扩展名。
【讨论】:
这有帮助。非常感谢。 :) BalusC,你能看看我的问题***.com/questions/8204417/… ..我不确定这是否是与你联系的合适方式,但我发现你的答案解释得很好..提前致谢【参考方案2】:我遇到了同样的问题,但根本原因不同。对我来说,richfaces 组件,尤其是 rich:tabPanel,没有渲染,因为页面中有普通的 html 标签。
<head>...</head>
而不是
<h:head>...</h:head>
导致rich:tabPanel 根本不显示。
使用纯 html 正文标签会导致选项卡呈现,但不可点击。
【讨论】:
以上是关于Richfaces 4 组件不渲染的主要内容,如果未能解决你的问题,请参考以下文章
如何让 Richfaces 组件在按需加载的弹出窗口中工作?