myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Volker Weber <>
Subject Re: I Created a UISelectMany, But, It Was Not Acceptable to the <f:selectItems>
Date Thu, 13 Oct 2005 11:04:03 GMT
Hi Caroline,

Caroline Jen wrote:
> Meanwhile, would you mind advising:

You want to clear the selected Items?

just clear or null the field in the bean.
public void clear(ActionEvent e)
  FacesContext facesContext =
  ValueBinding vb = e.getComponent().getValueBinding();
  if (vb != null) {
    vb.setValue(facesContext, null);

> 1. How do I deliver each element of the Object[]
> selectedItems into this method:
> public void clear(ActionEvent e) 
> {
>     FacesContext facesContext =
> FacesContext.getCurrentInstance();
>     UIViewRoot uiViewRoot =
> facesContext.getViewRoot();
>     // Here, I want to iterating through the Object[]
>     if (selectedItems[i] instanceof
> EditableValueHolder)
>     {

this can never happen, selectedItems[i] is not an instance of
EditableValueHolder !
selectedItems[i] is the first argument of SelectItem constructor:
String in my example.

>     EditableValueHolder evh = (EditableValueHolder)
> selectedItems[i];
>     evh.setSubmittedValue(null);

This has no effect in application phase.
just setting a variable to null and throwing away afterwards.

>     } 
> }
> The code snippet above is a draft.  I am uncertain if
> I am doing it right.

> 2. The multiple selections made by user are in an
> Object array (i.e. Object[] selectedItems).  How do I
> retrieve the values from this Object array (I think

Just fetch them from your bean or via ValueBinding from your Component.

> that the values retrieved will be a String[] if I am
> not terribly wrong.) to be sent to the database?

The type is the array type of the objects used to create the
selectItems, in my example Strings.

I attached updated and test.jsp with examples.

Volker Weber
Don't answer to From: address!
Mail to this account are droped if not recieved via mailinglist.
To contact me direct create the mail address by
concatenating my forename to my senders domain.

View raw message