You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Bruno Aranda <br...@gmail.com> on 2006/04/28 10:31:12 UTC
Re: UISelectMany and Argument Type Mismatch
Bonnie, you should address this questions to the user mailing list,
where you will get better and faster feedback.
Comments inline:
On 4/28/06, Bonnie SM TANG <ta...@smtpgw.rthk.org.hk> wrote:
>
>
>
>
> Hi, Bruno,
>
> I read your message dated 11 Oct 2005 about UISelectMany below. I have some
> question and hope you may help me out.
>
>
>
> 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.... :-)
>
>
>
>
>
> In your getPreSelection() your return dataFileItems. Is it a typo of
> PreSection ? I successfully follow your step1 but failed in step2 with
> array out of bound exception. What am I doing wrong ? any idea?
>
Yes it is a typo, it should be returnPreSelection (note that is
selection and not section).
> What is the difference of using binding=#{bean.field} and
> value=#{bean.field} in the jsp selectManyListBox ? (Note: you're using
> binding while Caroline Jen using value)
>
I guess, it is the opposite, I used value and Caroline binding? With
"binding" you create a reference to the component that can be used in
a backing bean, so you can handle the component directly in the bean.
For instance you could have an instance of UISelectMany (e.g. called
myList in the backing bean and use <h:selectManyListBox
binding="#{bean.myList}", so thus you can access to the attributes of
the UISelectMany from the bean. The value attribute allows you in a
selectMany to know the value of the items selected. This is way we use
the value in the preselection, to tell that when loading the
selectMany should have those values...
>
> Sorry! the questions may be very dum but please forgive for I'm a newbie.
>
>
>
There are no such thing as "dumb questions". Questions of any type are
more than welcome, but please, on the mailing list!
Cheers,
Bruno