1

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 Answer 1

3

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'}" />
Sign up to request clarification or add additional context in comments.

1 Comment

thanks for your reply. it seems that it will be work. but how could i make it customizable? i mean that read tag name and their setting from some configuration at runtime?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.