You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Eric Rizzo <er...@opennetwork.com> on 2001/09/26 20:19:57 UTC

Dual-list UI

Has anyone come up with a good way to implement a dual-list interface using 
Struts?  I mean a UI where there are two lists, a source and a destination, and 
buttons to move items between them.  Obviously, the lists would be created with 
<html:select> tags, and the source list can be populated with <html:option[s]> 
tags.  The big problem I see is how to get the destination list contents into 
the form bean when the form is submitted.  The Action is not interested in what 
is selected in the list, but instead the list's entire contents.

There are JavaScript solutions that I can think of, but I'm hoping that someone 
may have found a way to do it without resorting to that ugliness.

TIA,
	Eric
-- 
Eric Rizzo, Software Engineer
OpenNetwork Technologies
http://www.opennetwork.com
-----------------------------
I embrace my personality flaws, for without them
I might have no personality at all.


Re: Dual-list UI

Posted by Michael Baldwin <mi...@sun.com>.
Whoops.  Ignore that.  I gave you a solution to a slightly different problem.
Sorry.

Eric Rizzo wrote:

> Has anyone come up with a good way to implement a dual-list interface using
> Struts?  I mean a UI where there are two lists, a source and a destination, and
> buttons to move items between them.  Obviously, the lists would be created with
> <html:select> tags, and the source list can be populated with <html:option[s]>
> tags.  The big problem I see is how to get the destination list contents into
> the form bean when the form is submitted.  The Action is not interested in what
> is selected in the list, but instead the list's entire contents.
>
> There are JavaScript solutions that I can think of, but I'm hoping that someone
> may have found a way to do it without resorting to that ugliness.
>
> TIA,
>         Eric
> --
> Eric Rizzo, Software Engineer
> OpenNetwork Technologies
> http://www.opennetwork.com
> -----------------------------
> I embrace my personality flaws, for without them
> I might have no personality at all.


Re: Dual-list UI

Posted by Michael Baldwin <mi...@sun.com>.
{Off topic}
I made something to do this a while back as part of a prototype.

It takes a reference to two select boxes: the one that you are trying to move
from and to (i.e., origin and destination).  It works pretty well with IE and
NS4.x.  It puts things in a sequential order in the two lists so that if you
select an item in the destination list, it will put the origin item you want to
move under the destination item.

It's ugly but hey, you know, why reinvent the wheel?

--Michael



function simpleUpdate(originItem, destinationItem) {

 // do nothing if nothing is selected
 if (originItem.selectedIndex == -1) {
  return;
  }

 // set some variables
 oInd=originItem.selectedIndex
 oText=originItem.options[oInd].text
 oValue=originItem.options[oInd].value
 oLength= originItem.options.length
 dInd=destinationItem.selectedIndex
 dLength= destinationItem.options.length

 // build a temporary array
 itemArray = new Array()
 indx =0; // the initial index of the new array = the destination index

 // now add the item to be moved to the array
 itemArray[indx] = new Option(oText, oValue)
 indx++

 // if there are items from the destination that need to follow the item to be
added,
 if ( destinationItem.options[dInd + 1] != null ) {
  // pull out all of the options that follow the destination index into temporary
holding array
  for( i=dInd+1; i<dLength; i++) {
   // i is now the index of the option to temporarily remember
   // *NOTE* -- must build new option objects to satify Netscape 4.x issues.
Cannot just maintain reference to original in array.
   itemArray[indx] = new Option(destinationItem.options[i].text,
destinationItem.options[i].value)
   indx++
  }
 }

 // populate the destination with the items from the new array
 for ( i=0; i<itemArray.length; i++) {
  destinationItem.options[(dInd+1)+i] = itemArray[i];
 }

 // delete the item that was moved from the original list
 originItem.options[oInd]=null

 // select the appropriate items in both lists
 destinationItem.options[dInd+1].selected=true
  if (oLength > 1) {
  originItem.options[0].selected=true
 }
}


Marcelo Vanzin wrote:

> Eric Rizzo wrote:
>  > The Action is not interested in what is selected in the  list, but
>  > instead the list's entire contents.
>  >
>  > There are JavaScript solutions that I can think of, but I'm hoping
>  > that  someone may have found a way to do it without resorting to
>  > that ugliness.
>
>         I've built some pages with that (not in Struts, but this is not a
> Struts-related problem), and the only way I found to send the contents
> of the second list was to use Javascript (to select all the options of
> that "select" prior to submitting).
>
>         It's ugly, but...works.
>
>         The problem is that if the item is not selected, it's not sent in the
> request. So, you use Javascript or you ask the user to select all the
> options on the second list manually (which surely is not a good solution).
>
> --
> []'s
> Marcelo Vanzin
> Touch Tecnologia
> vanza@rededc.com.br
> "We're an underground revolution working overtime"


Re: Dual-list UI

Posted by Marcelo Vanzin <va...@rededc.com.br>.
Eric Rizzo wrote:
 > The Action is not interested in what is selected in the  list, but
 > instead the list's entire contents.
 >
 > There are JavaScript solutions that I can think of, but I'm hoping
 > that  someone may have found a way to do it without resorting to
 > that ugliness.

	I've built some pages with that (not in Struts, but this is not a 
Struts-related problem), and the only way I found to send the contents 
of the second list was to use Javascript (to select all the options of 
that "select" prior to submitting).

	It's ugly, but...works.

	The problem is that if the item is not selected, it's not sent in the 
request. So, you use Javascript or you ask the user to select all the 
options on the second list manually (which surely is not a good solution).

-- 
[]'s
Marcelo Vanzin
Touch Tecnologia
vanza@rededc.com.br
"We're an underground revolution working overtime"


Re: Dual-list UI

Posted by Matt Raible <ma...@yahoo.com>.
The only way that I've found to do this is to use javascript to set all the
destination elements as "selected" when you submit.

Matt

--- Eric Rizzo <er...@opennetwork.com> wrote:
> Has anyone come up with a good way to implement a dual-list interface using 
> Struts?  I mean a UI where there are two lists, a source and a destination,
> and 
> buttons to move items between them.  Obviously, the lists would be created
> with 
> <html:select> tags, and the source list can be populated with
> <html:option[s]> 
> tags.  The big problem I see is how to get the destination list contents into
> 
> the form bean when the form is submitted.  The Action is not interested in
> what 
> is selected in the list, but instead the list's entire contents.
> 
> There are JavaScript solutions that I can think of, but I'm hoping that
> someone 
> may have found a way to do it without resorting to that ugliness.
> 
> TIA,
> 	Eric
> -- 
> Eric Rizzo, Software Engineer
> OpenNetwork Technologies
> http://www.opennetwork.com
> -----------------------------
> I embrace my personality flaws, for without them
> I might have no personality at all.
> 


__________________________________________________
Do You Yahoo!?
Get email alerts & NEW webcam video instant messaging with Yahoo! Messenger. http://im.yahoo.com