Thursday, February 10, 2011

Displaying different Images in ADF table based on some condition Part-II

In my last blog Displaying different Images in ADF table based on some condition Part-I  I have explained how to use Switcher component to select some conditions.
af:Switcher component is very useful for conditional operations.
One example where Switcher component can be used is :
Suppose in the below table we want to add one column in the starting with checkbox in it. Now we want this checkbox to visible only when there is any Error or  when Status is "E". In this case we can use Switcher component in the same way as explained in my last blog and just keep Rendered = true for Error(initially set Rendered = false). I quoted the  above scenario because i personally like using af:Switcher component in different scenario.


I was wondering if we can achieve displaying Images in ADF tables based on some condition, with lesser effort and without using af:Switcher component and i found a very interesting trick.

we are getting "S" or "E" in the statrus column. so what i will do, i will rename the two images success.gif and failure .gif to S.gif and E.gif respectively.

Now in place of using af:Switcher component we will directly use af:image component.
but the trick lies in selecting the image based on its name.
In #{row.StatusFlag} we will get "S" or "E" as values. so in image source in place of directly writing the name of the image we will write the value of StatusFlag and append.gif. so now the image will be decided at runtime based on the value of the StatusFlag.
Below is the source code of the column:


<af:column sortProperty="StatusFlag" sortable="true"
                   headerText="#{bindings.SerachResultVO1.hints.StatusFlag.label}"
                   id="c2" align="center" width="100">
                   <af:image source="/images/#{row.StatusFlag}.gif" id="i1"/>
</af:column>

we will get the same result as we got in our earlier example:


Oracle JDeveloper 11g Handbook: A Guide to Fusion Web Development (Osborne ORACLE Press Series)





No comments:

Post a Comment