jsf dynamic tag from string

∥☆過路亽.° 提交于 2020-04-16 06:25:33

问题


i want to show some data to the user

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.

how could i do this?


回答1:


Make use of the rendered attribute.

<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'}" />

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.

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'}" />


来源:https://stackoverflow.com/questions/3378097/jsf-dynamic-tag-from-string

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!