如何输出EL为例 [英] How to output EL as example

查看:62
本文介绍了如何输出EL为例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为JSF创建Facelet组件,以供公司中的其他开发人员使用。为了帮助这些人,我们设置了示例页面,您可以在其中查看工作示例以及在其他页面中复制,粘贴和修改的源代码。



我需要显示一个如何在属性中使用EL的示例,但是如果没有诸如#p $

  attribute =< h:outputText value =# /> 
< h:outputText value = { />
< h:outputText value = myExpression /> ;
< h:outputText value =} />

这种方式有效,但对我来说却很沉闷。如何实现更精简和/或更清洁的目标?

解决方案

来自表达式语言规范2.2版


要生成文字值,其中
包含字符序列 $ {
#{ ,开发人员可以选择
使用复合表达式,如下所示

  $ {'$ {'} exprA} 
#{'#{'} exprB}

然后,结果值将是
字符串 $ {exprA} #{exprB}

或者,转义字符
\ $ \#可用于转义
,否则将其视为
eval表达式。给定
文字表达式:

  \ $ {exprA} 
\#{exprB}



I am creating Facelet components for JSF to be used by other developers in my company. To help those, we have example pages set up, where you could see working examples and the source code to copy, paste and modify in other pages.

I need to show an examples of how to use EL in attributes, but I cannot get the EL to be printed out as String without an ugly workaround like

attribute="<h:outputText value="#"/>
<h:outputText value="{"/>
<h:outputText value="myExpression"/>
<h:outputText value="}"/>"

It works this way, but looks pretty dull to me. How to achieve my goal leaner and/or cleaner?

解决方案

From the Expression Language Specification Version 2.2 :

To generate literal values that include the character sequence "${" or "#{", the developer can choose to use a composite expression as shown here:

${'${'}exprA}
#{'#{'}exprB}

The resulting values would then be the strings ${exprA} and #{exprB}.

Alternatively, the escape characters \$ and \# can be used to escape what would otherwise be treated as an eval-expression. Given the literal-expressions:

\${exprA}
\#{exprB}

这篇关于如何输出EL为例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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