You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Caroline Jen <ji...@yahoo.com> on 2005/10/12 16:05:04 UTC

I Created a UISelectMany, But, It Was Not Acceptable to the

Please help me.  I have been struggling for days.  If
anybody has the experience.

I got a runtime error:
"java.lang.IllegalArgumentException: Conversion Error
setting value ''{0}'' for ''{1}''. 

com.sun.faces.util.Util.getSelectItems(Util.java:628)"
Usually when we encounter this error using
selectItems, we have to ensure that the method the
SelectItems being returned is NOT NULL.  I have a
getter for what to be rendered in my backing bean. 
Therefore, it seems that what I created for rendering
has some problems.

This is my backing bean:

[code]
public class FileManagementBean 
{
	private UISelectMany dataFileItems;
	protected List dataFile;
	
	public FileManagementBean() 
	{
		dataFileItems = new UISelectMany();
		UISelectItem item = new UISelectItem();
 
		SelectItem file = new SelectItem( "file1", "Data
File No. 1" );
		item.setValue( file );
		dataFileItems.getChildren().add( item );
		file = new SelectItem( "file2", "Data File No. 2" );
		item.setValue( file );
		dataFileItems.getChildren().add( item );
......
......
	}

	public UISelectMany getDataFileItems() {
		return dataFileItems;
	}
	
	public Object[] getDataFile() 
	{
		return dataFile.toArray();
	}
	
	public void setDataFile( Object[] newDataFile ) 
	{
	    int len = 0;
		if ( null == newDataFile ||
		   ( len = newDataFile.length) == 0) 
		{
		    return;
		}
		dataFile.clear();
		dataFile = new ArrayList( len );
		for ( int i = 0; i < len; i++ ) 
		{
		    dataFile.add( newDataFile[i] );
                                           }	
	}
}
[/code]

and I tried to create a list box:

[code]
<h:selectManyListbox
binding="#{fileManagementBean.dataFile}" size="7" >
    <f:selectItems
value="#{fileManagementBean.dataFileItems}"/>
</h:selectManyListbox>
[/code]




	
		
__________________________________ 
Yahoo! Mail - PC Magazine Editors' Choice 2005 
http://mail.yahoo.com

Re: UISelectMany. Millions of Thanks for Your Guidance, Mr. Weber.

Posted by Caroline Jen <ji...@yahoo.com>.
Hi Volker,

     This morning, I followed and tested the example
that you provided to render a list box into the
browser using a UISelectMany.  It was a success.

     I had not found much, either in books or on the
internet, about using UI components.  Therefore, I had
had a very tough time.  Other advices (supply a List
and return a String[]) I had received were good; but,
I had been aware of that approach long time ago. 
Thanks God and you that I finally see the light after
spending days in dark.

     I am going to try your way of clean multiple
selections and your way of submitting multiple
selections right away.

