• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Empty space caused by rendered attribute

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Saloon Keeper
Posts: 27752
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Paolo Pinkel
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 200
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 200
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Put the moon back where you found it! We need it for tides and poetry and stuff. Like this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic