Posting a list box in struts

B

Ben Jessel

Hi,

I have two list boxes that look like this:

user_list
--------- ---------
|user a| |user f |
|user b| >> | |
|user c| > | |
|user d| < | |
|user e| << | |
|-------- |--------

[Submit]

On the left are a list of users ( which I load via a custom tag ). I
use the arrows to move the users from one box to the other. The moving
is done with client side code ( javascript ). I want to post all the
data contained in the right box, by clicking the submit button.

I have a getter in my struts form called getUser_list which is of type
list.
But ( as you wise struts developers know ), only the values that have
been selected / highlighted will actually be passed back. I want the
whole list box to be returned. My options, as I see it are:

a) Write code to highlight all the elements in the listbox in the
onSubmit() part of the form.
b) Do the whole moving backward and forwards of the users as server
side, returning to this page after the update, and reloading the data.

Does anyone have any suggestions?

Thanks

Ben
 
S

Scott Yanoff

Ben said:
a) Write code to highlight all the elements in the listbox in the
onSubmit() part of the form.
b) Do the whole moving backward and forwards of the users as server
side, returning to this page after the update, and reloading the data.

I recommend the first option. I think it is quicker for the user not to
have to wait for the refresh and the server to continually process the
movement of data between select boxes. The con is that you are going to
have to rely on client-side JavaScript, which most browsers support but
that a user can turn off.

I had to deal with an application (non-struts) that did the same thing
and in looking back at the old code, onSubmit I called a JavaScript
function that just checked to make sure that the list box was not empty
and then it looped through each element, which may have been the trick
needed to select everything.

function nextPage(form) {

var listBoxLength = form.current.options.length;
var dataList= form.current;

if ((listBoxLength <= 1) && (dataList.options[0].value == "")) {
alert ("Please select at least 1 entry from the list on the left.");
return false;
}

// I'm not sure why we have to assign variables to the elements in
this loop:
for (var i=0; i < listBoxLength; i++) {
var fundname = dataList.options.text;
var fundvalue = dataList.options.value;
}
return true;

}

HTH,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top