aspose file tools*
The moose likes JSF and the fly likes Is it possible to have a selectManyListBox within <ui:repeat> ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Is it possible to have a selectManyListBox within <ui:repeat> ?" Watch "Is it possible to have a selectManyListBox within <ui:repeat> ?" New topic
Author

Is it possible to have a selectManyListBox within <ui:repeat> ?

michael nik
Greenhorn

Joined: Mar 11, 2012
Posts: 15
Can I have a selectManyListBox within a <ui:repeat> or that is completely wrong ? I can displayed the values properly , however I cant retrieve the selected items in my list.

An error is displayed "myform:j_idt117:0:j_idt119:0:_t121: Validation Error: Value is not valid"

Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16063
    
  21

I recommend using the h:dataTable tag whenever you want to repeat UI elements in a tabular format (including single-column tables). ui:repeat is best left for less-structured elements.

You will find debugging a lot easier if you include your own "id=" attributes on the various XML elements. Otherwise JSF will automatically generate IDs, and when errors display, those IDs can be hard to resolve back to find the offending component.

When you have a collection of SelectItems, it's a lot simpler to simply use the "f:selectItems" tag than to manually code individual selectItems.

And finally, the answer you've been waiting for: The validation error comes when the list selection(s) reference values that aren't in the selectItem collection.


Customer surveys are for companies who didn't pay proper attention to begin with.
michael nik
Greenhorn

Joined: Mar 11, 2012
Posts: 15
Thank you for your answers are really helpful.

Now, I tried to do it using data tables or using selectManyListBox and both of the cases are displaying properly in the browser. My problem is when the user submits the selected items then I cant take the user's inputs, they do not save in my arrayList.

When I tried to put id's, each iteration build a new selectManyListBox with the same id but with different values, i receive an error message that Component ID myform:myKey has already been found in the view.

I tried to solve it by putting an increment variable in id="count" and from java e.g count++ but logically it does not work. Is this the reason that I cannot take the user's inputs ?

Another remarkable thing that I noticed is that: by using a selectManyListbox tag within a data table I can only retrieve user's input if the selected items belong to the last selectManyListbox that is created.


Do you have any suggestions?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16063
    
  21

You need to understand about how a DataModel works. And, for that matter, how Inversion of Control works. In IoC, you don't "retrieve" values, the values are set for you automatically in the Model by the Controller (JSF).

You defined the receiving property of your selectManyListBox as a property of myBean. Consider: you have ONE myBean and MULTIPLE selectManyListBoxes. Can you be surprised if only one of them sets the value?

What you need is a separate receiving property for each of the selectManyListBox controls. That would be a property in the row model object (tt) in the DataModel. In other words:


When you do it that way, you can obtain the value of the selections in the 5th row (from 0, of course, so it's really row 6) of the model using straight POJO:


That's assuming that you defined a class TTYype for holding instances of row model objects and that TTType has a property named "selectedItems" to match the selectManyCheckBox.
michael nik
Greenhorn

Joined: Mar 11, 2012
Posts: 15
Hmm, I understood my mistake I did using a property of selectManyListBox as a property of my Bean and I changed as you recommended me. However, I have some difficulties to understand how the dataModel is adjusted in my project. Before, I had an ArrayList of ArrayList<String>

tt was an ArrayList<String> and now I changed it to a DataModel. Also it had a property name {t} .

However what do you mean by and especially with ?

Please give me some tips since I am a bit confused, e.g from your last sentence, which type should be the property named "selectedItems" now to match the selectManyCheckBox?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16063
    
  21



I don't guarantee that I got everything exactly right here, but thats the general shape of it.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16063
    
  21


Please give me some tips since I am a bit confused, e.g from your last sentence, which type should be the property named "selectedItems" now to match the selectManyCheckBox?


michael nik
Greenhorn

Joined: Mar 11, 2012
Posts: 15
Thanks Tim Holloway for your help, finally it works.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Is it possible to have a selectManyListBox within <ui:repeat> ?