Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

adding a SelectItem object at particular index position in java.util.list

 
srikanth Thandra
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I am having a Select Box in JSF with select options like Gender,Employee,Associate.
Now select box list contains 3 items with index 0 -- Gender,index 1 -- Employee and index 3 -- Associate.
Based on our requirement when user selects a select item and clicks a button i need to delete the selected option from select box i.e if user selects Employee and submits, select box shows only Gender And Associate.

Now what i want is, can the deleted Employee object will be added back at the same index position as it is like before when a previous button is clicked.

Up to now what i have done i am maintaining two lists one parent list and another selected items list.When user selects one item from parent list and clicks submit button i am removing the selected item from parent list and adding it into selected items list.
When user clicks previous button i am removing from the selected items list and adding into the parent list. But the added one is coming at last position
 
Manoj Kumar Jain
Ranch Hand
Posts: 198
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not sure if I am addressing your problem but what I understand from your query I can suggest you one solution.

You need to maintain one more master list that is having all the list items in order you want, don't remove any item on selection from this list.

Initially show all the items from this master list. when user clicks on the submit button the logic will almost remain same, but when when user clicks on previous button just check your master list with the selected list. Now show the items form the master list. If masterlist.item==selectedlist.item then skip that item from showing in the box. also update your parent list at this time with the current items.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic