使用Facelets模板导航不起作用 [英] Navigation with Facelets template not working

查看:84
本文介绍了使用Facelets模板导航不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Facelets时导航出现问题.

I'm having some trouble with navigation when using Facelets.

我的主模板位于/WEB-INF:

<h:body>
    <div id="container">
        <div id="header">
            <ui:insert name="header">Header</ui:insert>
        </div>

        <div id="navigation">

            <a href="ram.xhtml">RAM</a>
            <a href="mobo.xhtml">Motherboard</a>
            <a href="video.xhtml">Video Card</a>
        </div>

        <div id="content">
            <ui:insert name ="content"></ui:insert>
        </div>

    </div>
</h:body> 

,然后是两个外观完全相同的模板客户端,分别是index.xhtmlram.xhtml:

and then 2 template clients that look exactly the same, index.xhtml and ram.xhtml:

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="./WEB-INF/layoutTemplate.xhtml">

    <ui:define name="header">
       some text
    </ui:define>

    <ui:define name="content"> 
        some content
    </ui:define>


</ui:composition>

如果在web.xml中将这些页面中的任何一个设置为欢迎页面,则将使用CSS和所有内容正确呈现它们.但是,如果我尝试使用链接从一个页面导航到另一页面,则会得到

If either of these pages are set as the welcome page in the web.xml, they are rendered correctly, with CSS and everything. But if I try to navigate from one page to the other using the link I get

此XML文件似乎没有与之关联的任何样式信息.文档树如下所示.

This XML file does not appear to have any style information associated with it. The document tree is shown below.

任何提示将不胜感激.

推荐答案

这意味着请求URL(在浏览器地址栏中显示)与web.xml中定义的FacesServlet的URL模式不匹配.

This means that the request URL (as appears in browser address bar) didn't match the URL pattern of the FacesServlet as definied in web.xml.

那些链接

<a href="ram.xhtml">RAM</a>
<a href="mobo.xhtml">Motherboard</a>
<a href="video.xhtml">Video Card</a>

期望要在*.xhtml上映射的FacesServlet.但是,如果出于某些原因(例如,强烈建议将其映射到*.jsf并将其更改为*.xhtml)不是一种选择,那么您就需要修复链接

expects the FacesServlet to be mapped on *.xhtml. But if it's mapped on for example *.jsf and changing it to *.xhtml is not an option for some reason (I however strongly recommend it), then you'd need to fix the links

<a href="ram.jsf">RAM</a>
<a href="mobo.jsf">Motherboard</a>
<a href="video.jsf">Video Card</a>

或者更好的是,只需使用<h:link>.它将隐式附加适当的上下文路径和FacesServlet映射:

Or, better, just use <h:link>. It'll implicitly append the proper context path and FacesServlet mapping:

<h:link value="RAM" outcome="ram" />
<h:link value="Motherboard" outcome="mobo" />
<h:link value="Video Card" outcome="video" />

另请参见:

  • JSF 2.0中的通信-隐式导航
  • See also:

    • Communication in JSF 2.0 - Implicit navigation
    • 这篇关于使用Facelets模板导航不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