selectManyListbox question

Hi,

I have two selectManyListboxes on a jsp page I am trying to move items from one selectManyListbox to other.

Here the selectManyListbox values I have are SelectItem[] types

Here I am using actionListener for moving items

Please anybody could explain me how to do this

any help is appreciated

[334 byte] By [Ruthera] at [2007-11-26 21:29:51]
# 1
any help
Ruthera at 2007-7-10 3:10:34 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

JSF<h:form>

<h:selectManyListbox value="#{myBean.selectedItemsLeft}">

<f:selectItems value="#{myBean.selectItemsLeft}" />

</h:selectManyListbox>

<h:commandButton value="left to right" action="#{myBean.leftToRight}" />

<h:commandButton value="right to left" action="#{myBean.rightToLeft}" />

<h:selectManyListbox value="#{myBean.selectedItemsRight}">

<f:selectItems value="#{myBean.selectItemsRight}" />

</h:selectManyListbox>

</h:form>

MyBean (this one is a session scoped design)public class MyBean {

private List selectItemsLeft = new ArrayList();

private List selectedItemsLeft;

private List selectItemsRight = new ArrayList();

private List selectedItemsRight;

// + getters + setters

public MyBean() {

loadSelectItemsLeft();

}

public void leftToRight() {

if (selectedItemsLeft != null) {

for (Iterator iter = selectItemsLeft.iterator(); iter.hasNext();) {

SelectItem selectItem = (SelectItem) iter.next();

if (selectedItemsLeft.contains(selectItem.getValue())) {

selectItemsRight.add(selectItem);

iter.remove();

}

}

selectedItemsLeft.clear();

}

}

public void rightToLeft() {

if (selectedItemsRight != null) {

for (Iterator iter = selectItemsRight.iterator(); iter.hasNext();) {

SelectItem selectItem = (SelectItem) iter.next();

if (selectedItemsRight.contains(selectItem.getValue())) {

selectItemsLeft.add(selectItem);

iter.remove();

}

}

selectedItemsRight.clear();

}

}

private void loadSelectItemsLeft() {

selectItemsLeft.add(new SelectItem("key1", "value1"));

selectItemsLeft.add(new SelectItem("key2", "value2"));

selectItemsLeft.add(new SelectItem("key3", "value3"));

selectItemsLeft.add(new SelectItem("key4", "value4"));

selectItemsLeft.add(new SelectItem("key5", "value5"));

}

}

BalusCa at 2007-7-10 3:10:34 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

Thanks BaluC sir,

But here my problem is I passing SelectItem[] type values to SelectManyListbox.

here is the code

Here is my bean class

public void setSelectedPriceList(SelectItem[] availablePriceLists)

{

this.selectedPriceList = availablePriceLists;

}

public SelectItem[] getSelectedPriceList()

{

selectedPriceList = getCpgPriceListDtos();

return selectedPriceList;

}

public void setAvailablePriceList(SelectItem[] availablePriceList)

{

this.availablePriceList = availablePriceList;

}

public SelectItem[] getAvailablePriceList()

{

availablePriceList = availablePriceListDtos();

return availablePriceList;

}

Here is my jsp page

<t:panelGrid columns="3" cellspacing="0" border="1" width="75%">

<t:outputText value="Available Price List"/>

<f:verbatim> </f:verbatim>

<t:outputText value="Selected Price List"/>

<t:selectManyListbox style="width: 300px;">

<f:selectItems value="#{mybean.availablePriceList}"/>

</t:selectManyListbox>

<t:panelGrid columns="1">

<t:commandButton value=">" actionListener="mybean.moveToSelected" style="width: 50px;"/>

<t:commandButton value="<<" actionListener="mybean.moveToAvailable" style="width: 50px;"/>

</t:panelGrid>

<t:selectManyListbox style="width: 300px;">

<f:selectItems id="visibleItems"

value="#{mybean.selectedPriceList}"/>

</t:selectManyListbox>

</t:panelGrid

>

Please help me to solve this

thanks in advance

Ruthera at 2007-7-10 3:10:34 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

any help on how to get the length of SelectManyListbox and remove the selected values and move that to another selectManyListbox

here my selectManyListbox values are SelectItem[] values so I can't

directly add and remove values

can anybody help me how to do this

any help is appreciated

Ruthera at 2007-7-10 3:10:34 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
Just convert it to List?List list = Arrays.asList(someOrdinaryArray);
BalusCa at 2007-7-10 3:10:34 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6
can I pass SelectItem[] values in place of someOrdinaryArray
Ruthera at 2007-7-10 3:10:34 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7
Hi BalauC Sir,Ok I tried a lot but not succeded,Can you please explain this how to do this in JavaScriptany help is appreciated.thanks in advance
Ruthera at 2007-7-10 3:10:34 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 8
please any help..
Ruthera at 2007-7-10 3:10:34 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 9

I already have explained how you could do it. Getting the length, moving the items and converting between an ordinary array and a collection is just basic Java API knowledge.

By the way, if you're using Tomahawk components for the UIInput, then please also use the appropriate t:selectItems component insead of f:selectItems.

BalusCa at 2007-7-10 3:10:34 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...