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

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

问题描述

我是JSF的新手(四天前才开始学习它),并且对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将内联内容隐式包装在以<h:outputText>表示的组件中(换句话说,将转义!).

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等时,或者想使用转换器(通过或通过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>.

我自己在不需要时不使用<h:outputText>.没有它,源代码将变得更易读.您可以像这样按#{bean.text}内嵌EL到模板文本中,而不用执行<h:outputText value="#{bean.text}">.在JSF 2.0之前,在JSP和Facelets 1.x中,这是不可能的,因此<h:outputText>是必需的.如果您的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天全站免登陆