• 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

how i get selected list data

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
This is my code:

ArrayList<PS_Department> UsersDept = serverFunc.adminLib.GetDepartmentsByCurrentUser();
int[] selectedDepts = new int[UsersDept.size()];
int i = 0;
for (PS_Department dept : UsersDept) {
selectedDepts[i]= dept.getID();
i++;
}

theForm.setSelectedDeptIds(selectedDepts);
here i got all the department value As a selected value.but i want only those selected value which is selected by user.how can i got those selected value.
Please help....
 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
not sure I fully understand what you want to accomplish:

first off to create an array from a list is as simple as this:
list.toArray(); that will create an object array for you... API = your friend.

When the form is submitted it will submit the values checked so your jsp. First before you load the jsp put your complete ArrayList in the request and iterate over that to create your checkboxes in your jsp and give the checkboxes their value.

jsp code


once you submit, your form's array will be populated with all the ids that have been checked and you can do your processing from there.
 
Raj
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply.
Actually i am using MultiSelect List Box.And I got all the value as a selected in my jsp page.

here is my code.
ArrayList<PS_Department> UsersDept = serverFunc.adminLib.GetDepartmentsByCurrentUser();
int[] selectedDepts = new int[UsersDept.size()];
int i = 0;
for (PS_Department dept : UsersDept) {
selectedDepts[i]= dept.getID();
i++;
}
After ittrating i got all the value as a selected value in my jsp page.
is there any way to check only those selected value?
 
Nick Williamson
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
same concept, you need to populate the values of the select with the list, don't set the values on the form. What you are doing, you're setting the values on the form so when the page loads all options will be selected.

1. DO NOT create an array from the list and set it on the form!
2. The array is going to be data filled from the form submit DON'T SET IT
3. Your select tag should use a list in the request or on the form, not the array from the from, that array is only to capture what is sent when the form is submitted.

 
Raj
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks again.
In my action class i want to put one condition so that it will store only selected value rather than all value.
my code
ArrayList<PS_Department> UsersDept = serverFunc.adminLib.GetDepartmentsByCurrentUser();
int[] selectedDepts = new int[UsersDept.size()];
int i = 0;
for (PS_Department dept : UsersDept) {
selectedDepts[i]= dept.getID();
i++;
}

see after for loop i got all the value and store in SelectedDepts[i].So here SelectedDepts[i]i want to store only those value which is selected.Please help.
 
Nick Williamson
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have no idea what you are talking about anymore. From your original question it makes no sense, the thing I have shown you should work the way you want. The way you get a list from the user is to have them submit the form to your action and then your array would only have the ids that were selected. I can't help you anymore with the information you have given. I see your code and that doesn't make sense to me either, all you are doing is creating an array of ids that are in your original list. That doesn't make sense. you have to have something to compare it to.
 
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rajm: I will give you some leeway on your English and I am sure that it was a mistake that you posted several threads with this same question. Nick is trying to help out, but posting what looks like the same few lines of code 3 times is not helping anybody understand your question. Step back, think about what you are trying to do and then post a follow up to this thread that does not contain any code.

- Brent
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic