facelets的ui:include和custom标签之间有什么区别? [英] What is the difference between facelets's ui:include and custom tag?

查看:115
本文介绍了facelets的ui:include和custom标签之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Ui:include和基于xhtml的标签(带有源代码elt的标签)对我来说几乎是相同的.两者都允许重用一块标记.但是我相信每个人都应该有一些理由.有人可以简要解释一下吗? (我想如果我阅读了完整的facelets教程,我将学习它,但是我现在没有时间这样做,所以请不要链接到冗长的文档:)

解决方案

它们非常相似.区别主要是句法上的.

在观察了一段时间后,似乎惯例是您仅在单个情况下使用的片段才是ui:include的候选对象,而您更经常重用且具有更独立语义的片段才是ui:include的候选对象自定义标签.

例如

单个视图可能具有包含三个部分的表单;个人资料,工作经历,偏好.如果页面变得笨拙,可以将其分成较小的部分.这3个部分中的每个部分都可以移到自己的Facelet文件中,然后将包含在用户界面中并包含在原始文件中.

另一方面,您可能有一种特定的方法可以在应用程序的许多视图上的图像上显示.也许您在它周围画了一条线,下面有一些文字,等等.不必一遍又一遍地重复,您可以再次将其抽象到其自己的Facelet文件中.虽然您可以ui:include它,但大多数人似乎更喜欢在此处创建标签,因此您可以使用例如Facelets上的<my:image src="..." />.这样看起来更好(更紧凑,与其他组件更加内联).

在与JSF 2.0捆绑在一起的Facelets版本中,可以将简单标签替换为composite components.这是第三个变种,乍一看看上去很像自定义标签,但是这些东西在技术上有所不同,因为它们不仅是包含,而且还代表具有声明属性的真实组件,将验证器附加到其上的能力等.

Ui:include and xhtml based tag (the one with source elt) seem to be much the same for me. Both allow to reuse piece of markup. But I believe there should be some reason for having each. Could somebody please briefly explain it? (I guess if I read full facelets tutorial I will learn it, but I have not time to do it now, so no links to lengthy docs please :)

解决方案

They are quite similar. The difference is mainly syntactical.

After observing their usage for some time it seems the convention is that fragments that you use only in a single situation are candidates for ui:include, while fragments that you re-use more often and have a more independent semantic are candidates for a custom tag.

E.g.

A single view might have a form with three sections; personal data, work history, preferences. If the page becomes unwieldy, you can divide it into smaller parts. Each of the 3 sections could be moved to their own Facelet file and will then be ui-include'ed into the original file.

On the other hand, you might have a specific way to display on image on many views in your application. Maybe you draw a line around it, have some text beneath it etc. Instead of repeating this over and over again you can abstract this to its own Facelet file again. Although you could ui:include it, most people seem to prefer to create a tag here, so you can use e.g. <my:image src="..." /> on your Facelets. This just looks nicer (more compact, more inline with other components).

In the Facelets version that's bundled with JSF 2.0, simple tags can be replaced by composite components. This is yet a third variant that on the first glance looks a lot like custom tags, but these things are technically different as they aren't merely an include but represent true components with declared attributes, ability to attach validators to, etc.

这篇关于facelets的ui:include和custom标签之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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