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/11 15:26:34 UTC

UISelectMany and Argument Type Mismatch

I used the UISelectItem to set its value to the
SelectItem (I have many SelectItme).  Then,  I added
each UISelectItem to the UISelectMany .  When I
displayed a list box, I got the runtime error:

"IllegalArgumentException: argument type mismatch"

In my JSP, I create a list box for multiple
selections: 

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

Therefore, the "dataFileItems" is of type UISelectMany
that has elements of type UISelectItem.  The multiple
selections that users make will be in a String array:
String[] dataFile.  Did I mess up anything here?  My
backing bean code is like:

[code]
.....
.....
public class FileManagementBean 
{
	private String[] dataFile;
	private UISelectMany dataFileItems;
	
	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 String[] getDataFile() {
		return dataFile;
	}

	public void setDataFile( String[] dataFile ) {
		this.dataFile = dataFile;
	}

	public UISelectMany getDataFileItems() {
		return dataFileItems;
	}
}
[/code]


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

Re: [Topic Changed] UISelectMany and EvaluationException

Posted by Caroline Jen <ji...@yahoo.com>.
In my JSP, the 'dataFile' will contain all the
multiple selections that users make from the list box.
 I do not understand your question.  Why should the
List dataFile be initialized?

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

> Hi,
> 
> where did you initialize the List dataFile?
> you posted the code incompletly.
> 
> but from your exception it looks like
>   return dataFile.toArray();
> throws a java.lang.NullPointerException.
> 
> Bye
> 
> Caroline Jen wrote:
> > I have gotten rid of the "Argument Type Mismatch"
> > problem.  
> > 
> > I found that if I use UISelectMany, user
> selections
> > from a list box will be in an Object[].
> > 
> > But, I got another runtime error:
> > "EvaluationException: Error getting property
> > 'dataFile' from bean of type
> > actions.FileManagementBean:
> > java.lang.NullPointerException'
> > 
> > Maybe people could help me better now.  I have the
> > getter and setter for the property 'dataFile' in
> my
> > backing bean.  Let me repeat my code.  In my JSP,
> I
> > create a list box:
> > [code]
> > <h:selectManyListbox
> > binding="#{fileManagementBean.dataFile}" size="7"
> >
> >     <f:selectItems
> > value="#{fileManagementBean.dataFileItems}"/>
> > </h:selectManyListbox>
> > [/code]
> > And 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 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] );
> >                 }	
> > 	}
> > 	
> > 	public UISelectMany getDataFileItems() 
> >         {
> > 		return dataFileItems;
> > 	}
> > }
> > [/code]
> > 
> > 
> > 
> > --- Caroline Jen <ji...@yahoo.com> wrote:
> > 
> > 
> >>Hi, I had known how to create selectManyListbox. 
> >>Two
> >>weeks before I posted my question, I had
> >>successfully
> >>used a List of SelectItem to create a list box.  I
> >>do
> >>not want to have pre-selected items when the web
> >>page
> >>is loaded into the browser.
> >>
> >>My problem occurred when I changed the
> dataFileItems
> >>from List to UISelectMany, I started getting
> >>"argument
> >>type mismatch".  
> >>
> >><h:selectManyListbox
> >>binding="#{fileManagementBean.dataFile}" size="7"
> >
> >>    <f:selectItems
> >>value="#{fileManagementBean.dataFileItems}"/>
> >></h:selectManyListbox>
> >>
> >>I am working on how to resolve my current problem.
> >>
> >>Besides, someone advised that "dataFile" should be
> >>of
> >>type SelectItem[].  Therefore, I changed the type
> of
> >>the "dataFile" from String[] to SelectItem[].  I
> >>still
> >>have argument type mismatch problem.
> >>
> >>--- Bruno Aranda <br...@gmail.com> wrote:
> >>
> >>
> >>>Mmmh, if I understood you ok at the beginning we
> >>>have two objectives:
> >>>
> >>>#1 - Have a list filled dinamically with
> >>
> >>SelectItem
> >>
> >>>objects
> >>>#2 - Some of the elements of the list are
> >>>pre-selected when the page loads.
> >>>
> >>>To do #1 we need to use the f:selectItems
> >>
> >>components
> >>
> >>>with a value that
> >>>points to an array/List of SelectItem objects in
> >>
> >>the
> >>
> >>>backing bean.
> >>>Something like this:
> >>>
> >>>[jsp]
> >>>
> >>><h:selectManyListBox>
> >>>  <f:selectItems
> >>>value="#{fileManagementBean.listOfSelectItems}"/>
> >>></h:selectManyListBox>
> >>>
> >>>[/jsp]
> >>>
> >>>Notice that I have used the value attribute of
> the
> >>>selectItems
> >>>component, instead of the binding... The backing
> >>>bean code should be,
> >>>in this case:
> >>>
> >>>[code]
> >>>
> >>>public class FileManagementBean
> >>>{
> >>>       private List listOfSelectItems
> >>>
> >>>       public FileManagementBean()
> >>>       {
> >>>               listOfSelectItems = new
> >>
> >>ArrayList();
> >>
> >>>               SelectItem file = new SelectItem(
> >>>"file1", "Data
> >>>File No. 1");
> >>>               listOfSelectItems.add( file );
> >>>
> >>>               SelectItem file2 = new SelectItem(
> >>>"file2", "Data File No. 2");
> >>>               listOfSelectItems.add( file2 );
> >>>.....
> >>>.....
> >>>       }
> >>>
> >>>       public List getListOfSelectItems() {
> >>>               return dataFileItems;
> >>>       }
> >>>
> >>>     public void setListOfSelectItems(List
> >>>listOfSelectItems) {
> 
=== message truncated ===



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

Re: [Topic Changed] UISelectMany and EvaluationException

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

where did you initialize the List dataFile?
you posted the code incompletly.

but from your exception it looks like
  return dataFile.toArray();
throws a java.lang.NullPointerException.

Bye

Caroline Jen wrote:
> I have gotten rid of the "Argument Type Mismatch"
> problem.  
> 
> I found that if I use UISelectMany, user selections
> from a list box will be in an Object[].
> 
> But, I got another runtime error:
> "EvaluationException: Error getting property
> 'dataFile' from bean of type
> actions.FileManagementBean:
> java.lang.NullPointerException'
> 
> Maybe people could help me better now.  I have the
> getter and setter for the property 'dataFile' in my
> backing bean.  Let me repeat my code.  In my JSP, I
> create a list box:
> [code]
> <h:selectManyListbox
> binding="#{fileManagementBean.dataFile}" size="7" >
>     <f:selectItems
> value="#{fileManagementBean.dataFileItems}"/>
> </h:selectManyListbox>
> [/code]
> And 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 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] );
>                 }	
> 	}
> 	
> 	public UISelectMany getDataFileItems() 
>         {
> 		return dataFileItems;
> 	}
> }
> [/code]
> 
> 
> 
> --- Caroline Jen <ji...@yahoo.com> wrote:
> 
> 
>>Hi, I had known how to create selectManyListbox. 
>>Two
>>weeks before I posted my question, I had
>>successfully
>>used a List of SelectItem to create a list box.  I
>>do
>>not want to have pre-selected items when the web
>>page
>>is loaded into the browser.
>>
>>My problem occurred when I changed the dataFileItems
>>from List to UISelectMany, I started getting
>>"argument
>>type mismatch".  
>>
>><h:selectManyListbox
>>binding="#{fileManagementBean.dataFile}" size="7" >
>>    <f:selectItems
>>value="#{fileManagementBean.dataFileItems}"/>
>></h:selectManyListbox>
>>
>>I am working on how to resolve my current problem.
>>
>>Besides, someone advised that "dataFile" should be
>>of
>>type SelectItem[].  Therefore, I changed the type of
>>the "dataFile" from String[] to SelectItem[].  I
>>still
>>have argument type mismatch problem.
>>
>>--- Bruno Aranda <br...@gmail.com> wrote:
>>
>>
>>>Mmmh, if I understood you ok at the beginning we
>>>have two objectives:
>>>
>>>#1 - Have a list filled dinamically with
>>
>>SelectItem
>>
>>>objects
>>>#2 - Some of the elements of the list are
>>>pre-selected when the page loads.
>>>
>>>To do #1 we need to use the f:selectItems
>>
>>components
>>
>>>with a value that
>>>points to an array/List of SelectItem objects in
>>
>>the
>>
>>>backing bean.
>>>Something like this:
>>>
>>>[jsp]
>>>
>>><h:selectManyListBox>
>>>  <f:selectItems
>>>value="#{fileManagementBean.listOfSelectItems}"/>
>>></h:selectManyListBox>
>>>
>>>[/jsp]
>>>
>>>Notice that I have used the value attribute of the
>>>selectItems
>>>component, instead of the binding... The backing
>>>bean code should be,
>>>in this case:
>>>
>>>[code]
>>>
>>>public class FileManagementBean
>>>{
>>>       private List listOfSelectItems
>>>
>>>       public FileManagementBean()
>>>       {
>>>               listOfSelectItems = new
>>
>>ArrayList();
>>
>>>               SelectItem file = new SelectItem(
>>>"file1", "Data
>>>File No. 1");
>>>               listOfSelectItems.add( file );
>>>
>>>               SelectItem file2 = new SelectItem(
>>>"file2", "Data File No. 2");
>>>               listOfSelectItems.add( file2 );
>>>.....
>>>.....
>>>       }
>>>
>>>       public List getListOfSelectItems() {
>>>               return dataFileItems;
>>>       }
>>>
>>>     public void setListOfSelectItems(List
>>>listOfSelectItems) {
>>>               this.listOfSelectItems =
>>>listOfSelectItems;
>>>       }
>>>}
>>>
>>>[/code]
>>>
>>>After doing this, we should have in our page a
>>
>>list
>>
>>>with two items,
>>>none of them pre-selected.
>>>So, to do #2, we just need to pass an array of the
>>>values for the
>>>items we want to be chosen to the
>>
>>selectManyListBox,
>>
>>>like this:
>>>
>>>[jsp]
>>>
>>><h:selectManyListBox
>>>value="#{fileManagementBean.preSelection}">
>>>  <f:selectItems
>>>value="#{fileManagementBean.listOfSelectItems}"/>
>>></h:selectManyListBox>
>>>
>>>[/jsp]
>>>
>>>[code]
>>>
>>>public class FileManagementBean
>>>{
>>>
>>>public class FileManagementBean
>>>{
>>>       private List listOfSelectItems
>>>       private String[] preSelection;
>>>
>>>       public FileManagementBean()
>>>       {
>>>               listOfSelectItems = new
>>
>>ArrayList();
>>
>>>               SelectItem file = new SelectItem(
>>>"file1", "Data
>>>File No. 1");
>>>               listOfSelectItems.add( file );
>>>
>>>               SelectItem file2 = new SelectItem(
>>>"file2", "Data File No. 2");
>>>               listOfSelectItems.add( file2 );
>>>
>>>               // pre-selection
>>>              preSelection = new String[]
>>
>>{"file2"};
>>
>>>// file2 is pre-selected
>>>.....
>>>.....
>>>       }
>>>
>>>       public String[] getPreSelection() {
>>>               return dataFileItems;
>>>       }
>>>
>>>     public void setPreSelection(String[]
>>>preSelection) {
>>>               this.preSelection = preSelection;
>>>       }
>>>
>>>....
>>>}
>>>
>>>}
>>>
>>>[/code]
>>>
>>>Hope that helps.... :-)
>>>
>>>Bruno
>>>
>>>
>>>2005/10/11, Caroline Jen <ji...@yahoo.com>:
>>>
>>>>Sorry, I am completely confused.
>>>>
>>>>OKay, here is my JSP:
>>>>
>>>>[code]
>>>>         <h:selectManyListbox
>>>> binding="#{fileManagementBean.dataFile}"
>>
>>size="7"
>>
>>>>             <f:selectItems
>>>> value="#{fileManagementBean.dataFileItems}"/>
>>>>         </h:selectManyListbox>
>>>>[/code]
>>>>
>>>>In my backing bean, I have changed String[]
>>>
>>>dataFile
>>>
>>>>to SelectItem[] dataFile.
>>>>
>>>><f:selectItems> cannot bind to UISelectMany? 
>>
>>The
>>
>>>>dataFileItems is of UISelectMany type in my
>>>
>>>backing
>>>
>>>>bean.  What should I do?
>>>>
>>>>In your code provided:
>>>><f:selectItems
>>>>value="#{fileManagementBean.listOfSelectItems}/>
>>>>
>>>>How do I do it?
>>
> === message truncated ===
> 
> 
> 
> 		
> __________________________________ 
> Yahoo! Music Unlimited 
> Access over 1 million songs. Try it free.
> http://music.yahoo.com/unlimited/
> 

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

[Topic Changed] UISelectMany and EvaluationException

Posted by Caroline Jen <ji...@yahoo.com>.
I have gotten rid of the "Argument Type Mismatch"
problem.  

I found that if I use UISelectMany, user selections
from a list box will be in an Object[].

But, I got another runtime error:
"EvaluationException: Error getting property
'dataFile' from bean of type
actions.FileManagementBean:
java.lang.NullPointerException'

Maybe people could help me better now.  I have the
getter and setter for the property 'dataFile' in my
backing bean.  Let me repeat my code.  In my JSP, I
create a list box:
[code]
<h:selectManyListbox
binding="#{fileManagementBean.dataFile}" size="7" >
    <f:selectItems
value="#{fileManagementBean.dataFileItems}"/>
</h:selectManyListbox>
[/code]
And 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 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] );
                }	
	}
	
	public UISelectMany getDataFileItems() 
        {
		return dataFileItems;
	}
}
[/code]



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

