aspose file tools
The moose likes JSF and the fly likes Empty space caused by rendered attribute Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » JSF
Reply Bookmark "Empty space caused by rendered attribute" Watch "Empty space caused by rendered attribute" New topic
Author

Empty space caused by rendered attribute

Paolo Pinkel
Ranch Hand

Joined: May 04, 2011
Posts: 35
How can I get rid of the empty space by components not rendered via rendered attribute?

I want to display a list of objects in a dataTable and sort them by a property they have. I do it likes this:
It will display one item every row only, because of the rendered thingy. How can I avoid this? I stumpled upon this also on other occasions...

Thank you!
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 14491
    
    7

I'm not sure what you mean here. If you're hoping that empty rows won't display, it's not a rendering issue. For that you just need a datamodel that excludes the empty rows. Since it's a table, the number of columns is fixed, whether data is rendered or not.

There can be problems with JSF doing annoying things with "unimportant" things like XML comments (treating them as though they are display elements, taking up cell slots), but that can be switched off by a web.xml setting.


Customer surveys are for companies who didn't pay proper attention to begin with.
Paolo Pinkel
Ranch Hand

Joined: May 04, 2011
Posts: 35
Thanks for your reply!

I'm not sure if I managed to explain my problem properly.

I want a table that has two columns. The first column should only display the values that have "A" as a property value, the second column should only display values that have "B" as a property value.

This is how I imagine it to be:

But this is what the code I pasted in the start pasting will produce:

I understand why it looks like this... but how can I achieve the first appearance?

I run across this problem often (I also try to have a grouped selectManyCheckbox or selectOneRadio using Tomahawks spread attribute with the same issue).

Am I thinking wrong? There must be an easy solution...

I guess I could just use two dataTables and two getters (one that only returns the A and one that only returns the B attributes) and try to display them next to each other somehow. But for selectManyCheckbox and selectOneRadio: I can't just have two of these with different value attributes, because the chosen values should be mapped to the same property. Hm. So two input components are no option in this case.

Thanks everyone!
Paolo Pinkel
Ranch Hand

Joined: May 04, 2011
Posts: 35
I can't believe no one knows any solution. Grouping elements by a property in a selectOneMenu or selectManyCheckbox seems like a common task to me. :O

For dataTables... okay, I can render more than one table. But for a select* component? I can't just render many... hm.
Guy deLyonesse
Ranch Hand

Joined: Apr 12, 2011
Posts: 189

I think the problem may be that you're trying to display data in a manner that is contrary to the way data is modeled, if I understand you correctly.

In a Data Table the rows represent individual items in the data set. If such an item has a value for attribute 'A' and not 'B' then that row will have an empty cell in column 'B' regardless. If you want that space to disappear by shifting the cells up from the next item that has a value for attribute 'B,' then it breaks the data model because it's displaying data from separate elements in the same data row. If, for some reason, you absolutely must display things in this way then the only way to do it is to render two separate data sets and display them in separate data tables and just place them next to each other on the page.
Paolo Pinkel
Ranch Hand

Joined: May 04, 2011
Posts: 35
Thanks for your reply!

For dataTables... yes, I can just display more than one.

But I have the same problem with selectOneRadio and selectManyCheckbox. Imagine a situation like this: You want the user to choose a car. You have four brands. What I want is a selectOneRadio or selectManyCheckbox that will just group them. It's still a List<Car>. And I still want it to be attached to one property.



I can't render four selectOneRadio/selectManyCheckbox (if the user can choose more than one car) in this case, because it still should have the same value attribute. I just want to group them for the user. I could use Tomahawk's spread attribute, but in the end I just would end up having a dataTable for each (with the gaps rendered).
Guy deLyonesse
Ranch Hand

Joined: Apr 12, 2011
Posts: 189

A control like selectManyCheckbox displays data items based on whatever data set is passed to it. It doesn't do any processing on its own. Therefore, however you want to group the data it needs to be done in the bean that's handling it.

The source data should be an Array of SelectItems.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Empty space caused by rendered attribute
 
Similar Threads
Get the count of selectted checkbox
JSF dataTable parameter call problem
How to dynamically set panel header on a condition using <f:facet
datatable - row colors
InputText in DataTable does not store value