File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSF and the fly likes How to display text using outputText conditionally in the DataTable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "How to display text using outputText conditionally in the DataTable" Watch "How to display text using outputText conditionally in the DataTable" New topic
Author

How to display text using outputText conditionally in the DataTable

Amitkumar Fulambarkar
Greenhorn

Joined: Sep 17, 2008
Posts: 29
Hi,

I am iterating a list and displaying the data in the DataTable. However, The list has the objects with the boolean values. I want to display some string value depending on the boolean value in the datatable.


I tried to implement the customized convertor as below. However, my convertor doesn't get called. I don't see any error in the log too. Can someone please suggest if I am doing any wrong.



JSP:



faces-config.xml



Regards
Amit
Amitkumar Fulambarkar
Greenhorn

Joined: Sep 17, 2008
Posts: 29
Can anybody help me on this, please?
Ilya Kudelin
Greenhorn

Joined: Aug 24, 2011
Posts: 7
Take a look at 'rendered' parameter of JSF tags
<hutputText value="smth" rendered="false"/> will not be displayed at the page.
You also can use property from backing bean that has type boolean.

Amitkumar Fulambarkar
Greenhorn

Joined: Sep 17, 2008
Posts: 29
I didn't get this.

How rendered attribute comes into picture? How is it related to Convertor? I know if we set the rendered="false" it won't render the component on UI.However, not sure how it applies to my case.

Please elaborate your views.

Thanks
Amit
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16019
    
  20

It's not usually worth the trouble to build a converter for boolean displays. It's easier to just provide 2 outputTexts, one for true and one for false and switch them on and off by their "rendered" attributes:


As far as your converter is concerned, I don't see anything wrong, so it may be you mis-capitalized something or made some other non-obvious mistake in the specs.


Customer surveys are for companies who didn't pay proper attention to begin with.
Ilya Kudelin
Greenhorn

Joined: Aug 24, 2011
Posts: 7
Tim Holloway wrote:It's easier to just provide 2 outputTexts

Also, you can use <h:panelGroup rendered="boolean"> to hide or display a bundle of objects(links,forms,messages,ui:repeats).
Amitkumar Fulambarkar
Greenhorn

Joined: Sep 17, 2008
Posts: 29
Thank you all.

I have some scenarios wherein I need to make the Convertor implementation working in my project. For this scenario, I dropped the idea to use Convertor. I replaced the properties in the bean from boolean to String and managed to set the values 'X' and empty string in the bean itself.

The idea to use the boolean value for rendered attribute was good. However, this doesn't applies to my case. In my case I am iterating a list and displaying the data in DataTable.
So rendered attribute will not help here.

I am still fighting with getting the convertor working for one more scenario. Here is my situation, while iterating the list, if the data for the property is null, I have to keep the column empty,however, if it is not null value I have to display as '*'.

Does the <f: Covertor> works in datatable?

Could you give me some specific pointers to cross check?

Thanks
Amit
Amitkumar Fulambarkar
Greenhorn

Joined: Sep 17, 2008
Posts: 29
Could some one help me out with this, please?
 
Consider Paul's rocket mass heater.
 
subject: How to display text using outputText conditionally in the DataTable