> Hi, I had known how to create selectManyListbox. 
> Two
> weeks before I posted my question, I had
> successfully
> used a List of SelectItem to create a list box.  I
> do
> not want to have pre-selected items when the web
> page
> is loaded into the browser.
> 
> My problem occurred when I changed the dataFileItems
> from List to UISelectMany, I started getting
> "argument
> type mismatch".  
> 
> <h:selectManyListbox
> binding="#{fileManagementBean.dataFile}" size="7" >
>     <f:selectItems
> value="#{fileManagementBean.dataFileItems}"/>
> </h:selectManyListbox>
> 
> I am working on how to resolve my current problem.
> 
> Besides, someone advised that "dataFile" should be
> of
> type SelectItem[].  Therefore, I changed the type of
> the "dataFile" from String[] to SelectItem[].  I
> still
> have argument type mismatch problem.
> 
> --- Bruno Aranda <br...@gmail.com> wrote:
> 
> > Mmmh, if I understood you ok at the beginning we
> > have two objectives:
> > 
> > #1 - Have a list filled dinamically with
> SelectItem
> > objects
> > #2 - Some of the elements of the list are
> > pre-selected when the page loads.
> > 
> > To do #1 we need to use the f:selectItems
> components
> > with a value that
> > points to an array/List of SelectItem objects in
> the
> > backing bean.
> > Something like this:
> > 
> > [jsp]
> > 
> > <h:selectManyListBox>
> >   <f:selectItems
> > value="#{fileManagementBean.listOfSelectItems}"/>
> > </h:selectManyListBox>
> > 
> > [/jsp]
> > 
> > Notice that I have used the value attribute of the
> > selectItems
> > component, instead of the binding... The backing
> > bean code should be,
> > in this case:
> > 
> > [code]
> > 
> > public class FileManagementBean
> > {
> >        private List listOfSelectItems
> > 
> >        public FileManagementBean()
> >        {
> >                listOfSelectItems = new
> ArrayList();
> >                SelectItem file = new SelectItem(
> > "file1", "Data
> > File No. 1");
> >                listOfSelectItems.add( file );
> > 
> >                SelectItem file2 = new SelectItem(
> > "file2", "Data File No. 2");
> >                listOfSelectItems.add( file2 );
> > .....
> > .....
> >        }
> > 
> >        public List getListOfSelectItems() {
> >                return dataFileItems;
> >        }
> > 
> >      public void setListOfSelectItems(List
> > listOfSelectItems) {
> >                this.listOfSelectItems =
> > listOfSelectItems;
> >        }
> > }
> > 
> > [/code]
> > 
> > After doing this, we should have in our page a
> list
> > with two items,
> > none of them pre-selected.
> > So, to do #2, we just need to pass an array of the
> > values for the
> > items we want to be chosen to the
> selectManyListBox,
> > like this:
> > 
> > [jsp]
> > 
> > <h:selectManyListBox
> > value="#{fileManagementBean.preSelection}">
> >   <f:selectItems
> > value="#{fileManagementBean.listOfSelectItems}"/>
> > </h:selectManyListBox>
> > 
> > [/jsp]
> > 
> > [code]
> > 
> > public class FileManagementBean
> > {
> > 
> > public class FileManagementBean
> > {
> >        private List listOfSelectItems
> >        private String[] preSelection;
> > 
> >        public FileManagementBean()
> >        {
> >                listOfSelectItems = new
> ArrayList();
> >                SelectItem file = new SelectItem(
> > "file1", "Data
> > File No. 1");
> >                listOfSelectItems.add( file );
> > 
> >                SelectItem file2 = new SelectItem(
> > "file2", "Data File No. 2");
> >                listOfSelectItems.add( file2 );
> > 
> >                // pre-selection
> >               preSelection = new String[]
> {"file2"};
> > // file2 is pre-selected
> > .....
> > .....
> >        }
> > 
> >        public String[] getPreSelection() {
> >                return dataFileItems;
> >        }
> > 
> >      public void setPreSelection(String[]
> > preSelection) {
> >                this.preSelection = preSelection;
> >        }
> > 
> > ....
> > }
> > 
> > }
> > 
> > [/code]
> > 
> > Hope that helps.... :-)
> > 
> > Bruno
> > 
> > 
> > 2005/10/11, Caroline Jen <ji...@yahoo.com>:
> > > Sorry, I am completely confused.
> > >
> > > OKay, here is my JSP:
> > >
> > > [code]
> > >          <h:selectManyListbox
> > >  binding="#{fileManagementBean.dataFile}"
> size="7"
> > >
> > >              <f:selectItems
> > >  value="#{fileManagementBean.dataFileItems}"/>
> > >          </h:selectManyListbox>
> > > [/code]
> > >
> > > In my backing bean, I have changed String[]
> > dataFile
> > > to SelectItem[] dataFile.
> > >
> > > <f:selectItems> cannot bind to UISelectMany? 
> The
> > > dataFileItems is of UISelectMany type in my
> > backing
> > > bean.  What should I do?
> > >
> > > In your code provided:
> > > <f:selectItems
> > > value="#{fileManagementBean.listOfSelectItems}/>
> > >
> > > How do I do it?
> 
=== message truncated ===



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

Re: UISelectMany and Argument Type Mismatch

Posted by Caroline Jen <ji...@yahoo.com>.
Hi, I had known how to create selectManyListbox.  Two
weeks before I posted my question, I had successfully
used a List of SelectItem to create a list box.  I do
not want to have pre-selected items when the web page
is loaded into the browser.

My problem occurred when I changed the dataFileItems
from List to UISelectMany, I started getting "argument
type mismatch".  

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

I am working on how to resolve my current problem.

Besides, someone advised that "dataFile" should be of
type SelectItem[].  Therefore, I changed the type of
the "dataFile" from String[] to SelectItem[].  I still
have argument type mismatch problem.

--- Bruno Aranda <br...@gmail.com> wrote:

> Mmmh, if I understood you ok at the beginning we
> have two objectives:
> 
> #1 - Have a list filled dinamically with SelectItem
> objects
> #2 - Some of the elements of the list are
> pre-selected when the page loads.
> 
> To do #1 we need to use the f:selectItems components
> with a value that
> points to an array/List of SelectItem objects in the
> backing bean.
> Something like this:
> 
> [jsp]
> 
> <h:selectManyListBox>
>   <f:selectItems
> value="#{fileManagementBean.listOfSelectItems}"/>
> </h:selectManyListBox>
> 
> [/jsp]
> 
> Notice that I have used the value attribute of the
> selectItems
> component, instead of the binding... The backing
> bean code should be,
> in this case:
> 
> [code]
> 
> public class FileManagementBean
> {
>        private List listOfSelectItems
> 
>        public FileManagementBean()
>        {
>                listOfSelectItems = new ArrayList();
>                SelectItem file = new SelectItem(
> "file1", "Data
> File No. 1");
>                listOfSelectItems.add( file );
> 
>                SelectItem file2 = new SelectItem(
> "file2", "Data File No. 2");
>                listOfSelectItems.add( file2 );
> .....
> .....
>        }
> 
>        public List getListOfSelectItems() {
>                return dataFileItems;
>        }
> 
>      public void setListOfSelectItems(List
> listOfSelectItems) {
>                this.listOfSelectItems =
> listOfSelectItems;
>        }
> }
> 
> [/code]
> 
> After doing this, we should have in our page a list
> with two items,
> none of them pre-selected.
> So, to do #2, we just need to pass an array of the
> values for the
> items we want to be chosen to the selectManyListBox,
> like this:
> 
> [jsp]
> 
> <h:selectManyListBox
> value="#{fileManagementBean.preSelection}">
>   <f:selectItems
> value="#{fileManagementBean.listOfSelectItems}"/>
> </h:selectManyListBox>
> 
> [/jsp]
> 
> [code]
> 
> public class FileManagementBean
> {
> 
> public class FileManagementBean
> {
>        private List listOfSelectItems
>        private String[] preSelection;
> 
>        public FileManagementBean()
>        {
>                listOfSelectItems = new ArrayList();
>                SelectItem file = new SelectItem(
> "file1", "Data
> File No. 1");
>                listOfSelectItems.add( file );
> 
>                SelectItem file2 = new SelectItem(
> "file2", "Data File No. 2");
>                listOfSelectItems.add( file2 );
> 
>                // pre-selection
>               preSelection = new String[] {"file2"};
> // file2 is pre-selected
> .....
> .....
>        }
> 
>        public String[] getPreSelection() {
>                return dataFileItems;
>        }
> 
>      public void setPreSelection(String[]
> preSelection) {
>                this.preSelection = preSelection;
>        }
> 
> ....
> }
> 
> }
> 
> [/code]
> 
> Hope that helps.... :-)
> 
> Bruno
> 
> 
> 2005/10/11, Caroline Jen <ji...@yahoo.com>:
> > Sorry, I am completely confused.
> >
> > OKay, here is my JSP:
> >
> > [code]
> >          <h:selectManyListbox
> >  binding="#{fileManagementBean.dataFile}" size="7"
> >
> >              <f:selectItems
> >  value="#{fileManagementBean.dataFileItems}"/>
> >          </h:selectManyListbox>
> > [/code]
> >
> > In my backing bean, I have changed String[]
> dataFile
> > to SelectItem[] dataFile.
> >
> > <f:selectItems> cannot bind to UISelectMany?  The
> > dataFileItems is of UISelectMany type in my
> backing
> > bean.  What should I do?
> >
> > In your code provided:
> > <f:selectItems
> > value="#{fileManagementBean.listOfSelectItems}/>
> >
> > How do I do it?
> >
> >
> > --- Bruno Aranda <br...@gmail.com> wrote:
> >
> > > Your code is not ok. You are binding the faces
> > > components to wrong
> > > types: h:selectManyListbox cannot be bound to
> > > String[] and
> > > f:selectItems cannot be bound to an instance of
> > > UISelectMany....
> > >
> > > The best pattern here is to pass an Array/List
> of
> > > SelectItem objects
> > > to the value of your f:selectItems component,
> like
> > > this:
> > >
> > > <h:selectManyListbox
> > > value="#{fileManagementBean.dataFile}">
> > >     <f:selectItem
> > > value="#{fileManagementBean.listOfSelectItems}/>
> > > </h:selectManyListbox>
> > >
> > > And also note that to have some values selected
> when
> > > the page is
> > > loaded you have to use the @value attribute.
> > >
> > > Regards,
> > >
> > > Bruno
> > >
> > > 2005/10/11, Caroline Jen <ji...@yahoo.com>:
> > > > I used the UISelectItem to set its value to
> the
> > > > SelectItem (I have many SelectItme).  Then,  I
> > > added
> > > > each UISelectItem to the UISelectMany .  When
> I
> > > > displayed a list box, I got the runtime error:
> > > >
> 
=== message truncated ===



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

Re: UISelectMany and Argument Type Mismatch

Posted by Bruno Aranda <br...@gmail.com>.
Mmmh, if I understood you ok at the beginning we have two objectives:

#1 - Have a list filled dinamically with SelectItem objects
#2 - Some of the elements of the list are pre-selected when the page loads.

To do #1 we need to use the f:selectItems components with a value that
points to an array/List of SelectItem objects in the backing bean.
Something like this:

[jsp]

<h:selectManyListBox>
  <f:selectItems value="#{fileManagementBean.listOfSelectItems}"/>
</h:selectManyListBox>

[/jsp]

Notice that I have used the value attribute of the selectItems
component, instead of the binding... The backing bean code should be,
in this case:

[code]

public class FileManagementBean
{
       private List listOfSelectItems

       public FileManagementBean()
       {
               listOfSelectItems = new ArrayList();
               SelectItem file = new SelectItem( "file1", "Data
File No. 1");
               listOfSelectItems.add( file );

               SelectItem file2 = new SelectItem( "file2", "Data File No. 2");
               listOfSelectItems.add( file2 );
.....
.....
       }

       public List getListOfSelectItems() {
               return dataFileItems;
       }

     public void setListOfSelectItems(List listOfSelectItems) {
               this.listOfSelectItems = listOfSelectItems;
       }
}

[/code]

After doing this, we should have in our page a list with two items,
none of them pre-selected.
So, to do #2, we just need to pass an array of the values for the
items we want to be chosen to the selectManyListBox, like this:

[jsp]

<h:selectManyListBox value="#{fileManagementBean.preSelection}">
  <f:selectItems value="#{fileManagementBean.listOfSelectItems}"/>
</h:selectManyListBox>

[/jsp]

[code]

public class FileManagementBean
{

public class FileManagementBean
{
       private List listOfSelectItems
       private String[] preSelection;

       public FileManagementBean()
       {
               listOfSelectItems = new ArrayList();
               SelectItem file = new SelectItem( "file1", "Data
File No. 1");
               listOfSelectItems.add( file );

               SelectItem file2 = new SelectItem( "file2", "Data File No. 2");
               listOfSelectItems.add( file2 );

               // pre-selection
              preSelection = new String[] {"file2"}; // file2 is pre-selected
.....
.....
       }

       public String[] getPreSelection() {
               return dataFileItems;
       }

     public void setPreSelection(String[] preSelection) {
               this.preSelection = preSelection;
       }

....
}

}

[/code]

Hope that helps.... :-)

Bruno


2005/10/11, Caroline Jen <ji...@yahoo.com>:
> Sorry, I am completely confused.
>
> OKay, here is my JSP:
>
> [code]
>          <h:selectManyListbox
>  binding="#{fileManagementBean.dataFile}" size="7" >
>              <f:selectItems
>  value="#{fileManagementBean.dataFileItems}"/>
>          </h:selectManyListbox>
> [/code]
>
> In my backing bean, I have changed String[] dataFile
> to SelectItem[] dataFile.
>
> <f:selectItems> cannot bind to UISelectMany?  The
> dataFileItems is of UISelectMany type in my backing
> bean.  What should I do?
>
> In your code provided:
> <f:selectItems
> value="#{fileManagementBean.listOfSelectItems}/>
>
> How do I do it?
>
>
> --- Bruno Aranda <br...@gmail.com> wrote:
>
> > Your code is not ok. You are binding the faces
> > components to wrong
> > types: h:selectManyListbox cannot be bound to
> > String[] and
> > f:selectItems cannot be bound to an instance of
> > UISelectMany....
> >
> > The best pattern here is to pass an Array/List of
> > SelectItem objects
> > to the value of your f:selectItems component, like
> > this:
> >
> > <h:selectManyListbox
> > value="#{fileManagementBean.dataFile}">
> >     <f:selectItem
> > value="#{fileManagementBean.listOfSelectItems}/>
> > </h:selectManyListbox>
> >
> > And also note that to have some values selected when
> > the page is
> > loaded you have to use the @value attribute.
> >
> > Regards,
> >
> > Bruno
> >
> > 2005/10/11, Caroline Jen <ji...@yahoo.com>:
> > > I used the UISelectItem to set its value to the
> > > SelectItem (I have many SelectItme).  Then,  I
> > added
> > > each UISelectItem to the UISelectMany .  When I
> > > displayed a list box, I got the runtime error:
> > >
> > > "IllegalArgumentException: argument type mismatch"
> > >
> > > In my JSP, I create a list box for multiple
> > > selections:
> > >
> > > [code]
> > >         <h:selectManyListbox
> > > binding="#{fileManagementBean.dataFile}" size="7"
> > >
> > >             <f:selectItems
> > > value="#{fileManagementBean.dataFileItems}"/>
> > >         </h:selectManyListbox>
> > > [/code]
> > >
> > > Therefore, the "dataFileItems" is of type
> > UISelectMany
> > > that has elements of type UISelectItem.  The
> > multiple
> > > selections that users make will be in a String
> > array:
> > > String[] dataFile.  Did I mess up anything here?
> > My
> > > backing bean code is like:
> > >
> > > [code]
> > > .....
> > > .....
> > > public class FileManagementBean
> > > {
> > >         private String[] dataFile;
> > >         private UISelectMany dataFileItems;
> > >
> > >         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 String[] getDataFile() {
> > >                 return dataFile;
> > >         }
> > >
> > >         public void setDataFile( String[] dataFile
> > ) {
> > >                 this.dataFile = dataFile;
> > >         }
> > >
> > >         public UISelectMany getDataFileItems() {
> > >                 return dataFileItems;
> > >         }
> > > }
> > > [/code]
> > >
> > >
> > >
> > >
> > > __________________________________
> > > Yahoo! Mail - PC Magazine Editors' Choice 2005
> > > http://mail.yahoo.com
> > >
> >
>
>
>
>
> __________________________________
> Yahoo! Music Unlimited
> Access over 1 million songs. Try it free.
> http://music.yahoo.com/unlimited/
>

Re: UISelectMany and Argument Type Mismatch

Posted by Bruno Aranda <br...@gmail.com>.
Yes, this is what I mean, and what I thought you were also trying to
do in your example. The 'value' attribute:

<h:selectManyListbox VALUE="pre-selection">

I could speak english better in a previous life :-)

Bruno

2005/10/11, Caroline Jen <ji...@yahoo.com>:
> Thanks for your reply.
>
> [QUOTE]
> to have some values selected when the page is
> loaded you have to use the @value attribute.
> [/QUOTE]
>
> What is @value attribute?  I am completely confused by
> the sentence.  Do you mean if I want to display some
> pre-selected values when the page is loaded?
>
> --- Bruno Aranda <br...@gmail.com> wrote:
>
> > Your code is not ok. You are binding the faces
> > components to wrong
> > types: h:selectManyListbox cannot be bound to
> > String[] and
> > f:selectItems cannot be bound to an instance of
> > UISelectMany....
> >
> > The best pattern here is to pass an Array/List of
> > SelectItem objects
> > to the value of your f:selectItems component, like
> > this:
> >
> > <h:selectManyListbox
> > value="#{fileManagementBean.dataFile}">
> >     <f:selectItem
> > value="#{fileManagementBean.listOfSelectItems}/>
> > </h:selectManyListbox>
> >
> > And also note that to have some values selected when
> > the page is
> > loaded you have to use the @value attribute.
> >
> > Regards,
> >
> > Bruno
> >
> > 2005/10/11, Caroline Jen <ji...@yahoo.com>:
> > > I used the UISelectItem to set its value to the
> > > SelectItem (I have many SelectItme).  Then,  I
> > added
> > > each UISelectItem to the UISelectMany .  When I
> > > displayed a list box, I got the runtime error:
> > >
> > > "IllegalArgumentException: argument type mismatch"
> > >
> > > In my JSP, I create a list box for multiple
> > > selections:
> > >
> > > [code]
> > >         <h:selectManyListbox
> > > binding="#{fileManagementBean.dataFile}" size="7"
> > >
> > >             <f:selectItems
> > > value="#{fileManagementBean.dataFileItems}"/>
> > >         </h:selectManyListbox>
> > > [/code]
> > >
> > > Therefore, the "dataFileItems" is of type
> > UISelectMany
> > > that has elements of type UISelectItem.  The
> > multiple
> > > selections that users make will be in a String
> > array:
> > > String[] dataFile.  Did I mess up anything here?
> > My
> > > backing bean code is like:
> > >
> > > [code]
> > > .....
> > > .....
> > > public class FileManagementBean
> > > {
> > >         private String[] dataFile;
> > >         private UISelectMany dataFileItems;
> > >
> > >         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 String[] getDataFile() {
> > >                 return dataFile;
> > >         }
> > >
> > >         public void setDataFile( String[] dataFile
> > ) {
> > >                 this.dataFile = dataFile;
> > >         }
> > >
> > >         public UISelectMany getDataFileItems() {
> > >                 return dataFileItems;
> > >         }
> > > }
> > > [/code]
> > >
> > >
> > >
> > >
> > > __________________________________
> > > Yahoo! Mail - PC Magazine Editors' Choice 2005
> > > http://mail.yahoo.com
> > >
> >
>
>
>
>
> __________________________________
> Yahoo! Music Unlimited
> Access over 1 million songs. Try it free.
> http://music.yahoo.com/unlimited/
>

Re: UISelectMany and Argument Type Mismatch

Posted by Bruno Aranda <br...@gmail.com>.
Well, I wanted to put <f:selectItems instead of <f:selectItem in my example ;-)

Regards,

Bruno

2005/10/11, Bruno Aranda <br...@gmail.com>:
> Your code is not ok. You are binding the faces components to wrong
> types: h:selectManyListbox cannot be bound to String[] and
> f:selectItems cannot be bound to an instance of UISelectMany....
>
> The best pattern here is to pass an Array/List of SelectItem objects
> to the value of your f:selectItems component, like this:
>
> <h:selectManyListbox value="#{fileManagementBean.dataFile}">
>     <f:selectItem value="#{fileManagementBean.listOfSelectItems}/>
> </h:selectManyListbox>
>
> And also note that to have some values selected when the page is
> loaded you have to use the @value attribute.
>
> Regards,
>
> Bruno
>
> 2005/10/11, Caroline Jen <ji...@yahoo.com>:
> > I used the UISelectItem to set its value to the
> > SelectItem (I have many SelectItme).  Then,  I added
> > each UISelectItem to the UISelectMany .  When I
> > displayed a list box, I got the runtime error:
> >
> > "IllegalArgumentException: argument type mismatch"
> >
> > In my JSP, I create a list box for multiple
> > selections:
> >
> > [code]
> >         <h:selectManyListbox
> > binding="#{fileManagementBean.dataFile}" size="7" >
> >             <f:selectItems
> > value="#{fileManagementBean.dataFileItems}"/>
> >         </h:selectManyListbox>
> > [/code]
> >
> > Therefore, the "dataFileItems" is of type UISelectMany
> > that has elements of type UISelectItem.  The multiple
> > selections that users make will be in a String array:
> > String[] dataFile.  Did I mess up anything here?  My
> > backing bean code is like:
> >
> > [code]
> > .....
> > .....
> > public class FileManagementBean
> > {
> >         private String[] dataFile;
> >         private UISelectMany dataFileItems;
> >
> >         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 String[] getDataFile() {
> >                 return dataFile;
> >         }
> >
> >         public void setDataFile( String[] dataFile ) {
> >                 this.dataFile = dataFile;
> >         }
> >
> >         public UISelectMany getDataFileItems() {
> >                 return dataFileItems;
> >         }
> > }
> > [/code]
> >
> >
> >
> >
> > __________________________________
> > Yahoo! Mail - PC Magazine Editors' Choice 2005
> > http://mail.yahoo.com
> >
>

Re: UISelectMany and Argument Type Mismatch

Posted by Caroline Jen <ji...@yahoo.com>.
Sorry, I am completely confused.

OKay, here is my JSP:

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

In my backing bean, I have changed String[] dataFile
to SelectItem[] dataFile.

<f:selectItems> cannot bind to UISelectMany?  The
dataFileItems is of UISelectMany type in my backing
bean.  What should I do?

In your code provided:
<f:selectItems
value="#{fileManagementBean.listOfSelectItems}/>

How do I do it?


--- Bruno Aranda <br...@gmail.com> wrote:

> Your code is not ok. You are binding the faces
> components to wrong
> types: h:selectManyListbox cannot be bound to
> String[] and
> f:selectItems cannot be bound to an instance of
> UISelectMany....
> 
> The best pattern here is to pass an Array/List of
> SelectItem objects
> to the value of your f:selectItems component, like
> this:
> 
> <h:selectManyListbox
> value="#{fileManagementBean.dataFile}">
>     <f:selectItem
> value="#{fileManagementBean.listOfSelectItems}/>
> </h:selectManyListbox>
> 
> And also note that to have some values selected when
> the page is
> loaded you have to use the @value attribute.
> 
> Regards,
> 
> Bruno
> 
> 2005/10/11, Caroline Jen <ji...@yahoo.com>:
> > I used the UISelectItem to set its value to the
> > SelectItem (I have many SelectItme).  Then,  I
> added
> > each UISelectItem to the UISelectMany .  When I
> > displayed a list box, I got the runtime error:
> >
> > "IllegalArgumentException: argument type mismatch"
> >
> > In my JSP, I create a list box for multiple
> > selections:
> >
> > [code]
> >         <h:selectManyListbox
> > binding="#{fileManagementBean.dataFile}" size="7"
> >
> >             <f:selectItems
> > value="#{fileManagementBean.dataFileItems}"/>
> >         </h:selectManyListbox>
> > [/code]
> >
> > Therefore, the "dataFileItems" is of type
> UISelectMany
> > that has elements of type UISelectItem.  The
> multiple
> > selections that users make will be in a String
> array:
> > String[] dataFile.  Did I mess up anything here? 
> My
> > backing bean code is like:
> >
> > [code]
> > .....
> > .....
> > public class FileManagementBean
> > {
> >         private String[] dataFile;
> >         private UISelectMany dataFileItems;
> >
> >         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 String[] getDataFile() {
> >                 return dataFile;
> >         }
> >
> >         public void setDataFile( String[] dataFile
> ) {
> >                 this.dataFile = dataFile;
> >         }
> >
> >         public UISelectMany getDataFileItems() {
> >                 return dataFileItems;
> >         }
> > }
> > [/code]
> >
> >
> >
> >
> > __________________________________
> > Yahoo! Mail - PC Magazine Editors' Choice 2005
> > http://mail.yahoo.com
> >
> 



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

Re: UISelectMany and Argument Type Mismatch

Posted by Caroline Jen <ji...@yahoo.com>.
Thanks for your reply.

[QUOTE]
to have some values selected when the page is
loaded you have to use the @value attribute.
[/QUOTE]

What is @value attribute?  I am completely confused by
the sentence.  Do you mean if I want to display some
pre-selected values when the page is loaded?

--- Bruno Aranda <br...@gmail.com> wrote:

> Your code is not ok. You are binding the faces
> components to wrong
> types: h:selectManyListbox cannot be bound to
> String[] and
> f:selectItems cannot be bound to an instance of
> UISelectMany....
> 
> The best pattern here is to pass an Array/List of
> SelectItem objects
> to the value of your f:selectItems component, like
> this:
> 
> <h:selectManyListbox
> value="#{fileManagementBean.dataFile}">
>     <f:selectItem
> value="#{fileManagementBean.listOfSelectItems}/>
> </h:selectManyListbox>
> 
> And also note that to have some values selected when
> the page is
> loaded you have to use the @value attribute.
> 
> Regards,
> 
> Bruno
> 
> 2005/10/11, Caroline Jen <ji...@yahoo.com>:
> > I used the UISelectItem to set its value to the
> > SelectItem (I have many SelectItme).  Then,  I
> added
> > each UISelectItem to the UISelectMany .  When I
> > displayed a list box, I got the runtime error:
> >
> > "IllegalArgumentException: argument type mismatch"
> >
> > In my JSP, I create a list box for multiple
> > selections:
> >
> > [code]
> >         <h:selectManyListbox
> > binding="#{fileManagementBean.dataFile}" size="7"
> >
> >             <f:selectItems
> > value="#{fileManagementBean.dataFileItems}"/>
> >         </h:selectManyListbox>
> > [/code]
> >
> > Therefore, the "dataFileItems" is of type
> UISelectMany
> > that has elements of type UISelectItem.  The
> multiple
> > selections that users make will be in a String
> array:
> > String[] dataFile.  Did I mess up anything here? 
> My
> > backing bean code is like:
> >
> > [code]
> > .....
> > .....
> > public class FileManagementBean
> > {
> >         private String[] dataFile;
> >         private UISelectMany dataFileItems;
> >
> >         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 String[] getDataFile() {
> >                 return dataFile;
> >         }
> >
> >         public void setDataFile( String[] dataFile
> ) {
> >                 this.dataFile = dataFile;
> >         }
> >
> >         public UISelectMany getDataFileItems() {
> >                 return dataFileItems;
> >         }
> > }
> > [/code]
> >
> >
> >
> >
> > __________________________________
> > Yahoo! Mail - PC Magazine Editors' Choice 2005
> > http://mail.yahoo.com
> >
> 



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

Re: UISelectMany and Argument Type Mismatch

Posted by Bruno Aranda <br...@gmail.com>.
Your code is not ok. You are binding the faces components to wrong
types: h:selectManyListbox cannot be bound to String[] and
f:selectItems cannot be bound to an instance of UISelectMany....

The best pattern here is to pass an Array/List of SelectItem objects
to the value of your f:selectItems component, like this:

<h:selectManyListbox value="#{fileManagementBean.dataFile}">
    <f:selectItem value="#{fileManagementBean.listOfSelectItems}/>
</h:selectManyListbox>

And also note that to have some values selected when the page is
loaded you have to use the @value attribute.

Regards,

Bruno

2005/10/11, Caroline Jen <ji...@yahoo.com>:
> I used the UISelectItem to set its value to the
> SelectItem (I have many SelectItme).  Then,  I added
> each UISelectItem to the UISelectMany .  When I
> displayed a list box, I got the runtime error:
>
> "IllegalArgumentException: argument type mismatch"
>
> In my JSP, I create a list box for multiple
> selections:
>
> [code]
>         <h:selectManyListbox
> binding="#{fileManagementBean.dataFile}" size="7" >
>             <f:selectItems
> value="#{fileManagementBean.dataFileItems}"/>
>         </h:selectManyListbox>
> [/code]
>
> Therefore, the "dataFileItems" is of type UISelectMany
> that has elements of type UISelectItem.  The multiple
> selections that users make will be in a String array:
> String[] dataFile.  Did I mess up anything here?  My
> backing bean code is like:
>
> [code]
> .....
> .....
> public class FileManagementBean
> {
>         private String[] dataFile;
>         private UISelectMany dataFileItems;
>
>         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 String[] getDataFile() {
>                 return dataFile;
>         }
>
>         public void setDataFile( String[] dataFile ) {
>                 this.dataFile = dataFile;
>         }
>
>         public UISelectMany getDataFileItems() {
>                 return dataFileItems;
>         }
> }
> [/code]
>
>
>
>
> __________________________________
> Yahoo! Mail - PC Magazine Editors' Choice 2005
> http://mail.yahoo.com
>

RE: UISelectMany and Argument Type Mismatch

Posted by Guillermo Meyer <gm...@interbanking.com.ar>.
dataFileItems in the backing bean should return a Map or an array of
SelectItem[].

Regards.
Guillermo.

-----Original Message-----
From: Caroline Jen [mailto:jiapei_jen@yahoo.com] 
Sent: Martes, 11 de Octubre de 2005 10:27 a.m.
To: users@myfaces.apache.org
Subject: UISelectMany and Argument Type Mismatch

I used the UISelectItem to set its value to the
SelectItem (I have many SelectItme).  Then,  I added
each UISelectItem to the UISelectMany .  When I
displayed a list box, I got the runtime error:

"IllegalArgumentException: argument type mismatch"

In my JSP, I create a list box for multiple
selections: 

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

Therefore, the "dataFileItems" is of type UISelectMany
that has elements of type UISelectItem.  The multiple
selections that users make will be in a String array:
String[] dataFile.  Did I mess up anything here?  My
backing bean code is like:

[code]
.....
.....
public class FileManagementBean 
{
	private String[] dataFile;
	private UISelectMany dataFileItems;
	
	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 String[] getDataFile() {
		return dataFile;
	}

	public void setDataFile( String[] dataFile ) {
		this.dataFile = dataFile;
	}

	public UISelectMany getDataFileItems() {
		return dataFileItems;
	}
}
[/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.