是否建议对所有内容都使用 h:outputText? [英] Is it suggested to use h:outputText for everything?

查看:19
本文介绍了是否建议对所有内容都使用 h:outputText?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 JSF 的新手(4 天前才开始学习),我对 h:outputText 的用法有点困惑.我知道这是一个简单的标签,但在我见过的大多数示例中,它用于输出非常简单(无需转义)的非 i18n 文本.例如(取自此处)

I'm new to JSF (just started learning about it 4 days ago) and I'm a bit confused about the usage of h:outputText. I know that is a simple tag, but in most examples I've seen, it's used to output very simple (no need to escape), non-i18n text. For example (taken from here)

<h:outputText value="Transport" />

可以用

Transport 

所以,我想知道我是否遗漏了什么,或者我看到的大多数示例是否过于复杂到了疯狂的地步.

So, I'm wondering if I'm missing something or if most of the examples I've seen are overcomplicated to the point of insanity.

推荐答案

如果您将 JSF 2.x 与 Facelets 2.x 而不是 JSP 一起使用,则两者同样有效.更重要的是,Facelets 将内联内容隐式包装在由 表示的组件中(换句话说,它被转义!).

If you're using JSF 2.x with Facelets 2.x instead of JSP, then both are equally valid. Even more, Facelets implicitly wraps inline content in a component as represented by <h:outputText> (in other words, it will be escaped!).

仅当您想使用 escape="false" 禁用转义,或想分配 idstyleonclick 等以编程方式,或者想使用转换器(通过 converter 显式或通过 forClass 隐式),那么你需要 <h:outputText>.

Only whenever you'd like to disable escaping using escape="false", or would like to assign id, style, onclick, etc programmatically, or would like to use a converter (either explicit via converter or implicit via forClass), then you need <h:outputText>.

我自己不会在没有必要时使用 .没有它,源代码变得更好可读.您可以像这样在模板文本中内联 EL #{bean.text} 而不是执行 <h:outputText value="#{bean.text}">.在 JSF 2.0 之前,在 JSP 和 Facelets 1.x 中,这是不可能的,因此 是强制性的.如果您的 IDE 对此发出警告,则很可能是配置/考虑了 JSF 1.x.

I myself don't use <h:outputText> whenever it is not necessary. Without it, the source code becomes better readable. You can just inline EL in template text like so #{bean.text} instead of doing <h:outputText value="#{bean.text}">. Before JSF 2.0, in JSP and Facelets 1.x, this was not possible and thus the <h:outputText> is mandatory. If your IDE gives warnings on this, it's most likely JSF 1.x configured/minded.

这篇关于是否建议对所有内容都使用 h:outputText?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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