And this is why I hate frameworks sometimes.

Basically what I have, as I said, is I need to be able to add keywords to a select list from a textfield.  Then, upon save/update, I need to be able to get all the items from the select list. 

To get all the items, here is what I did:

List selectItems = keywordSelect.getChildren();
Iterator iter = selectItems.iterator();
while(iter.hasNext())
{
    UISelectItems items = (UISelectItems)iter.next();
    List l = (List)items.getValue();
    for (int i = 0; i < l.size(); i++)
    {
        SelectItem item = (SelectItem)l.get(i);
        System.out.println(item.getLabel());
    }
}

This works fine.  The problem then became in how I was adding items to the select list.  Originally, I was using _javascript_ to add items and I used a commandButton with a type="button" and use the onclick to call the _javascript_ function.  However, what I realized is that since the model for the select list isn't being updated, I don't get the new values I added using the above solution.

So what I had to do was add keywords to the select list using Java code.  I did it like so.

SelectItem item = new SelectItem(getKeyWord(), getKeyWord());
List list = keywordSelect.getChildren();
Iterator iter = list.iterator();
while(iter.hasNext())
{
    UISelectItems items = (UISelectItems)iter.next();
    List itemsList = (List)items.getValue();
    itemsList.add(item);
    items.setValue(itemsList);
}

While this works, it seems silly to me that I need to hit the server to do this.  Actually, pretty rediculous.  Sure, I could incorporate some Ajax to update the model so I wasn't having to send so much across the pipe, but even that seems silly.

I'd still like to know if there are any alternatives.

On 6/20/06, Gregg Bolinger <[EMAIL PROTECTED] > wrote:
Thanks for the suggestion, but it can't be a SelectMany because I use the same form for editing and I need the user to be able to only select one.  I am going to play around with the getChildren method because I should be able to get a handle on the selectItems that it contains.  Any other suggestions?

Gregg


On 6/20/06, Ian Johnson < [EMAIL PROTECTED]> wrote:
First off, you probably need to use the UISelectMany, and then use _javascript_ to select all of the items before submitting the form, you know something like this:
   
    var selectList = document.getElementById(selectListId);
    for(var i = 0;i < selectList.length;i++)
    {
    selectList.options[i].selected = true;
    }
 


From: Gregg Bolinger [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, June 20, 2006 8:08 AM
To: MyFaces Discussion
Subject: Get All Values of SelectOneListBox

Can anyone suggest the best way to get all the values of an HtmlSelectOneListbox in the managed bean?  I have a page where I need to add keywords to a category so I have an inputText and I use _javascript_ to add inputed keywords into the list box.  But I am unclear on how to get all of those values when I submit the page.

Thanks.


Reply via email to