     By the way, where do I find documentations that
illustrate how to use UIs?

-Caroline

--- Volker Weber <us...@weber-oldenburg.de>
wrote:

> 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 =
>       FacesContext.getCurrentInstance();
>   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 TestBean.java and test.jsp with
> examples.
> 
> Regards
> 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.
> > package org.apache.myfaces.examples;
> 
> import javax.faces.component.UISelectMany;
> import javax.faces.component.UISelectItems;
> import javax.faces.model.SelectItem;
> import javax.faces.event.ActionEvent;
> import javax.faces.context.FacesContext;
> import javax.faces.el.ValueBinding;
> import java.util.List;
> import java.util.ArrayList;
> 
> public class TestBean {
> 
>   private UISelectMany selectMany;
> 
>   private Object[] selectedItems;
> 
>   public TestBean() {
>     selectMany = new UISelectMany();
>     selectMany.setId("selectMany");
> 
>     UISelectItems items = new UISelectItems();
>     items.setId("selectManyItems");
>     items.setValue(createSelectItems());
> 
>     selectMany.getChildren().add(items);
>   }
> 
>   private Object createSelectItems() {
>     List items = new ArrayList();
>     for (int i = 0; i < 10; i++){
>       items.add(new SelectItem("item" + i, "Item No.
> " + i));
>     }
>     return items;
>   }
> 
>   public UISelectMany getSelectMany() {
>     return selectMany;
>   }
> 
>   public void setSelectMany(UISelectMany selectMany)
> {
>     this.selectMany = selectMany;
>   }
> 
>   public Object[] getSelectedItems() {
>     return selectedItems;
>   }
> 
>   public void setSelectedItems(Object[]
> selectedItems) {
>     this.selectedItems = selectedItems;
>   }
> 
>   public void clear(ActionEvent e) {
> 
>     selectedItems = null;
> 
> // or if no direct access possible
> //    FacesContext facesContext =
> //        FacesContext.getCurrentInstance();
> //    ValueBinding vb =
> e.getComponent().getValueBinding("value");
> //    if (vb != null) {
> //      vb.setValue(facesContext, null);
> //    }
> 
> // ! we have to clear itemsDisplay here also !
> // otherwise it holds his value until next submit
> click.    
>     itemsDisplay = null;
>   }
> 
>   private String itemsDisplay;
> 
>   public void submit(ActionEvent e){
>     Object[] items;
> 
>     items = selectedItems;
> 
> // or if no direct access possible
> //    FacesContext facesContext =
> //        FacesContext.getCurrentInstance();
> //    ValueBinding vb =
> e.getComponent().getValueBinding("value");
> //    if (vb != null) {
> //      items = vb.getValue(facesContext);
> //    }
> 
>     if (items == null || items.length == 0) {
>       itemsDisplay = "No items selected!";
>     } else {
>       StringBuffer sb = new StringBuffer("Selected
> Items: ");
>       for (int i = 0; i < items.length; i++) {
>         sb.append(items[i]);
>         sb.append("; ");
>       }
>       itemsDisplay = sb.toString();
>     }
>   }
> 
>   public String getItemsDisplay() {
>     return itemsDisplay;
>   }
> }
> > <%@ page
> import="org.apache.myfaces.examples.TestBean"%>
> <%@ taglib uri="http://java.sun.com/jsf/html"
> prefix="h"%>
> <%@ taglib uri="http://java.sun.com/jsf/core"
> prefix="f"%>
> 
> <%
>   Object testbean =
> pageContext.getAttribute("TestBean",
> PageContext.SESSION_SCOPE);
>   if (testbean == null) {
>     pageContext.setAttribute("TestBean", new
> TestBean(), PageContext.SESSION_SCOPE);
>   }
> %>
> 
> <html>
> <body>
> <f:view>
>   <h:form>
> 
>     <h:selectManyListbox id="selectMany"
>         binding="#{TestBean.selectMany}"
>         value="#{TestBean.selectedItems}" />
> 
>     <br>
>     <h:commandButton value="Submit"
> actionListener="#{TestBean.submit}"/>
>     <h:commandButton value="Clear"
> actionListener="#{TestBean.clear}"/>
>     <br>
>     <br>
>     <h:outputText value="#{TestBean.itemsDisplay}"/>
> 
>   </h:form>
> </f:view>
> </body>
> </html>



		
__________________________________ 
Yahoo! Music Unlimited 
Access over 1 million songs. Try it free.
http://music.yahoo.com/unlimited/

Re: UISelectMany. Mr. Weber, Question Regarding Cleaning Multiple Selections

Posted by Caroline Jen <ji...@yahoo.com>.
Mr. Weber:

     Thanks for your guidance again.

     One problem remains.  If users change mind about
the multiple selections that have been made "before"
submitting the form, the action listener will invoke
the clear( ActionEvent e ) method in the backing bean.
 And then, users make another set of selections.  Your
code has been tested working well in cleaning the
previous selection "INTERNALLY".  (I mean either set
selectedItems to null or get the component ValueBiding
and set it to null in the FacesContext will work.)

     The problem is that the "previous selections"
remains "on the screen" after the clear( ActionEvent e
) is invoked.  For example, I first selected File No.2
and File No. 4, then, I invoked the action listener
and the clear( ActionEvent e ).  At this point, I
think file2 and file4 are erased from the
selectedItems, but, File No. 2 and File No. 4 are
still highlighted in the list box on the screen.

     itemDisplay = null; does not help.  How do I also
clear the previous selections "visually"?

--Caroline


  public void clear(ActionEvent e) {

    selectedItems = null;

// or if no direct access possible
//    FacesContext facesContext =
//        FacesContext.getCurrentInstance();
//    ValueBinding vb =
e.getComponent().getValueBinding("value");
//    if (vb != null) {
//      vb.setValue(facesContext, null);
//    }

// ! we have to clear itemsDisplay here also !
// otherwise it holds his value until next submit
click.    
    itemsDisplay = null;
  }



--- Volker Weber <us...@weber-oldenburg.de>
wrote:

> 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 =
>       FacesContext.getCurrentInstance();
>   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 TestBean.java and test.jsp with
> examples.
> 
> Regards
> 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.
> > package org.apache.myfaces.examples;
> 
> import javax.faces.component.UISelectMany;
> import javax.faces.component.UISelectItems;
> import javax.faces.model.SelectItem;
> import javax.faces.event.ActionEvent;
> import javax.faces.context.FacesContext;
> import javax.faces.el.ValueBinding;
> import java.util.List;
> import java.util.ArrayList;
> 
> public class TestBean {
> 
>   private UISelectMany selectMany;
> 
>   private Object[] selectedItems;
> 
>   public TestBean() {
>     selectMany = new UISelectMany();
>     selectMany.setId("selectMany");
> 
>     UISelectItems items = new UISelectItems();
>     items.setId("selectManyItems");
>     items.setValue(createSelectItems());
> 
>     selectMany.getChildren().add(items);
>   }
> 
>   private Object createSelectItems() {
>     List items = new ArrayList();
>     for (int i = 0; i < 10; i++){
>       items.add(new SelectItem("item" + i, "Item No.
> " + i));
>     }
>     return items;
>   }
> 
>   public UISelectMany getSelectMany() {
>     return selectMany;
>   }
> 
>   public void setSelectMany(UISelectMany selectMany)
> {
>     this.selectMany = selectMany;
>   }
> 
>   public Object[] getSelectedItems() {
>     return selectedItems;
>   }
> 
>   public void setSelectedItems(Object[]
> selectedItems) {
>     this.selectedItems = selectedItems;
>   }
> 
>   public void clear(ActionEvent e) {
> 
>     selectedItems = null;
> 
> // or if no direct access possible
> //    FacesContext facesContext =
> //        FacesContext.getCurrentInstance();
> //    ValueBinding vb =
> e.getComponent().getValueBinding("value");
> //    if (vb != null) {
> //      vb.setValue(facesContext, null);
> //    }
> 
> // ! we have to clear itemsDisplay here also !
> // otherwise it holds his value until next submit
> click.    
>     itemsDisplay = null;
>   }
> 
>   private String itemsDisplay;
> 
>   public void submit(ActionEvent e){
>     Object[] items;
> 
>     items = selectedItems;
> 
> // or if no direct access possible
> //    FacesContext facesContext =
> //        FacesContext.getCurrentInstance();
> //    ValueBinding vb =
> e.getComponent().getValueBinding("value");
> //    if (vb != null) {
> //      items = vb.getValue(facesContext);
> //    }
> 
>     if (items == null || items.length == 0) {
>       itemsDisplay = "No items selected!";
>     } else {
>       StringBuffer sb = new StringBuffer("Selected
> Items: ");
>       for (int i = 0; i < items.length; i++) {
>         sb.append(items[i]);
>         sb.append("; ");
>       }
>       itemsDisplay = sb.toString();
>     }
>   }
> 
>   public String getItemsDisplay() {
>     return itemsDisplay;
>   }
> }
> > <%@ page
> import="org.apache.myfaces.examples.TestBean"%>
> <%@ taglib uri="http://java.sun.com/jsf/html"
> prefix="h"%>
> <%@ taglib uri="http://java.sun.com/jsf/core"
> prefix="f"%>
> 
> <%
>   Object testbean =
> pageContext.getAttribute("TestBean",
> PageContext.SESSION_SCOPE);
>   if (testbean == null) {
>     pageContext.setAttribute("TestBean", new
> TestBean(), PageContext.SESSION_SCOPE);
>   }
> %>
> 
> <html>
> <body>
> <f:view>
>   <h:form>
> 
>     <h:selectManyListbox id="selectMany"
>         binding="#{TestBean.selectMany}"
>         value="#{TestBean.selectedItems}" />
> 
>     <br>
>     <h:commandButton value="Submit"
> actionListener="#{TestBean.submit}"/>
>     <h:commandButton value="Clear"
> actionListener="#{TestBean.clear}"/>
>     <br>
>     <br>
>     <h:outputText value="#{TestBean.itemsDisplay}"/>
> 
>   </h:form>
> </f:view>
> </body>
> </html>



		
__________________________________ 
Yahoo! Music Unlimited 
Access over 1 million songs. Try it free.
http://music.yahoo.com/unlimited/

Re: UISelectMany. Mr. Weber, Regarding Cleaning Multiple Selections

Posted by Volker Weber <vo...@weber-oldenburg.de>.
Hi,

Caroline Jen wrote:
> Hi Volker,
> 
>      I asked a wrong question in my previous post. 
> Sorry.
> 
>      Your code works fine.  It cleans the multiple
> selections "internally".  
> 
>      I observe a problem:
> 
> After a user submits his/her multiple selections,
> which is an action (instead of an action listener), I
> display the files that he/she has selected.  Then, I
> close the browser.
> 
>      While the server is still running, I run the same
> application again.  And I see the previously selected
> items are highlighted in the list box on my screen.
> 
>      What should I do to resolve this problem?  I mean
> how to erase the selections visually after the
> 'action' takes place?  See

Use the same code as in clear ActionListener, or invoke the method, to
clear the List.


> 
> 						<h:commandButton value="View Data Files ..."
> type="submit" style="width: 180px"
> action="#{fileManagementBean.displaySelectedFiles}"/>
> 
> The "type' attribute in the commandButton has to have
> a value "submit".
> 
>      The cleaning multiple selections is easier.  the
> command button that has an action listener to invoke
> the clear( ActionEvent e ) method can have a 'type'
> attibute with its value being "reset" to clean the
> previous selections visually.

a reset button dosen't clear a selection, just reset the whole form
content to initial state.

> 
> --Caroline
> 
> --- Volker Weber <us...@weber-oldenburg.de>
> wrote:
> 
> 
>>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 =
>>      FacesContext.getCurrentInstance();
>>  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 TestBean.java and test.jsp with
>>examples.
>>
>>Regards
>>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.
>>
>>>package org.apache.myfaces.examples;
>>
>>import javax.faces.component.UISelectMany;
>>import javax.faces.component.UISelectItems;
>>import javax.faces.model.SelectItem;
>>import javax.faces.event.ActionEvent;
>>import javax.faces.context.FacesContext;
>>import javax.faces.el.ValueBinding;
>>import java.util.List;
>>import java.util.ArrayList;
>>
>>public class TestBean {
>>
>>  private UISelectMany selectMany;
>>
>>  private Object[] selectedItems;
>>
>>  public TestBean() {
>>    selectMany = new UISelectMany();
>>    selectMany.setId("selectMany");
>>
>>    UISelectItems items = new UISelectItems();
>>    items.setId("selectManyItems");
>>    items.setValue(createSelectItems());
>>
>>    selectMany.getChildren().add(items);
>>  }
>>
>>  private Object createSelectItems() {
>>    List items = new ArrayList();
>>    for (int i = 0; i < 10; i++){
>>      items.add(new SelectItem("item" + i, "Item No.
>>" + i));
>>    }
>>    return items;
>>  }
>>
>>  public UISelectMany getSelectMany() {
>>    return selectMany;
>>  }
>>
>>  public void setSelectMany(UISelectMany selectMany)
>>{
>>    this.selectMany = selectMany;
>>  }
>>
>>  public Object[] getSelectedItems() {
>>    return selectedItems;
>>  }
>>
>>  public void setSelectedItems(Object[]
>>selectedItems) {
>>    this.selectedItems = selectedItems;
>>  }
>>
>>  public void clear(ActionEvent e) {
>>
>>    selectedItems = null;
>>
>>// or if no direct access possible
>>//    FacesContext facesContext =
>>//        FacesContext.getCurrentInstance();
>>//    ValueBinding vb =
>>e.getComponent().getValueBinding("value");
>>//    if (vb != null) {
>>//      vb.setValue(facesContext, null);
>>//    }
>>
>>// ! we have to clear itemsDisplay here also !
>>// otherwise it holds his value until next submit
>>click.    
>>    itemsDisplay = null;
>>  }
>>
>>  private String itemsDisplay;
>>
>>  public void submit(ActionEvent e){
>>    Object[] items;
>>
>>    items = selectedItems;
>>
>>// or if no direct access possible
>>//    FacesContext facesContext =
>>//        FacesContext.getCurrentInstance();
>>//    ValueBinding vb =
>>e.getComponent().getValueBinding("value");
>>//    if (vb != null) {
>>//      items = vb.getValue(facesContext);
>>//    }
>>
>>    if (items == null || items.length == 0) {
>>      itemsDisplay = "No items selected!";
>>    } else {
>>      StringBuffer sb = new StringBuffer("Selected
>>Items: ");
>>      for (int i = 0; i < items.length; i++) {
>>        sb.append(items[i]);
>>        sb.append("; ");
>>      }
>>      itemsDisplay = sb.toString();
>>    }
>>  }
>>
>>  public String getItemsDisplay() {
>>    return itemsDisplay;
>>  }
>>}
>>
>>><%@ page
>>
>>import="org.apache.myfaces.examples.TestBean"%>
>><%@ taglib uri="http://java.sun.com/jsf/html"
>>prefix="h"%>
>><%@ taglib uri="http://java.sun.com/jsf/core"
>>prefix="f"%>
>>
>><%
>>  Object testbean =
>>pageContext.getAttribute("TestBean",
>>PageContext.SESSION_SCOPE);
>>  if (testbean == null) {
>>    pageContext.setAttribute("TestBean", new
>>TestBean(), PageContext.SESSION_SCOPE);
>>  }
>>%>
>>
>><html>
>><body>
>><f:view>
>>  <h:form>
>>
>>    <h:selectManyListbox id="selectMany"
>>        binding="#{TestBean.selectMany}"
>>        value="#{TestBean.selectedItems}" />
>>
>>    <br>
>>    <h:commandButton value="Submit"
>>actionListener="#{TestBean.submit}"/>
>>    <h:commandButton value="Clear"
>>actionListener="#{TestBean.clear}"/>
>>    <br>
>>    <br>
>>    <h:outputText value="#{TestBean.itemsDisplay}"/>
>>
>>  </h:form>
>></f:view>
>></body>
>></html>
> 
> 
> 
> 
> 	
> 		
> __________________________________ 
> Yahoo! Mail - PC Magazine Editors' Choice 2005 
> http://mail.yahoo.com
> 

-- 
-------------------------------------------------------------------------
    Volker Weber    Dietrichsweg 38a     26127 Oldenburg     Germany
    MAILTO:Volker@weber-oldenburg.de   HTTP://www.weber-oldenburg.de

Re: UISelectMany (Problem Resolved). Mr. Weber, Regarding Cleaning Multiple Selections

Posted by Caroline Jen <ji...@yahoo.com>.
Hi Volker,

     Thanks a lot.  I have an answer to the question
that I posted earlier.

     In the submit() method that is invoked by an
action, I nullify the selectedItems after the
StringBuffer is created.  This way, the multiple
selections that were made previously will not show up
(not be highlighted) on the screen when I re-run the
application.

     Thanks again.  Have a nice day.

Warm Regards,
Caroline

--- Caroline Jen <ji...@yahoo.com> wrote:

> Hi Volker,
> 
>      I asked a wrong question in my previous post. 
> Sorry.
> 
>      Your code works fine.  It cleans the multiple
> selections "internally".  
> 
>      I observe a problem:
> 
> After a user submits his/her multiple selections,
> which is an action (instead of an action listener),
> I
> display the files that he/she has selected.  Then, I
> close the browser.
> 
>      While the server is still running, I run the
> same
> application again.  And I see the previously
> selected
> items are highlighted in the list box on my screen.
> 
>      What should I do to resolve this problem?  I
> mean
> how to erase the selections visually after the
> 'action' takes place?  See
> 
> 						<h:commandButton value="View Data Files ..."
> type="submit" style="width: 180px"
>
action="#{fileManagementBean.displaySelectedFiles}"/>
> 
> The "type' attribute in the commandButton has to
> have
> a value "submit".
> 
>      The cleaning multiple selections is easier. 
> the
> command button that has an action listener to invoke
> the clear( ActionEvent e ) method can have a 'type'
> attibute with its value being "reset" to clean the
> previous selections visually.
> 
> --Caroline
> 
> --- Volker Weber <us...@weber-oldenburg.de>
> wrote:
> 
> > 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 =
> >       FacesContext.getCurrentInstance();
> >   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 TestBean.java and test.jsp with
> > examples.
> > 
> > Regards
> > 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.
> > > package org.apache.myfaces.examples;
> > 
> > import javax.faces.component.UISelectMany;
> > import javax.faces.component.UISelectItems;
> > import javax.faces.model.SelectItem;
> > import javax.faces.event.ActionEvent;
> > import javax.faces.context.FacesContext;
> > import javax.faces.el.ValueBinding;
> > import java.util.List;
> > import java.util.ArrayList;
> > 
> > public class TestBean {
> > 
> >   private UISelectMany selectMany;
> > 
> >   private Object[] selectedItems;
> > 
> >   public TestBean() {
> >     selectMany = new UISelectMany();
> >     selectMany.setId("selectMany");
> > 
> >     UISelectItems items = new UISelectItems();
> >     items.setId("selectManyItems");
> >     items.setValue(createSelectItems());
> > 
> >     selectMany.getChildren().add(items);
> >   }
> > 
> >   private Object createSelectItems() {
> >     List items = new ArrayList();
> >     for (int i = 0; i < 10; i++){
> >       items.add(new SelectItem("item" + i, "Item
> No.
> > " + i));
> >     }
> >     return items;
> >   }
> > 
> >   public UISelectMany getSelectMany() {
> >     return selectMany;
> >   }
> > 
> >   public void setSelectMany(UISelectMany
> selectMany)
> > {
> >     this.selectMany = selectMany;
> >   }
> > 
> >   public Object[] getSelectedItems() {
> >     return selectedItems;
> >   }
> > 
> >   public void setSelectedItems(Object[]
> > selectedItems) {
> 
=== message truncated ===



	
		
__________________________________ 
Yahoo! Mail - PC Magazine Editors' Choice 2005 
http://mail.yahoo.com

Re: UISelectMany. Mr. Weber, Regarding Cleaning Multiple Selections

Posted by Caroline Jen <ji...@yahoo.com>.
Hi Volker,

     I asked a wrong question in my previous post. 
Sorry.

     Your code works fine.  It cleans the multiple
selections "internally".  

     I observe a problem:

After a user submits his/her multiple selections,
which is an action (instead of an action listener), I
display the files that he/she has selected.  Then, I
close the browser.

     While the server is still running, I run the same
application again.  And I see the previously selected
items are highlighted in the list box on my screen.

     What should I do to resolve this problem?  I mean
how to erase the selections visually after the
'action' takes place?  See

						<h:commandButton value="View Data Files ..."
type="submit" style="width: 180px"
action="#{fileManagementBean.displaySelectedFiles}"/>

The "type' attribute in the commandButton has to have
a value "submit".

     The cleaning multiple selections is easier.  the
command button that has an action listener to invoke
the clear( ActionEvent e ) method can have a 'type'
attibute with its value being "reset" to clean the
previous selections visually.

--Caroline

--- Volker Weber <us...@weber-oldenburg.de>
wrote:

> 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 =
>       FacesContext.getCurrentInstance();
>   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 TestBean.java and test.jsp with
> examples.
> 
> Regards
> 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.
> > package org.apache.myfaces.examples;
> 
> import javax.faces.component.UISelectMany;
> import javax.faces.component.UISelectItems;
> import javax.faces.model.SelectItem;
> import javax.faces.event.ActionEvent;
> import javax.faces.context.FacesContext;
> import javax.faces.el.ValueBinding;
> import java.util.List;
> import java.util.ArrayList;
> 
> public class TestBean {
> 
>   private UISelectMany selectMany;
> 
>   private Object[] selectedItems;
> 
>   public TestBean() {
>     selectMany = new UISelectMany();
>     selectMany.setId("selectMany");
> 
>     UISelectItems items = new UISelectItems();
>     items.setId("selectManyItems");
>     items.setValue(createSelectItems());
> 
>     selectMany.getChildren().add(items);
>   }
> 
>   private Object createSelectItems() {
>     List items = new ArrayList();
>     for (int i = 0; i < 10; i++){
>       items.add(new SelectItem("item" + i, "Item No.
> " + i));
>     }
>     return items;
>   }
> 
>   public UISelectMany getSelectMany() {
>     return selectMany;
>   }
> 
>   public void setSelectMany(UISelectMany selectMany)
> {
>     this.selectMany = selectMany;
>   }
> 
>   public Object[] getSelectedItems() {
>     return selectedItems;
>   }
> 
>   public void setSelectedItems(Object[]
> selectedItems) {
>     this.selectedItems = selectedItems;
>   }
> 
>   public void clear(ActionEvent e) {
> 
>     selectedItems = null;
> 
> // or if no direct access possible
> //    FacesContext facesContext =
> //        FacesContext.getCurrentInstance();
> //    ValueBinding vb =
> e.getComponent().getValueBinding("value");
> //    if (vb != null) {
> //      vb.setValue(facesContext, null);
> //    }
> 
> // ! we have to clear itemsDisplay here also !
> // otherwise it holds his value until next submit
> click.    
>     itemsDisplay = null;
>   }
> 
>   private String itemsDisplay;
> 
>   public void submit(ActionEvent e){
>     Object[] items;
> 
>     items = selectedItems;
> 
> // or if no direct access possible
> //    FacesContext facesContext =
> //        FacesContext.getCurrentInstance();
> //    ValueBinding vb =
> e.getComponent().getValueBinding("value");
> //    if (vb != null) {
> //      items = vb.getValue(facesContext);
> //    }
> 
>     if (items == null || items.length == 0) {
>       itemsDisplay = "No items selected!";
>     } else {
>       StringBuffer sb = new StringBuffer("Selected
> Items: ");
>       for (int i = 0; i < items.length; i++) {
>         sb.append(items[i]);
>         sb.append("; ");
>       }
>       itemsDisplay = sb.toString();
>     }
>   }
> 
>   public String getItemsDisplay() {
>     return itemsDisplay;
>   }
> }
> > <%@ page
> import="org.apache.myfaces.examples.TestBean"%>
> <%@ taglib uri="http://java.sun.com/jsf/html"
> prefix="h"%>
> <%@ taglib uri="http://java.sun.com/jsf/core"
> prefix="f"%>
> 
> <%
>   Object testbean =
> pageContext.getAttribute("TestBean",
> PageContext.SESSION_SCOPE);
>   if (testbean == null) {
>     pageContext.setAttribute("TestBean", new
> TestBean(), PageContext.SESSION_SCOPE);
>   }
> %>
> 
> <html>
> <body>
> <f:view>
>   <h:form>
> 
>     <h:selectManyListbox id="selectMany"
>         binding="#{TestBean.selectMany}"
>         value="#{TestBean.selectedItems}" />
> 
>     <br>
>     <h:commandButton value="Submit"
> actionListener="#{TestBean.submit}"/>
>     <h:commandButton value="Clear"
> actionListener="#{TestBean.clear}"/>
>     <br>
>     <br>
>     <h:outputText value="#{TestBean.itemsDisplay}"/>
> 
>   </h:form>
> </f:view>
> </body>
> </html>



	
		
__________________________________ 
Yahoo! Mail - PC Magazine Editors' Choice 2005 
http://mail.yahoo.com

Re: I Created a UISelectMany, But, It Was Not Acceptable to the

Posted by Volker Weber <us...@weber-oldenburg.de>.
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 =
      FacesContext.getCurrentInstance();
  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 TestBean.java and test.jsp with examples.

Regards
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.

Re: I Created a UISelectMany, But, It Was Not Acceptable to the

Posted by Caroline Jen <ji...@yahoo.com>.
Hi Volker, thanks for responding to my posting.  Books
do not talk about UISelectMany much.  And I was unable
to find much information about it on the internet.

Yes, exactly.  I am trying to provide a UISelectMany
and render it as a list box in the browser.

Thank you for the example provided.  I am going to
follow and test the example when I go to office
tomorrow morning.
 
Meanwhile, would you mind advising:

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)
    {
    EditableValueHolder evh = (EditableValueHolder)
selectedItems[i];
    evh.setSubmittedValue(null);
    } 
}

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
that the values retrieved will be a String[] if I am
not terribly wrong.) to be sent to the database?

Regards,
Caroline

--- Volker Weber <us...@weber-oldenburg.de>
wrote:

> Hi,
> 
> i'm a bit confused about what you want to do.
> 
> Lets clear up by consructing an example:
> 
> If i understand you correct you want your
> application to provide a
> component (UISelectMany) which is rendered as a
> listbox
> (<select size=5 ...> <option ... >label</option>+
> </select>).
> 
> The items should created by application and put into
> the component.
> 
> 
> The Bean class:
>
===============================================================================
> package org.apache.myfaces.examples;
> 
> import javax.faces.component.UISelectMany;
> import javax.faces.component.UISelectItems;
> import javax.faces.model.SelectItem;
> import java.util.List;
> import java.util.ArrayList;
> 
> public class TestBean {
> 
>   private UISelectMany selectMany;
> 
>   private Object[] selectedItems;
> 
>   public TestBean() {
>     selectMany = new UISelectMany();
>     selectMany.setId("selectMany");
> 
>     UISelectItems items = new UISelectItems();
>     items.setId("selectManyItems");
>     items.setValue(createSelectItems());
> 
>     selectMany.getChildren().add(items);
>   }
> 
>   private Object createSelectItems() {
>     List items = new ArrayList();
>     for (int i = 0; i < 10; i++){
>       items.add(new SelectItem("item" + i, "Item No.
> " + i));
>     }
>     return items;
>   }
> 
>   public UISelectMany getSelectMany() {
>     return selectMany;
>   }
> 
>   public void setSelectMany(UISelectMany selectMany)
> {
>     this.selectMany = selectMany;
>   }
> 
>   public Object[] getSelectedItems() {
>     return selectedItems;
>   }
> 
>   public void setSelectedItems(Object[]
> selectedItems) {
>     this.selectedItems = selectedItems;
>   }
> }
>
===============================================================================
> 
> and the jsp page:
>
===============================================================================
> <%@ page
> import="org.apache.myfaces.examples.TestBean"%>
> <%@ taglib uri="http://java.sun.com/jsf/html"
> prefix="h"%>
> <%@ taglib uri="http://java.sun.com/jsf/core"
> prefix="f"%>
> 
> <%
>   Object testbean = pageContext.getAttribute(
>       "TestBean", PageContext.SESSION_SCOPE);
>   if (testbean == null) {
>     pageContext.setAttribute(
>         "TestBean", new TestBean(),
> PageContext.SESSION_SCOPE);
>   }
> %>
> 
> <html>
> <body>
> <f:view>
>   <h:form>
> 
>     <h:selectManyListbox id="selectMany"
>         binding="#{TestBean.selectMany}"
>         value="#{TestBean.selectedItems}" />
> 
>     <h:commandButton value="Submit"/>
> 
>   </h:form>
> </f:view>
> </body>
> </html>
>
===============================================================================
> 
> 
> If this is what you want to do, it should be easy to
> adapt it to your needs.
> 
> If not you shoud explain a bit clearer what you
> want.
> 
> Regards
> 
>   Volker Weber
> 
> Caroline Jen wrote:
> > I understand what you are talking about.  I
> created
> > select one and select many long time ago without
> any
> > problem.
> > 
> > I think the conclusion is that it is NOT POSSIBLE
> to
> > supply a UISelectMany to render a list box.  Is it
> > correct?
> > 
> 
> -- 
> 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.
> 
> 



		
__________________________________ 
Yahoo! Music Unlimited 
Access over 1 million songs. Try it free.
http://music.yahoo.com/unlimited/

Re: I Created a UISelectMany, But, It Was Not Acceptable to the

Posted by Volker Weber <us...@weber-oldenburg.de>.
Hi,

i'm a bit confused about what you want to do.

Lets clear up by consructing an example:

If i understand you correct you want your application to provide a
component (UISelectMany) which is rendered as a listbox
(<select size=5 ...> <option ... >label</option>+ </select>).

The items should created by application and put into the component.


The Bean class:
===============================================================================
package org.apache.myfaces.examples;

import javax.faces.component.UISelectMany;
import javax.faces.component.UISelectItems;
import javax.faces.model.SelectItem;
import java.util.List;
import java.util.ArrayList;

public class TestBean {

  private UISelectMany selectMany;

  private Object[] selectedItems;

  public TestBean() {
    selectMany = new UISelectMany();
    selectMany.setId("selectMany");

    UISelectItems items = new UISelectItems();
    items.setId("selectManyItems");
    items.setValue(createSelectItems());

    selectMany.getChildren().add(items);
  }

  private Object createSelectItems() {
    List items = new ArrayList();
    for (int i = 0; i < 10; i++){
      items.add(new SelectItem("item" + i, "Item No. " + i));
    }
    return items;
  }

  public UISelectMany getSelectMany() {
    return selectMany;
  }

  public void setSelectMany(UISelectMany selectMany) {
    this.selectMany = selectMany;
  }

  public Object[] getSelectedItems() {
    return selectedItems;
  }

  public void setSelectedItems(Object[] selectedItems) {
    this.selectedItems = selectedItems;
  }
}
===============================================================================

and the jsp page:
===============================================================================
<%@ page import="org.apache.myfaces.examples.TestBean"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>

<%
  Object testbean = pageContext.getAttribute(
      "TestBean", PageContext.SESSION_SCOPE);
  if (testbean == null) {
    pageContext.setAttribute(
        "TestBean", new TestBean(), PageContext.SESSION_SCOPE);
  }
%>

<html>
<body>
<f:view>
  <h:form>

    <h:selectManyListbox id="selectMany"
        binding="#{TestBean.selectMany}"
        value="#{TestBean.selectedItems}" />

    <h:commandButton value="Submit"/>

  </h:form>
</f:view>
</body>
</html>
===============================================================================


If this is what you want to do, it should be easy to adapt it to your needs.

If not you shoud explain a bit clearer what you want.

Regards

  Volker Weber

Caroline Jen wrote:
> I understand what you are talking about.  I created
> select one and select many long time ago without any
> problem.
> 
> I think the conclusion is that it is NOT POSSIBLE to
> supply a UISelectMany to render a list box.  Is it
> correct?
> 

-- 
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.


RE: I Created a UISelectMany, But, It Was Not Acceptable to the

Posted by Caroline Jen <ji...@yahoo.com>.
I understand what you are talking about.  I created
select one and select many long time ago without any
problem.

I think the conclusion is that it is NOT POSSIBLE to
supply a UISelectMany to render a list box.  Is it
correct?

--- Guillermo Meyer <gm...@interbanking.com.ar>
wrote:

> Creating a select one or a select many by using
> selectItems is the same.
> selectItems behavior is the same
> You are trying to set selectItems value to an
> invalid type property
> 
> <h:selectManyListbox
> binding="#{fileManagementBean.dataFile}" size="7" >
>      <f:selectItems
>  value="#{fileManagementBean.dataFileItems}"/>
> </h:selectManyListbox>
> 
> value points to fileManagementBean.dataFileItems
> that returns UISelectMany
> 
>  	public UISelectMany getDataFileItems() {
> 		return dataFileItems;
>  	}
> 
> check this documentation:
>
http://www.horstmann.com/corejsf/jsf-tags.html#Table4_22a
> 
> "Value binding expression that points to a
> SelectItem, an array or
> Collection of SelectItem objects, or a Map mapping
> labels to values."
> 
> 
> Saludos.
> Guillermo.
> 
> 
> 
> -----Original Message-----
> From: Caroline Jen [mailto:jiapei_jen@yahoo.com] 
> Sent: Miércoles, 12 de Octubre de 2005 12:35 p.m.
> To: MyFaces Discussion; gmeyer@interbanking.com.ar
> Subject: RE: I Created a UISelectMany, But, It Was
> Not Acceptable to the
> <f:selectItems>
> 
> I knew how to create a list box using a List of
> SelectItem.  I did it successfully long time ago.
> 
> What I am struggling now is to have a UISelectMany
> to
> be rendered as a list box in the browser.
> 
> --- Guillermo Meyer <gm...@interbanking.com.ar>
> wrote:
> 
> > You ask this befote. The problem seems to be that
> > dataFileItems in the
> > backing bean should return a Map or an array of
> > SelectItem[].
> > 
> > Change:
> > public UISelectMany getDataFileItems() ....
> > 
> > To:
> > public SelectItem[] getDataFileItems() ....
> > 
> > 
> > And use as you do like this:
> > <h:selectManyListbox
> > binding="#{fileManagementBean.dataFile}" size="7"
> >
> >     <f:selectItems
> > value="#{fileManagementBean.dataFileItems}"/>
> > </h:selectManyListbox>
> > 
> > As you see, #{fileManagementBean.dataFileItems}
> > binding expression points to
> > dataFileItems that in your case returns
> > UISelectMany. It should return
> > SelectItem[] (or a Map)
> > 
> > 
> > Regards.
> > Guillermo.
> > 
> > -----Original Message-----
> > From: Caroline Jen [mailto:jiapei_jen@yahoo.com] 
> > Sent: Miércoles, 12 de Octubre de 2005 11:05 a.m.
> > To: users@myfaces.apache.org
> > Subject: I Created a UISelectMany, But, It Was Not
> > Acceptable to the
> > <f:selectItems>
> > 
> > Please help me.  I have been struggling for days. 
> > If
> > anybody has the experience.
> > 
> > I got a runtime error:
> > "java.lang.IllegalArgumentException: Conversion
> > Error
> > setting value ''{0}'' for ''{1}''. 
> > 
> >
>
com.sun.faces.util.Util.getSelectItems(Util.java:628)"
> > Usually when we encounter this error using
> > selectItems, we have to ensure that the method the
> > SelectItems being returned is NOT NULL.  I have a
> > getter for what to be rendered in my backing bean.
> 
> > Therefore, it seems that what I created for
> > rendering
> > has some problems.
> > 
> > This is my backing bean:
> > 
> > [code]
> > public class FileManagementBean 
> > {
> > 	private UISelectMany dataFileItems;
> > 	protected List dataFile;
> > 	
> > 	public FileManagementBean() 
> > 	{
> > 		dataFileItems = new UISelectMany();
> > 		UISelectItem item = new UISelectItem();
> >  
> > 		SelectItem file = new SelectItem( "file1", "Data
> > File No. 1" );
> > 		item.setValue( file );
> > 		dataFileItems.getChildren().add( item );
> > 		file = new SelectItem( "file2", "Data File No.
> 2"
> > );
> > 		item.setValue( file );
> > 		dataFileItems.getChildren().add( item );
> > ......
> > ......
> > 	}
> > 
> > 	public UISelectMany getDataFileItems() {
> > 		return dataFileItems;
> > 	}
> > 	
> > 	public Object[] getDataFile() 
> > 	{
> > 		return dataFile.toArray();
> > 	}
> > 	
> > 	public void setDataFile( Object[] newDataFile ) 
> > 	{
> > 	    int len = 0;
> > 		if ( null == newDataFile ||
> > 		   ( len = newDataFile.length) == 0) 
> > 		{
> > 		    return;
> > 		}
> > 		dataFile.clear();
> > 		dataFile = new ArrayList( len );
> > 		for ( int i = 0; i < len; i++ ) 
> > 		{
> > 		    dataFile.add( newDataFile[i] );
> >                                            }	
> > 	}
> > }
> > [/code]
> > 
> > and I tried to create a list box:
> > 
> > [code]
> > <h:selectManyListbox
> > binding="#{fileManagementBean.dataFile}" size="7"
> >
> >     <f:selectItems
> > value="#{fileManagementBean.dataFileItems}"/>
> > </h:selectManyListbox>
> > [/code]
> > 
> > 
> > 
> > 
> > 	
> > 		
> > __________________________________ 
> > Yahoo! Mail - PC Magazine Editors' Choice 2005 
> > http://mail.yahoo.com
> > 
> > NOTA DE CONFIDENCIALIDAD
> > Este mensaje (y sus anexos) es confidencial, esta
> > dirigido exclusivamente a las personas
> direccionadas
> > en el mail y puede contener informacion (i)de
> > propiedad exclusiva de Interbanking S.A. o (ii)
> > amparada por el secreto profesional. Cualquier
> > opinion en el contenido, es exclusiva de su autor
> y
> > no representa necesariamente la opinion de
> > Interbanking S.A. El acceso no autorizado, uso,
> > reproduccion, o divulgacion esta prohibido.
> > Interbanking S.A no asumira responsabilidad ni
> > obligacion legal alguna por cualquier informacion
> > incorrecta o alterada contenida en este mensaje.
> Si
> > usted ha recibido este mensaje por error, le
> rogamos
> > tenga la amabilidad de destruirlo inmediatamente
> 
=== message truncated ===



		
__________________________________ 
Yahoo! Music Unlimited 
Access over 1 million songs. Try it free.
http://music.yahoo.com/unlimited/

RE: I Created a UISelectMany, But, It Was Not Acceptable to the

Posted by Guillermo Meyer <gm...@interbanking.com.ar>.
Creating a select one or a select many by using selectItems is the same.
selectItems behavior is the same
You are trying to set selectItems value to an invalid type property

<h:selectManyListbox
binding="#{fileManagementBean.dataFile}" size="7" >
     <f:selectItems
 value="#{fileManagementBean.dataFileItems}"/>
</h:selectManyListbox>

value points to fileManagementBean.dataFileItems that returns UISelectMany

 	public UISelectMany getDataFileItems() {
		return dataFileItems;
 	}

check this documentation:
http://www.horstmann.com/corejsf/jsf-tags.html#Table4_22a

"Value binding expression that points to a SelectItem, an array or
Collection of SelectItem objects, or a Map mapping labels to values."


Saludos.
Guillermo.



-----Original Message-----
From: Caroline Jen [mailto:jiapei_jen@yahoo.com] 
Sent: Miércoles, 12 de Octubre de 2005 12:35 p.m.
To: MyFaces Discussion; gmeyer@interbanking.com.ar
Subject: RE: I Created a UISelectMany, But, It Was Not Acceptable to the
<f:selectItems>

I knew how to create a list box using a List of
SelectItem.  I did it successfully long time ago.

What I am struggling now is to have a UISelectMany to
be rendered as a list box in the browser.

--- Guillermo Meyer <gm...@interbanking.com.ar>
wrote:

> You ask this befote. The problem seems to be that
> dataFileItems in the
> backing bean should return a Map or an array of
> SelectItem[].
> 
> Change:
> public UISelectMany getDataFileItems() ....
> 
> To:
> public SelectItem[] getDataFileItems() ....
> 
> 
> And use as you do like this:
> <h:selectManyListbox
> binding="#{fileManagementBean.dataFile}" size="7" >
>     <f:selectItems
> value="#{fileManagementBean.dataFileItems}"/>
> </h:selectManyListbox>
> 
> As you see, #{fileManagementBean.dataFileItems}
> binding expression points to
> dataFileItems that in your case returns
> UISelectMany. It should return
> SelectItem[] (or a Map)
> 
> 
> Regards.
> Guillermo.
> 
> -----Original Message-----
> From: Caroline Jen [mailto:jiapei_jen@yahoo.com] 
> Sent: Miércoles, 12 de Octubre de 2005 11:05 a.m.
> To: users@myfaces.apache.org
> Subject: I Created a UISelectMany, But, It Was Not
> Acceptable to the
> <f:selectItems>
> 
> Please help me.  I have been struggling for days. 
> If
> anybody has the experience.
> 
> I got a runtime error:
> "java.lang.IllegalArgumentException: Conversion
> Error
> setting value ''{0}'' for ''{1}''. 
> 
>
com.sun.faces.util.Util.getSelectItems(Util.java:628)"
> Usually when we encounter this error using
> selectItems, we have to ensure that the method the
> SelectItems being returned is NOT NULL.  I have a
> getter for what to be rendered in my backing bean. 
> Therefore, it seems that what I created for
> rendering
> has some problems.
> 
> This is my backing bean:
> 
> [code]
> public class FileManagementBean 
> {
> 	private UISelectMany dataFileItems;
> 	protected List dataFile;
> 	
> 	public FileManagementBean() 
> 	{
> 		dataFileItems = new UISelectMany();
> 		UISelectItem item = new UISelectItem();
>  
> 		SelectItem file = new SelectItem( "file1", "Data
> File No. 1" );
> 		item.setValue( file );
> 		dataFileItems.getChildren().add( item );
> 		file = new SelectItem( "file2", "Data File No. 2"
> );
> 		item.setValue( file );
> 		dataFileItems.getChildren().add( item );
> ......
> ......
> 	}
> 
> 	public UISelectMany getDataFileItems() {
> 		return dataFileItems;
> 	}
> 	
> 	public Object[] getDataFile() 
> 	{
> 		return dataFile.toArray();
> 	}
> 	
> 	public void setDataFile( Object[] newDataFile ) 
> 	{
> 	    int len = 0;
> 		if ( null == newDataFile ||
> 		   ( len = newDataFile.length) == 0) 
> 		{
> 		    return;
> 		}
> 		dataFile.clear();
> 		dataFile = new ArrayList( len );
> 		for ( int i = 0; i < len; i++ ) 
> 		{
> 		    dataFile.add( newDataFile[i] );
>                                            }	
> 	}
> }
> [/code]
> 
> and I tried to create a list box:
> 
> [code]
> <h:selectManyListbox
> binding="#{fileManagementBean.dataFile}" size="7" >
>     <f:selectItems
> value="#{fileManagementBean.dataFileItems}"/>
> </h:selectManyListbox>
> [/code]
> 
> 
> 
> 
> 	
> 		
> __________________________________ 
> Yahoo! Mail - PC Magazine Editors' Choice 2005 
> http://mail.yahoo.com
> 
> NOTA DE CONFIDENCIALIDAD
> Este mensaje (y sus anexos) es confidencial, esta
> dirigido exclusivamente a las personas direccionadas
> en el mail y puede contener informacion (i)de
> propiedad exclusiva de Interbanking S.A. o (ii)
> amparada por el secreto profesional. Cualquier
> opinion en el contenido, es exclusiva de su autor y
> no representa necesariamente la opinion de
> Interbanking S.A. El acceso no autorizado, uso,
> reproduccion, o divulgacion esta prohibido.
> Interbanking S.A no asumira responsabilidad ni
> obligacion legal alguna por cualquier informacion
> incorrecta o alterada contenida en este mensaje. Si
> usted ha recibido este mensaje por error, le rogamos
> tenga la amabilidad de destruirlo inmediatamente
> junto con todas las copias del mismo, notificando al
> remitente. No debera utilizar, revelar, distribuir,
> imprimir o copiar este mensaje ni ninguna de sus
> partes si usted no es el destinatario. Muchas
> gracias.
> 
> 
> 



	
		
__________________________________ 
Yahoo! Mail - PC Magazine Editors' Choice 2005 
http://mail.yahoo.com

NOTA DE CONFIDENCIALIDAD
Este mensaje (y sus anexos) es confidencial, esta dirigido exclusivamente a las personas direccionadas en el mail y puede contener informacion (i)de propiedad exclusiva de Interbanking S.A. o (ii) amparada por el secreto profesional. Cualquier opinion en el contenido, es exclusiva de su autor y no representa necesariamente la opinion de Interbanking S.A. El acceso no autorizado, uso, reproduccion, o divulgacion esta prohibido. Interbanking S.A no asumira responsabilidad ni obligacion legal alguna por cualquier informacion incorrecta o alterada contenida en este mensaje. Si usted ha recibido este mensaje por error, le rogamos tenga la amabilidad de destruirlo inmediatamente junto con todas las copias del mismo, notificando al remitente. No debera utilizar, revelar, distribuir, imprimir o copiar este mensaje ni ninguna de sus partes si usted no es el destinatario. Muchas gracias.



RE: I Created a UISelectMany, But, It Was Not Acceptable to the

Posted by Caroline Jen <ji...@yahoo.com>.
I knew how to create a list box using a List of
SelectItem.  I did it successfully long time ago.

What I am struggling now is to have a UISelectMany to
be rendered as a list box in the browser.

--- Guillermo Meyer <gm...@interbanking.com.ar>
wrote:

> You ask this befote. The problem seems to be that
> dataFileItems in the
> backing bean should return a Map or an array of
> SelectItem[].
> 
> Change:
> public UISelectMany getDataFileItems() ....
> 
> To:
> public SelectItem[] getDataFileItems() ....
> 
> 
> And use as you do like this:
> <h:selectManyListbox
> binding="#{fileManagementBean.dataFile}" size="7" >
>     <f:selectItems
> value="#{fileManagementBean.dataFileItems}"/>
> </h:selectManyListbox>
> 
> As you see, #{fileManagementBean.dataFileItems}
> binding expression points to
> dataFileItems that in your case returns
> UISelectMany. It should return
> SelectItem[] (or a Map)
> 
> 
> Regards.
> Guillermo.
> 
> -----Original Message-----
> From: Caroline Jen [mailto:jiapei_jen@yahoo.com] 
> Sent: Miércoles, 12 de Octubre de 2005 11:05 a.m.
> To: users@myfaces.apache.org
> Subject: I Created a UISelectMany, But, It Was Not
> Acceptable to the
> <f:selectItems>
> 
> Please help me.  I have been struggling for days. 
> If
> anybody has the experience.
> 
> I got a runtime error:
> "java.lang.IllegalArgumentException: Conversion
> Error
> setting value ''{0}'' for ''{1}''. 
> 
>
com.sun.faces.util.Util.getSelectItems(Util.java:628)"
> Usually when we encounter this error using
> selectItems, we have to ensure that the method the
> SelectItems being returned is NOT NULL.  I have a
> getter for what to be rendered in my backing bean. 
> Therefore, it seems that what I created for
> rendering
> has some problems.
> 
> This is my backing bean:
> 
> [code]
> public class FileManagementBean 
> {
> 	private UISelectMany dataFileItems;
> 	protected List dataFile;
> 	
> 	public FileManagementBean() 
> 	{
> 		dataFileItems = new UISelectMany();
> 		UISelectItem item = new UISelectItem();
>  
> 		SelectItem file = new SelectItem( "file1", "Data
> File No. 1" );
> 		item.setValue( file );
> 		dataFileItems.getChildren().add( item );
> 		file = new SelectItem( "file2", "Data File No. 2"
> );
> 		item.setValue( file );
> 		dataFileItems.getChildren().add( item );
> ......
> ......
> 	}
> 
> 	public UISelectMany getDataFileItems() {
> 		return dataFileItems;
> 	}
> 	
> 	public Object[] getDataFile() 
> 	{
> 		return dataFile.toArray();
> 	}
> 	
> 	public void setDataFile( Object[] newDataFile ) 
> 	{
> 	    int len = 0;
> 		if ( null == newDataFile ||
> 		   ( len = newDataFile.length) == 0) 
> 		{
> 		    return;
> 		}
> 		dataFile.clear();
> 		dataFile = new ArrayList( len );
> 		for ( int i = 0; i < len; i++ ) 
> 		{
> 		    dataFile.add( newDataFile[i] );
>                                            }	
> 	}
> }
> [/code]
> 
> and I tried to create a list box:
> 
> [code]
> <h:selectManyListbox
> binding="#{fileManagementBean.dataFile}" size="7" >
>     <f:selectItems
> value="#{fileManagementBean.dataFileItems}"/>
> </h:selectManyListbox>
> [/code]
> 
> 
> 
> 
> 	
> 		
> __________________________________ 
> Yahoo! Mail - PC Magazine Editors' Choice 2005 
> http://mail.yahoo.com
> 
> NOTA DE CONFIDENCIALIDAD
> Este mensaje (y sus anexos) es confidencial, esta
> dirigido exclusivamente a las personas direccionadas
> en el mail y puede contener informacion (i)de
> propiedad exclusiva de Interbanking S.A. o (ii)
> amparada por el secreto profesional. Cualquier
> opinion en el contenido, es exclusiva de su autor y
> no representa necesariamente la opinion de
> Interbanking S.A. El acceso no autorizado, uso,
> reproduccion, o divulgacion esta prohibido.
> Interbanking S.A no asumira responsabilidad ni
> obligacion legal alguna por cualquier informacion
> incorrecta o alterada contenida en este mensaje. Si
> usted ha recibido este mensaje por error, le rogamos
> tenga la amabilidad de destruirlo inmediatamente
> junto con todas las copias del mismo, notificando al
> remitente. No debera utilizar, revelar, distribuir,
> imprimir o copiar este mensaje ni ninguna de sus
> partes si usted no es el destinatario. Muchas
> gracias.
> 
> 
> 



	
		
__________________________________ 
Yahoo! Mail - PC Magazine Editors' Choice 2005 
http://mail.yahoo.com

RE: I Created a UISelectMany, But, It Was Not Acceptable to the

Posted by Guillermo Meyer <gm...@interbanking.com.ar>.
You ask this befote. The problem seems to be that dataFileItems in the
backing bean should return a Map or an array of SelectItem[].

Change:
public UISelectMany getDataFileItems() ....

To:
public SelectItem[] getDataFileItems() ....


And use as you do like this:
<h:selectManyListbox
binding="#{fileManagementBean.dataFile}" size="7" >
    <f:selectItems
value="#{fileManagementBean.dataFileItems}"/>
</h:selectManyListbox>

As you see, #{fileManagementBean.dataFileItems} binding expression points to
dataFileItems that in your case returns UISelectMany. It should return
SelectItem[] (or a Map)


Regards.
Guillermo.

-----Original Message-----
From: Caroline Jen [mailto:jiapei_jen@yahoo.com] 
Sent: Miércoles, 12 de Octubre de 2005 11:05 a.m.
To: users@myfaces.apache.org
Subject: I Created a UISelectMany, But, It Was Not Acceptable to the
<f:selectItems>

Please help me.  I have been struggling for days.  If
anybody has the experience.

I got a runtime error:
"java.lang.IllegalArgumentException: Conversion Error
setting value ''{0}'' for ''{1}''. 

com.sun.faces.util.Util.getSelectItems(Util.java:628)"
Usually when we encounter this error using
selectItems, we have to ensure that the method the
SelectItems being returned is NOT NULL.  I have a
getter for what to be rendered in my backing bean. 
Therefore, it seems that what I created for rendering
has some problems.

This is my backing bean:

[code]
public class FileManagementBean 
{
	private UISelectMany dataFileItems;
	protected List dataFile;
	
	public FileManagementBean() 
	{
		dataFileItems = new UISelectMany();
		UISelectItem item = new UISelectItem();
 
		SelectItem file = new SelectItem( "file1", "Data
File No. 1" );
		item.setValue( file );
		dataFileItems.getChildren().add( item );
		file = new SelectItem( "file2", "Data File No. 2" );
		item.setValue( file );
		dataFileItems.getChildren().add( item );
......
......
	}

	public UISelectMany getDataFileItems() {
		return dataFileItems;
	}
	
	public Object[] getDataFile() 
	{
		return dataFile.toArray();
	}
	
	public void setDataFile( Object[] newDataFile ) 
	{
	    int len = 0;
		if ( null == newDataFile ||
		   ( len = newDataFile.length) == 0) 
		{
		    return;
		}
		dataFile.clear();
		dataFile = new ArrayList( len );
		for ( int i = 0; i < len; i++ ) 
		{
		    dataFile.add( newDataFile[i] );
                                           }	
	}
}
[/code]

and I tried to create a list box:

[code]
<h:selectManyListbox
binding="#{fileManagementBean.dataFile}" size="7" >
    <f:selectItems
value="#{fileManagementBean.dataFileItems}"/>
</h:selectManyListbox>
[/code]




	
		
__________________________________ 
Yahoo! Mail - PC Magazine Editors' Choice 2005 
http://mail.yahoo.com

NOTA DE CONFIDENCIALIDAD
Este mensaje (y sus anexos) es confidencial, esta dirigido exclusivamente a las personas direccionadas en el mail y puede contener informacion (i)de propiedad exclusiva de Interbanking S.A. o (ii) amparada por el secreto profesional. Cualquier opinion en el contenido, es exclusiva de su autor y no representa necesariamente la opinion de Interbanking S.A. El acceso no autorizado, uso, reproduccion, o divulgacion esta prohibido. Interbanking S.A no asumira responsabilidad ni obligacion legal alguna por cualquier informacion incorrecta o alterada contenida en este mensaje. Si usted ha recibido este mensaje por error, le rogamos tenga la amabilidad de destruirlo inmediatamente junto con todas las copias del mismo, notificando al remitente. No debera utilizar, revelar, distribuir, imprimir o copiar este mensaje ni ninguna de sus partes si usted no es el destinatario. Muchas gracias.