h:selectManyListbox editing
Hi,
I have <h:selectManyListbox which contains values as A,B,C,D,E.
So at time of saving to database suppose I am selecting A,B.
While editing I want to display this A,B in selected mode.How to do this ?
List list = bean.method(); // this contains value as A,B.
SO how to set these value while editing in ><h:selectManyListbox
Sandip>
# 1
Just put this in the valuebinding of h:selectManyListBox.
# 3
Hi BalusC,
As you said valubinding can you please explain it how to do it.
My JSP is,
<h:selectManyListbox value="#{Bean.stage}" >
<f:selectItems value="#{AnotherBean.stageList}" /> // contains A,B,C,D,E
</h:selectManyListbox>
In Java Code I am doing as,
List list = list from database;// ie. value A,B selected out of A,B,C,D,E.
So how I will set this list to stage variable of my JSP while editing.
Thanks
Sandip Patil
# 4
Do something like stage.addAll(list);
# 5
Thanks for your reply.
I tried as,
List list = list from database; // ie. value A,B selected out of A,B,C,D,E.
stage.addAll(list);
But its giving me Nullpointerexception.
When I did System.out.println(list) . I got value 1 for list.
My list contain value as A,B
I am writing stage variable as.
private List stage ; // getter / setter
Can you please help me.
Thanks
Sandip
# 6
Do you understand NullPointerExceptions? This will occur if you invoke an action on an object which isn't instantiated yet. In this case you're invoking an action on stage using addAll() and not on list. So checking the contents of list is totally irrelevant.
Just instantiate the stage object.
private List stage = new ArrayList();
# 7
Thanks for your reply.
But still I am not able to display multiple lists if I click on edit link.
i.e though I selected A,B while saving to databse while editing I am not getting A,B in selected mode.
But if i save only A OR B i.e single value, its displaying in selected mode while editing.
can you suggest why I am not getting displayed multiple values selected.
Thanks
Sandip
# 8
Hi BalusC can you help me in this.
# 9
can anybody help me in this.
# 10
Hi BalusC,
Thanks a lot for your help.
on google I got link regarding same issue.
http://balusc.xs4all.nl/frm/list_message/21777
Here you wrote method as,
public void leftToRight() {
if (selectedItemsLeft != null) {
for (Iterator iter = selectItemsLeft.iterator(); iter.hasNext();) {
SelectItem selectItem = (SelectItem) iter.next();// Can you please tell me why this SelectItem is here . if (selectedItemsLeft.contains(selectItem.getValue())) {
selectItemsRight.add(selectItem);
iter.remove();
}
Thanks
# 11
Just read the code? It loops through the selectItems, it compares the value with the selected item and if equal, the move from left to right.
# 12
Hi BalusC,
SelectItem selectItem = (SelectItem) iter.next();
If I use it then I am not able to display selected list.
But if I do ,
String st = (String)iter.next();
if (li.toString.contains(st) {
stage.add(st);
}
Here I am able to display list.
But still problem there as I am using contains, Suppose there are list as,A,B,C,A-B,D,E.
So while saving if I selected A,E, then at time of editing it will display me A,E,A-B (as A-B contains letter A)
Thanks
# 13
This code is not iterating trough selectedItems, but through selectItems.
# 14
Hi,
I agree with you that you are itearationg through selectItems
But in my case I am doing as,
List allstages = all values from Databse i.e.A,B,C,A-B,D,E
List li = here I m retriving saved values i.e. A,C
if (li != null) {
for (Iterator iter = allstages.iterator(); iter.hasNext();) {
String mystage = (String) iter.next(); // Here I used String
if (li.toString().contains(mystage)) {
stage.add(mystage);
}
}
}
I saved A,C but while editing its also displaying A-B i.e. A,C,A-B
If I try to use SelectItem instead String nothing is in selected mode.
Thanks again
# 15
Hi BalusCcan you please tell me what i m missing ?
# 16
Hi Sandip
I did out your example and didn't get that error. i.e. I got only A and C
Here is the code I used:
import java.util.Iterator;
public class TestContains
{
/**
* @param args
*/
public static void main(String[] args)
{
// TODO Auto-generated method stub
ArrayList first = new ArrayList();
ArrayList second = new ArrayList();
ArrayList third = new ArrayList();
first.add("a");
first.add("b");
first.add("a-b");
first.add("c");
second.add("a");
second.add("c");
if (second != null)
{
for (Iterator iter = first.iterator(); iter.hasNext();)
{
String mystage = (String) iter.next(); // Here I used String
if (second.toString().contains(mystage))
{
third.add(mystage);
}
}
}
for (Iterator iter = third.iterator(); iter.hasNext();)
{
System.out.println(iter.next());
}
}
}
This prints out only A and C, I don't see how it could print out A-B.
Could your error be caused by using List and not ArrayList perhaps? Are your lists are not being cleaned after each use?
Cheers,
Illu
Message was edited by:
Illu
Illua at 2007-7-9 5:04:55 >

