字符串中的jsf动态标签 [英] jsf dynamic tag from string

查看:78
本文介绍了字符串中的jsf动态标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想向用户显示一些数据

i want to show some data to the user

数据可能由基于配置的不同JSF标签向用户表示

the data maybe represented to user by different JSF tags based on a configuration

例如,有时它可能由文本

for example some times it may represented by text

表示,有时可能由图形符号甚至图表表示

and sometimes it may represented by graphical symbol or even chart

我也希望这种表示形式可自定义。

also i want that this representation be customizable.

我该怎么做?

推荐答案

使用渲染的属性。

<h:outputText value="#{bean.value}" rendered="#{bean.datatype == 'text'}" />
<h:graphicImage value="#{bean.value}" rendered="#{bean.datatype == 'image'}" />
<x:someChart value="#{bean.value}" rendered="#{bean.datatype == 'chart'}" />

只要渲染的属性中的布尔表达式计算结果为 true ,该组件将被渲染(显示),否则将被渲染(隐藏)。在上面的示例中, Bean#getDataType()应该返回 String Enum

Whenever the boolean expression in the rendered attribute evaluates to true, the component will be rendered (displayed), otherwise not (hidden). In the above example the Bean#getDataType() should return a String or an Enum.

以下是在EL中如何使用布尔表达式的另一个示例:

Here are another examples of how to use boolean expressions in EL:

<h:someComponent rendered="#{bean.booleanValue}" />
<h:someComponent rendered="#{bean.intValue > 10}" />
<h:someComponent rendered="#{bean.objectValue == null}" />
<h:someComponent rendered="#{bean.stringValue != 'someValue'}" />
<h:someComponent rendered="#{!empty bean.collectionValue}" />
<h:someComponent rendered="#{!bean.booleanValue && bean.intValue != 0}" />
<h:someComponent rendered="#{bean.enumValue == 'FOO' || bean.enumValue == 'BAR'}" />

这篇关于字符串中的jsf动态标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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