我正在使用GlassFishV3,JSF2,漂亮面孔3
我已经尝试了很多组合来摆脱我的* .xhtml扩展o美化我的网址,但我没有设法这样做。
如果你知道另一个解决方案请给我一个如何做的例子,或者如果我的解决方案是可行的,请告诉我我错了:
我按照http://ocpsoft.org/prettyfaces/上的教程创建了一个只有一个index.xhtml的简单应用程序,并且我已经添加了一个指向home.xhtml的链接(两者都在WebContent中)。
我的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>extension</display-name>
<welcome-file-list>
<welcome-file>index.xhtml</welcome-file>
</welcome-file-list>
<context-param>
<param-name>com.ocpsoft.pretty.DEVELOPMENT</param-name>
<param-value>true</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></web-app>
我的pretty-config.xml
<pretty-config xmlns="http://ocpsoft.com/prettyfaces/3.3.3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ocpsoft.com/prettyfaces/3.3.3
http://ocpsoft.com/xml/ns/prettyfaces/ocpsoft-pretty-faces-3.3.3.xsd ">
<url-mapping id="home">
<pattern value="/home" />
<view-id value="/home.xhtml"/>
</url-mapping> </pretty-config>
at com.sun.faces.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:308) 在com.sun.faces.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:367) 在com.sun.faces.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:346) at com.sun.faces.facelets.impl.DefaultFaceletContext.includeFacelet(DefaultFaceletContext.java:199) 在com.sun.faces.facelets.tag.ui.CompositionHandler.apply(CompositionHandler.java:155) at com.sun.faces.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:93) at com.sun.faces.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:86)
非常感谢你的时间!
修改:
我做了一个简单的网络应用程序,看看扩展程序的隐藏是如何工作的。 index.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:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"><ui:composition template="">
<ui:define name="header">
Add your header here or delete to use the default
</ui:define>
<ui:define name="content">
<a id="home" href="home.xhtml">Home</a>
</ui:define>
<ui:define name="footer">
Add your footer here or delete to use the default
</ui:define></ui:composition>
和home.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:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<ui:composition template="">
<ui:define name="header">
Add your header here or delete to use the default
</ui:define>
<ui:define name="content">
home#######
</ui:define>
<ui:define name="footer">
Add your footer here or delete to use the default
</ui:define>
</ui:composition>
</html>
现在,如果我启动应用程序127.0.01:8080 / myapp,则会立即出现错误java.lang.StackOverflowError
但如果我只是放入index.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:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<h:body>
<a id="home" href="home.xhtml">Home</a>
</h:body>
</html>
和home.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:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<h:body>
HOME
</h:body>
</html>
它有效,但扩展名是prezent 以127.0.0.1:8080/myapp/开头,然后点击链接和127.0.0.1:8080/myapp/home.xhtml
我想像第一个索引和带模板的主页一样,因为我在一个已经有模板的网络应用程序上工作。
“a href”标签中的id =“home”我没有t know if it is necesary, the id it
使用CSS来格式化它,但我越来越鄙视了:))
任何帮助将不胜感激。谢谢!
###修改t get any errors but I still can
更改我的网址到目前为止我做了什么:
我在WEB-INF / lib中放了pretty-faces-jsf-3.3.3.jar
我输入了WEB-INF pretty-config.xml
<?xml version="1.0" encoding="UTF-8"?><pretty-config xmlns="http://ocpsoft.com/prettyfaces/3.3.3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ocpsoft.com/prettyfaces/3.3.3
http://ocpsoft.com/xml/ns/prettyfaces/ocpsoft-pretty-faces-3.3.3.xsd">
<url-mapping id="home">
<pattern value="/home" />
<view-id value="/home.xhtml" />
</url-mapping>
我的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>test</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<context-param>
<param-name>com.ocpsoft.pretty.DEVELOPMENT</param-name>
<param-value>true</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></web-app>
我有index.html,home.xhtml和template.xhtml
的index.html
<!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">
<h:body>
<a href="home.xhtml">HOME</a>
</h:body>
</html>
home.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:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<ui:composition template="/tempate.xhtml">
<ui:define name="header">
Add your header here or delete to use the default
</ui:define>
<ui:define name="content">
########################
</ui:define>
<ui:define name="footer">
Add your footer here or delete to use the default
</ui:define>
</ui:composition>
</html>
的template.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:ui="http://java.sun.com/jsf/facelets">
<head>
<title><ui:insert name="title">Default title</ui:insert></title>
</head>
<body>
<div id="header">
<ui:insert name="header">
Header area. See comments below this line in the source.
<!-- include your header file or uncomment the include below and create header.xhtml in this directory -->
<!-- <ui:include src="header.xhtml"/> -->
</ui:insert>
</div>
<div id="content">
<ui:insert name="content">
<ui:include src="home.xhtml" />
</ui:insert>
</div>
<div id="footer">
<ui:insert name="footer">
Footer area. See comments below this line in the source.
<!-- include your header file or uncomment the include below and create footer.xhtml in this directory -->
<!--<ui:include src="footer.xhtml"/> -->
</ui:insert> </div> </body></html>
我没有用
更改我的web.xml <web-app xmlns="http://java.sun.com/xml/ns/javaee" version="2.5"><filter>
<filter-name>Pretty Filter</filter-name>
<filter-class>com.ocpsoft.pretty.PrettyFilter</filter-class>
<async-supported>true</async-supported>
</filter>
<filter-mapping>
<filter-name>Pretty Filter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
<dispatcher>ERROR</dispatcher>
<dispatcher>ASYNC</dispatcher>
</filter-mapping></web-app>
因为我使用Glassfishv3
正如我所说,它是一个简单的网络应用程序,只是为了看它是如何工作的。 请帮助我理解为什么我有困难......
答案 0 :(得分:1)
我不认为这个问题与PrettyFaces有什么关系。 stacktrace只显示一些与Facelets相关的东西:
at com.sun.faces.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:308)
at com.sun.faces.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:367)
at com.sun.faces.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:346)
at com.sun.faces.facelets.impl.DefaultFaceletContext.includeFacelet(DefaultFaceletContext.java:199)
at com.sun.faces.facelets.tag.ui.CompositionHandler.apply(CompositionHandler.java:155)
at com.sun.faces.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:93)
at com.sun.faces.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:86)
我看到您使用的是空template
属性:
<ui:composition template="">
如果不引用基本模板,您的页面将无效。我认为这可能会导致你得到的错误。
BTW:您可以在不使用Facelets模板的情况下测试PrettyFaces。 PrettyFaces对模板一无所知。因此,如果它在没有模板的情况下工作,它也可以使用模板。 :)