哪里放组成组件?(JSF 2.0) [英] Where to put composition components?(JSF 2.0)
问题描述
我正在继续使用JSF 2.0。
我认为模板是一件好事,它有很多优点。但今天我对它有了新的疑问。
I am continuing my practices with JSF 2.0. I see templating is a great thing to do, and it has lots of advantages. But today i got a new doubt related to it.
我为我的网页创建了一个模板。
在模板中,我使用标签 作为不同的部分(这些部分将在稍后的页面中使用组合标记组合实现一个或多个定义标签)。
I created a template for my pages. In the template, i use tags for the parts that are different(Those parts will be implemented later in a page using the composition tag in combination one or more define tags).
<ui:insert name="content" />
同样在模板内部,为了避免在模板中添加太多代码,我创建 标签,用于添加其他一些xhtml。
Also inside the template, to avoid putting to much code in the template, i create tags to add some other chunks of xhtml.
<ui:include src="/languageChanger.xhtml"/>
这是我的文件夹结构的样子:
This is how my folder structure looks:
一切正常就像我一样,但是当我在网址中导航到languageChanger.xhtml时,我看到了xhtml的复合块:
It all works as i spect, but when in the url i navigate to languageChanger.xhtml i see the composite chunk of xhtml:
我的怀疑是:
- 那个独立代码块放在正确的位置吗?或者它是错误的,不应该允许用户从URL中看到它?
-Is that chunk of independent code placed in the right place?, Or it is wrong, the user should not be allowed to see that from the URL?
- 该地方是否保存其他组件,如登录,注册......?
-Is that place save to have other components like login, register...?
- 避免用户直接访问我可以将它放在WEB-INF文件夹中的组件,但是我有一个问题,即include标签找不到路径。我该怎么办?
-To avoid user access directly the component i could place it in WEB-INF folder, but then i have a problem that the include tag does not find the path. What should i do?
- 什么是最佳做法,在哪里放置这些独立的代码块?
-What would be the best practice, where to place this independent chunks of code?
推荐答案
是否有一大堆独立代码放在正确的位置?或者是错误的,不应允许用户从URL?
将它放在 / WEB-INF
。容器不允许直接访问此文件夹。
Put it somewhere in /WEB-INF
. Direct access to this folder is disallowed by the container.
是那个地方保存到其他组件,如登录,注册......?
我不明白你。也许你想说安全而不是保存?你对其他组件是什么意思?
I don't understand you. Perhaps you meant to say "safe" instead of "save"? What do you mean with "other components"?
避免用户访问直接我可以将它放在WEB-INF文件夹中的组件,但是我有一个问题,包含标签找不到路径。我该怎么办?
你的路径显然是完全错误的。 Facelet模板,包含,标签和合成(非复合组件)可以完美地放在 / WEB-INF
中。
Your path was apparently plain wrong. Facelet templates, includes, tags and compositions (not composite components) can perfectly be placed in /WEB-INF
.
什么是最佳做法,在哪里放置这些独立的代码块?
将其放入 / WEB-INF
。最佳做法是使用绝对路径,即使用 /
启动路径。它将相对于webcontent根进行解析。例如
Put it in /WEB-INF
. Best practice is to use absolute paths, i.e. start the path with /
. It will be resolved relative to the webcontent root. E.g.
<ui:include src="/WEB-INF/languageChanger.xhtml" />
只有主页面(URL请求的页面)不能放入 / WEB-INF
。
Only the "main" page (the one which is to be requested by URL) cannot be placed in /WEB-INF
.
这篇关于哪里放组成组件?(JSF 2.0)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!