• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to remove duplicated headers in SelectItemGroup  RSS feed

 
Omar Ali
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I need your assistant and help in removing the repeated group header in the arraylist while showing a selectonemenu in jsf. I have an arraylist which should show two group headers (Type A & Type B) for the selectonemenu. Below each group header, there will be some values and they are (Name,Code). Currently the Type A & Type B is showing above each value which it is being shown in the selectonemenu, so how to make to be shown only once at the top of the group. My code is below:


I tried to keep the above the while loop and it is repeating only the first record and the Type A many times.
 
Carey Brown
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You create a new ArrayList on line 2, and then overwrite it on line 25. Also, on line 25 you create the new ArrayList for each item in the result set, overwriting the one created in the prior iteration through the result set. I'm not sure what you're trying to accomplish here. Can you give us more info, perhaps a mockup of what you expect the output to look like vs. what you're actually getting?
 
Omar Ali
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply.

What I am trying to do here is that I am trying to do grouping in the selectonemenu item. While clicking on it it should show "Type A" as a group header and then it should show the retrieved names (retrieved from Query 1) and then it should show "Type B" and below the group header is the values (retrieved from Query 2). I am trying to do something similar to the below example, however instead of fixed values, I want to retrieve from the database:



Here is an example of the static, however my issue is how to do that by retrieving the values from the database:



Thanks
 
Carey Brown
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have this:

You've left out some code (e.g. SelectItemGroup) so it's hard to propose a solution.
Does this help?

Assuming SelectItemGroup is something you've written, you might want an add(SelectItem) method.
 
Omar Ali
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Carey,

Thanks for your solution, I tried your code but unfortunately the group headers are not shown in the drop down.

I tried to change the code and to make it similar to yours:



However this time, I took the piece of code:



and I have added it above the while statement. It showed me the group headers but below them I can see an unknown reference. Have a look below:

Type A
[Java@1234SelectItem
SSS
AAA
BB
Type B
[Java76565SelectItem987
DDD
ZZZ
WWW

So how to exclude it.

Thanks
 
Carey Brown
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you overloaded your add() method? You seem to have one that takes SelectItem as an argument, and another on that takes a SelectItemGroup. Not sure what affect you're looking for by adding a SelectItemGroup, seems like this is the cause of your [Java@1234SelectItem.
 
Omar Ali
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So what do you suggest to do ?
 
Carey Brown
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Omar Ali wrote:So what do you suggest to do ?

Explain why you are adding a SelectItemGroup. What happens if you omit this call entirely?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!