Well, HTML never submit the "whole" content of a list AFAIK, only the
selected one. So you have a few choices:

1) Select using javascript ALL the items as Ian suggested, so they are
all submitted (but this need a select many)

2) Populate the list in the server side, so you don't need to submit
those values (your solution)

3) A trick would be to have an hidden property and having a javascript
put all the items in it on submit. Your visible control will send the
selected item, and your hidden property the while list (comma
separated?). If you use a JSF component for the hidden you will need a
binding to get the submitted value (because your using
immediate="true") or you may want to use a plain old html <input
type="hidden"> and retrieve its value using the external context. Not
very much JSF, IMO this isn't a very good solution.

4) Take solution 2 and add ajax4jsf, so you wrap the server round-trip
as an ajax request and let a4j rewrite the DOM only for your list
component.

Sometimes I hate frameworks too, but in your situation I think that
its not a framework fault at all :-). JSF allows you to solve the
problem in a clean way if you want to (solutions 2 and 4), or to go
the non-JSF tricky way (solution 1 and 3).


Bye
Cosma


2006/6/20, Gregg Bolinger <[EMAIL PROTECTED]>:
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