链接导航未检测 JSF 2.0 Facelets 页面中的模板

发布于 2024-12-21 09:25:23 字数 1141 浏览 0 评论 0原文

<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:ui="http://java.sun.com/jsf/facelets">

<h:body>
    <title><ui:define name="title">Page 2</ui:define></title>
    <ui:composition template="template/common/commonLayout.xhtml">
        <ui:define name="content">
            This is the content of Page 2 page<br/>
            <h:form prependId="false">
                <h:commandButton id="goToIndex" value="Go to Index" action="index" />
            </h:form>
            <a href="index.xhtml">Index</a>
        </ui:define>

    </ui:composition>

</h:body>
</html>

我有两个相同的facelets 页面:index.xhtml 和page2.xhtml,它们相互链接。我还有一个模板文件。除了标题中的页面名称、内容文本和 commandButton 值之外,index 和 page2 之间的代码没有任何区别。

当我单击表单实现的 goToIndex 按钮导航到index.xhtml 时,一切都按预期工作:它转到index.xhtml。但是,当我单击 [a href] 链接实现的链接导航到index.xhtml 时,它会转到index.xhtml,但似乎忽略页面的所有模板设置,包括任何表单标记。唯一呈现的是限制在“内容”定义中的文本,但没有任何 css 格式。

这件事是双向发生的。 “index -> page2”和“pag2 -> index”

知道为什么会发生这种情况吗?

<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:ui="http://java.sun.com/jsf/facelets">

<h:body>
    <title><ui:define name="title">Page 2</ui:define></title>
    <ui:composition template="template/common/commonLayout.xhtml">
        <ui:define name="content">
            This is the content of Page 2 page<br/>
            <h:form prependId="false">
                <h:commandButton id="goToIndex" value="Go to Index" action="index" />
            </h:form>
            <a href="index.xhtml">Index</a>
        </ui:define>

    </ui:composition>

</h:body>
</html>

I have two identical facelets pages: index.xhtml and page2.xhtml which link to each other. I also have a template file. There is no difference in the code between index and page2, apart from the name of the pages in the title, content text and commandButton values.

When I click on the goToIndex button implemented by the form to navigate to index.xhtml, everything works as expected: it goes to index.xhtml. However, when I click on the link implemented by the [a href] link to navigate to index.xhtml, it goes to index.xhtml but seems to ignore all the template settings for the page, including any form tag. The only thing rendered is the text confined in the "content" definition, but without any css formatting whatsoever.

This thing happens both way round. "index -> page2" and "pag2 -> index"

Any idea why this occurs?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

_畞蕅 2024-12-28 09:25:23

调用的页面未由 faces servlet 处理,因此未正确翻译且不包含 css/js。

查看您的 web.xml 并检查 faces servlet 的映射方式。在那里您可能会发现类似的内容:

<servlet-mapping>
  <servlet-name>Faces Servlet</servlet-name>
  <url-pattern>/faces/*</url-pattern>
</servlet-mapping>

您可以将模式更改为:

<url-pattern>*.xhtml</url-pattern>

然后所有带有 xhtml 前缀的文件将由 faces servlet 处理。但是,如果在您的项目中 xhtml 前缀用于 Facelet 之外的其他目的,这可能会导致问题。

另一种方法是使用 h:link 而不是 a:href

<h:link value="Index" outcome="index" >

其中结果属性采用不带 .xhtml 的目标页面。

The page that is called by <a href ...> isn't processed by the faces servlet and therefore not correctly translated and no css/js included.

Look in your web.xml and check how the faces servlet is mapped. There you might find something like:

<servlet-mapping>
  <servlet-name>Faces Servlet</servlet-name>
  <url-pattern>/faces/*</url-pattern>
</servlet-mapping>

You could change the pattern to:

<url-pattern>*.xhtml</url-pattern>

Then all files with the xhtml prefix will be processed by the faces servlet. However this could cause problems if in you project the xhtml prefix is used for other purposes than facelets.

Another way would be to use h:link instead of a:href:

<h:link value="Index" outcome="index" >

where the outcome attribute takes the target page without .xhtml.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文