【问题标题】:pretty faces jsf glassfish doesn`t work for me漂亮的面孔 jsf glassfish 不适合我
【发布时间】:2012-11-12 05:35:13
【问题描述】:

我正在使用 GlassFishV3、JSF2、漂亮面孔 3

我已经尝试了很多组合来摆脱我的 *.xhtml 扩展名或美化我的 URL,但我没能做到。

如果您知道其他解决方案,请给我一个示例说明如何执行此操作,或者我的解决方案是否合理,请告诉我我是否出错了:

我按照http://ocpsoft.org/prettyfaces/ snd 的教程创建了一个只有一个 index.xhtml 的简单应用程序,并且我已经放置了 home.xhtml 的链接(两者都在 WebContent 中)。

  • 我有 dwl jar(我不使用 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_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>
    
  • 我的漂亮配置.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>
    
    • 使用此配置,我不断收到 java.lang.StackOverflowError(与其他人或我的应用程序无法编译或我收到不同的错误)循环是

    在 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 可以工作,但是当我点击链接时出现上述错误
    • 我没有任何 bean(另一个问题是,如果我设法获得漂亮的面孔,是否必须对映射的 bean 进行任何注释)

    非常感谢您的宝贵时间!

修改:

  • 我做了一个简单的网络应用程序来看看隐藏扩展是如何工作的。 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>

它可以工作,但扩展是存在的 从 127.0.0.1:8080/myapp/ 开始,然后点击链接和 127.0.0.1:8080/myapp/home.xhtml

我想像第一个索引和模板一样使用模板,因为我在一个已经有模板的网络应用程序上工作。 “a href”标签中的 id="home" 我不使用 CSS 使用t know if it is necesary, the id its 来格式化它,但我越来越绝望:))

任何帮助将不胜感激。谢谢!

### 修改
  • 所以我又开始使用一个简单的网络应用程序来看看漂亮的面孔是如何工作的
  • 现在我不要t get any errors but I still cant 更改我的网址
  • 到目前为止我做了什么:

  • 我把 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>
    

  • 我的 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="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>

模板.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

正如我所说,这是一个微不足道的网络应用程序,只是为了看看它是如何工作的。 请帮助我理解为什么我有困难...

【问题讨论】:

  • 可以分享一下xhtml文件吗?
  • 我已经编辑了我原来的问题。
  • 设置美颜的基本步骤是什么?我做的事情肯定是错的......我看到的每一个地方都说这真的很容易......
  • 这真的很简单,并在文档中进行了描述。您可以查看 Maven 原型作为快速入门:github.com/chkal/prettyfaces-archetypes/wiki
  • 最后一次修改后,如果您在浏览器中输入localhost:8080/myapp/home,您应该会看到主页。您的问题与所有修改部分都很混乱。如果它不起作用,请在ocpsoft.org/support 上发帖并附上您的示例应用程序。我相信我们能在这方面为您提供帮助。

标签: url jsf-2 hide glassfish-3 prettyfaces


【解决方案1】:

我认为这个问题与 PrettyFaces 没有任何关系。堆栈跟踪仅显示一些与 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="">

如果不引用基本模板,您的页面将无法工作。我认为这可能会导致您遇到的错误。

顺便说一句:您可以在不使用 Facelets 模板的情况下测试 PrettyFaces。 PrettyFaces 对模板一无所知。因此,如果它在没有模板的情况下工作,它也将与模板一起工作。 :)

【讨论】:

  • 有什么消息吗?如果还是不行,请在 PrettyFaces 论坛上发帖。如果您上传示例应用程序,我相信我们可以为您提供帮助。 ocpsoft.org/support
  • 对于给您带来的不便,我深表歉意,但无论谁给我以“您可以尝试以下操作:index.xhtml 中的链接需要在漂亮配置中重写”的答案,我cant see your answer anywhere, Ive 收到一封电子邮件说 Ive got an answer for my question on Nov 29. The email is as follows: The following items were added to your Stack Exchange global inbox since you last checked it on 2012-11-15: Nov, 29 pretty faces jsf glassfish doesnt 为我工作 回答:您可以尝试以下操作: index.xhtml 中的链接需要在 pretty-config 中重写......
猜你喜欢
  • 2014-04-10
  • 2014-07-16
  • 2012-10-05
  • 2016-11-24
  • 1970-01-01
  • 2017-09-13
  • 2011-05-25
  • 2015-03-30
  • 2010-11-18
相关资源
最近更新 更多