Използвам GlassFishV3, JSF2, pretty faces 3
Опитах много комбинации за премахване на моето разширение *.xhtml или за украсяване на моя URL адрес, но не успях да го направя.
Моля, ако знаете друго решение, дайте ми ПРИМЕР как да го направя или ако решението ми е правдоподобно, моля, кажете ми дали съм сгрешил:
Следвах урока на http://ocpsoft.org/prettyfaces/ и създадох тривиално приложение само с един индекс .xhtml и аз поставих връзка към home.xhtml (и двете са в WebContent).
- Запазих буркана (не използвам Maven) и го поставих в WEB-INF/lib
- според урока не е необходимо да променям моя web.xml, защото при използване на GlassFishv3
моят 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
5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app<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>
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><!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="/bghome.xhtml">Home</a> </ui:define> <ui:define name="footer"> Add your footer here or delete to use the default </ui:define></ui:composition>
моят 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>
- with this configuration I keep getting java.lang.StackOverflowError (with others or my app doesn`t compile or I get a different error) the loop is
на 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) в com.sun.faces.facelets.impl.DefaultFaceletContext.includeFacelet(DefaultFaceletContext.java:199) в com.sun.faces.facelets.tag.ui.CompositionHandler.apply (CompositionHandler.java:155) в com.sun.faces.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:93) в com.sun.faces.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:86)
- моят index.xhtml работи, но когато щракна върху връзката, се появява горната грешка
- Нямам никакви зърна (друг въпрос би бил дали трябва да поставя някакви пояснения към картографираните зърна, ако успея да направя красиви лица)
Благодаря ви много за отделеното време!
Модификациите:
Направих тривиално уеб приложение, за да видя как работи скриването на разширението. 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="/bghome.xhtml">Home</a> </ui:define> <ui:define name="footer"> Add your footer here or delete to use the default </ui:define></ui:composition>
and the 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="/bghome.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>
работи, но разширението е представено, стартирано с 127.0.0.1:8080/myapp/ и след това щракнете върху връзката и 127.0.0.1:8080/myapp/home.xhtml
Искам да го направя като първия индекс и начало с шаблона, защото работя върху уеб приложение, което вече има шаблони. Id="home" в тага "a href" неt know if it is necesary, the id it
s използвах от CSS, за да го форматирам, но започвам да се отчайвам :))
Всяка помощ ще бъде оценена. Благодаря ти!
### MODIFICATIONS- така че започнах отново с тривиално уеб приложение, за да видя как работят красивите лица
- сега не
t get any errors but I still can
не променям URL адреса си какво направих досега:
Сложих pretty-faces-jsf-3.3.3.jar в WEB-INF/lib
Сложих 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>
my 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>
в WEB-INF имам 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="/bghome.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
Както казах, това е тривиално уеб приложение, само за да видим как работи. Моля, помогнете ми да разбера защо имам затруднения...