在XHTML页面中包含另一个XHTML页面的最正确方法是什么?我一直在尝试不同的方式,但都没有.
一直试着学习JSF,有时候我看到的URL *.jsf有时是*.xhtml或者/faces/*.请问有人填写我的知识吗?当我使用Facelet创建JSF时,文件扩展名是.xhtml,所以.jsfURL扩展来自哪里?
我已经完成了关于Facelets模板的教程.
现在我尝试创建一个与模板不在同一目录中的页面.我有页面样式的问题,因为样式用相对路径引用,如下所示:
<link rel="stylesheet" href="style_resource_path.css" />
Run Code Online (Sandbox Code Playgroud)
我可以通过以下开头使用绝对引用/:
<link rel="stylesheet" href="/project_root_path/style_resource_path.css" />
Run Code Online (Sandbox Code Playgroud)
但是,当我将应用程序移动到不同的环境时,这将给我带来麻烦.
所以我想知道在Facelets中引用CSS(以及JS和图像)资源的最佳方法是什么?
我正在学习JSF 2,感谢我在这么短的时间里学到了很多东西.
我的问题是关于如何为我的所有JSF 2页面实现一个公共布局,并且每当我从另一个面板单击一个链接/菜单时,只有页面的内容部分不刷新整个页面.我使用Facelets方法它做了我想做的事情,除了每次我点击一个面板的链接(例如左面板的菜单项)时,整个页面都会刷新.我正在寻找的是一种只刷新页面内容部分的方法.为了说明这一点,我的目标是pagelayout.
没有发布我的代码,因为我不确定Facelets是否可以这样做.除了Facelets之外,还有其他方法更适合我的要求吗?
我有一些Facelets文件,如下所示.
WebContent |-- index.xhtml |-- register.xhtml |-- templates | |--userForm.xhtml | `--banner.xhtml :
两个页面都使用/templates目录中的模板.我/index.xhtml在浏览器中打开了.我得到生成的HTML输出.我在/index.xhtml文件中有一个链接/register.xhtml文件.但是,我/register.xhtml没有被解析并返回为普通的XHTML/raw XML而不是生成的HTML输出.当我在浏览器中右键单击页面并执行查看页面源代码时,我仍然看到XHTML源代码而不是生成的HTML输出.看起来模板没有得到应用.
但是,当我在浏览器的地址栏中打开#{...}相似内容<h:body>时,它会正确显示.这是怎么造成的,我该如何解决?
我想将我的JSF 2.0 xhtml文件放在WEB-INF\jsf下.我如何访问它们呢?我知道WEB-INF内部的任何内容都没有暴露在外面,所以我需要一个控制器来将我重定向到相应的JSP,对吧?(这也是模型2模式iirc).
我可以使用web.xml/faces-config.xml中的参数来实现这一点吗?我认为FacesServlet是我的webapp的控制器所以它应该用于此目的?
另一个理解模型2模式的问题.是否每个操作都必须首先进入servlet,然后处理下一个可能的步骤?因此,<a href="anotherPage.html" />在这种模式中禁止使用简单,因为它不会进入控制servlet?
我正在使用JBoss 7.1和JSF 2.1/Prime Faces并继续遇到标题中列出的错误.我已经尝试了很多这里提出的建议,但最终都出现了同样的错误.
文件结构是:
WEB-INF
faces
login.xhtml
Run Code Online (Sandbox Code Playgroud)
我在web.xml中有以下内容:
<display-name>clientAccountManager</display-name>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<context-param>
<param-name>javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL</param-name>
<param-value>true</param-value>
</context-param>
Run Code Online (Sandbox Code Playgroud)
我正在使用以下URL访问该文件:
http://localhost:8080/clientAccountManager/faces/login.xhtml
Run Code Online (Sandbox Code Playgroud)
我还将URL模式更改为*.xhtml并使用:
http://localhost:8080/clientAccountManager/login.xhtml
Run Code Online (Sandbox Code Playgroud)
结果相同.
我错过了什么?
到目前为止,我在书或教程中看到的每个项目示例都将XHTML(Facelets)页面与WEB-INF目录放在同一级别上.我还读过,为了让服务器上的页面无法直接访问,你需要将它们隐藏在WEB-INF目录下,这意味着需要某种视图解析器.我的问题是,我该怎么做?
我们如何将多个xhtml页面包含在摘要页面中.这里所有的xhtml页面都包含相同的模板.
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:ui="http://java.sun.com/jsf/facelets">
<head>
<title> SNS </title>
<meta http-equiv="expires" content="0"/>
<meta http-equiv="pragma" content="no-cache"/>
<meta http-equiv="cache-control" content="no-cache"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" href="sns.css" type="text/css" />
</head>
<h:body>
<div id="header">
<ui:insert name="commonHeader">
<ui:include src="header.xhtml" />
</ui:insert>
</div>
<div id="content">
<ui:insert name="commonBodyContent">
Common Body Content.
</ui:insert>
</div>
<div id="footer">
<ui:insert name="commonFooter">
<ui:include src="footer.xhtml" />
</ui:insert>
</div>
</h:body>
</html>
Run Code Online (Sandbox Code Playgroud)
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
template="commonTemplate.xhtml">
<ui:define name="commonBodyContent">
.........;
..........;
</ui:define>
</ui:composition>
Run Code Online (Sandbox Code Playgroud)
<ui:composition …Run Code Online (Sandbox Code Playgroud) 我在这里找到了一个想法,将文件放在/ WEB-INF下是一种阻止直接访问的方法:
使用Facelets,还可以将XHTML文件放在/ WEB-INF下,如果它们是模板或包含文件(基本上与JSP相同的限制).
该页面还提供了基于Java EE安全性的解决方案,该解决方案仅允许直接XHTML访问特定用户组的成员.
<security-constraint>
<display-name>Restrict XHTML Documents</display-name>
<web-resource-collection>
<web-resource-name>XHTML</web-resource-name>
<url-pattern>*.xhtml</url-pattern>
</web-resource-collection>
<auth-constraint>
<description>Only let 'developer's access XHTML pages</description>
<role-name>developer</role-name>
</auth-constraint>
</security-constraint>
Run Code Online (Sandbox Code Playgroud)
您会推荐其中一种解决方案,还是一般都使用?
我使用Primefaces DialogFramework与
我的问题是,如果用户知道我的对话框的位置,他可以直接通过URL访问它.我不希望这是可能的,所以我认为它可以将对话框放在我的web-app的WEB-INF文件夹中,但是现在,如果我想打开对话框,我会得到一个FileNotFound-Exception.
如果我的对话框位于某个常规文件夹中,则可以正常工作
RequestContext.getCurrentInstance().openDialog("/myfolder/mydialog");
// this works as expected
Run Code Online (Sandbox Code Playgroud)
但如果它位于WEB-INF中,则它不再起作用
RequestContext.getCurrentInstance().openDialog("/WEB-INF/mydialog",options,null);
// this is causing a fileNotFoundException
Run Code Online (Sandbox Code Playgroud)
我也尝试为此设置导航规则faces-config但是再次没有成功
<navigation-case>
<from-outcome>mydialog</from-outcome>
<to-view-id>/WEB-INF/mydialog.xhtml</to-view-id>
<redirect />
</navigation-case>
Run Code Online (Sandbox Code Playgroud)
我如何打开位于WEB-INF文件夹中的对话框,或者根本不可能?提前致谢
昨天我发布了一个关于必须按两次按钮才能使其工作的问题.我收到了很好的帮助,这是stackoverflow的标志,但问题仍然存在.我将我的代码减少到最低限度,问题仍然存在.我仔细阅读了BalusC的建议,希望我能在表格中找到一个表格.我肯定没有什么可以看到所以我会发布我的代码,希望额外的双眼会看到一些东西.
我有一个模板,我从welcome(登录部分)调用.这将转到userInfo,它有一个命令按钮.这是我神秘地要按两次的命令按钮.在第二次按下命令按钮将我带到userPhoto.一切都被削减到最小,以便我可以发布它.
master.xthml:
<?xml version="1.0" encoding="UTF-8"?>
<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!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:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>Master template</title>
</h:head>
<h:body>
<p:layout fullPage="true" >
<p:layoutUnit position="north" size="254">
Top
</p:layoutUnit>
<p:layoutUnit position="east" size="50" resizable="true">
Hello
</p:layoutUnit>
<p:layoutUnit position="south" size="30">
south
</p:layoutUnit>
<p:layoutUnit position="center">
<ui:insert name="AreaOne">Default text</ui:insert>
</p:layoutUnit>
</p:layout>
</h:body>
</html>
Run Code Online (Sandbox Code Playgroud)
welcome1.xhtml:
<?xml version="1.0" encoding="UTF-8"?>
<!--
To change this …Run Code Online (Sandbox Code Playgroud) 我正在创建我的第一个facelets/JSF应用程序.在我的第一页中,我添加了一个facelet模板:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!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:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html" xmlns:ui="http://java.sun.com/jsf/facelets">
<f:view>
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Insert title here</title>
</h:head>
<body>
<ui:insert name='top'>
<ui:include src="/templates/template_a.xhtml"></ui:include>
</ui:insert>
</body>
</f:view>
</html>
Run Code Online (Sandbox Code Playgroud)
这是我的模板页面:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!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:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html" xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Insert title here</title>
</h:head>
<body>
<ui:composition template="/inwert_a.xhtml">
<ui:define name="top">
<h2>naglowek</h2>
</ui:define>
</ui:composition>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
但是当我在网络浏览器中查看页面源代码时,我看到了:
<?xml version="1.0" encoding="ISO-8859-1" …Run Code Online (Sandbox Code Playgroud) jsf ×11
facelets ×9
jsf-2 ×6
java ×3
web-inf ×3
primefaces ×2
url-pattern ×2
ajax ×1
ajax-update ×1
dialog ×1
el ×1
include ×1
resources ×1
templating ×1
uiinclude ×1
web.xml ×1
xhtml ×1