cancel
Showing results for 
Search instead for 
Did you mean: 

usage of a:selectList

gilles
Champ in-the-making
Champ in-the-making
I get an exception javax.faces.model.SelectItem cannot be cast to org.alfresco.web.ui.common.component.UIListItem when I add a simple …
<a:selectList id="template-list"  value="#{SearchProperties.folderTypes}" styleClass="selectListTable" itemStyleClass="selectListItem">
  <a:listItems value="#{AdvancedSearchDialog.folderTypes}"/>
</a:selectList>
… in the advanced-search.jsp
I checked the SearchProperties setFolderTypes, and the AdvancedSearchDialog getFolderTypes, wich use both a List<SelectItem>
Can you explain my mistake?
Thanks
12 REPLIES 12

gavinc
Champ in-the-making
Champ in-the-making
You have a mismatch between the list and it's items.

If you want to have a list of folderTypes from AdvancedSearchDialog you will need to use h:selectOneMenu or other JSF component, for example:


<h:selectOneMenu …>
   <f:selectItems value="#{AdvancedSearchDialog.folderTypes}" … />
</h:selectOneMenu>

The tags above are standard JSF components.

The <a:selectList> and <a:listItems> tags are Alfresco JSF components, they are basically used to provide slightly richer lists than the standard components. To use them the method you bind to needs to return different objects, in the example you tried it was expecting a return type of List<UIListItem> but AdvancedSearchDialog.getFolderTypes() returns List<SelectItem>.

Hope that helps!

gilles
Champ in-the-making
Champ in-the-making
Thank you Gavin.
I try to understand. Actually, I need a multiple choice component, so I tried with an h:selectManyMenu.
So, the AdvancedSearchDialog getFolderTypes() returns a List<SelectItem>, the SearchProperties.folderTypes expects a List<SelectItem>, but a still get a
java.lang.IllegalArgumentException: Value is no String (class=javax.faces.model.SelectItem, …) and component …javax.faces.component.html.HtmlSelectManyMenu… does not have a Converter
and I can't find where is the mismatch. Here is my code (Alf. 2.9b):
<h:selectManyMenu id="selectManyMenu-folderTypes" value="#{SearchProperties.folderTypes}" >
   <f:selectItems value="#{AdvancedSearchDialog.folderTypes}" id="selectManyMenu-folderType-items"/>
</h:selectManyMenu>
About the <a:selectList > and <a:listItems>, there are no suitable methods to let the user choose more than one folder.  Right?
Thanks

gavinc
Champ in-the-making
Champ in-the-making
OK, so the "thing" at the end of the value binding for the value attribute of the list (in your example, #{SearchProperties.folderTypes}), must accept the appropriate type. For most components this is a String, the list will be trying to set the selected values the user chose, this is typically done as a String, comma separated String or String array.

As the #{SearchProperties.folderTypes} method takes a List<SelectItem> the error occurrs. You need to change the value binding to a method that accepts the output from the list (you may need to experiment to find what it is, I'm not sure off the top of my head).

As for <a:selectList>, yes, they should support multi select, there is a property on the component called "multiSelect", set it to true (it's false by default).

gilles
Champ in-the-making
Champ in-the-making
Thank you Gavin, I think I'll have to take a closer look at the beans methods.
But,        why do I fell I'm the first to use this multiselect selectlist in alfresco?
Do you plan to give us an example? Great!
I love this Community.

gilles
Champ in-the-making
Champ in-the-making
You need to change the value binding to a method that accepts the output from the list …
I can't find methods showing the folder types and storing themin the search bean. :?   
Had anyone allready done this?
As for <a:selectList>, yes, they should support multi select, there is a property on the component called "multiSelect", set it to true (it's false by default).
OK, but there again, I can't find a method in the SearchProperties who use this List<UIListItem>. Does it mean that <a:selectList> cant be used to multiselect folders types?

Do I need to investigate AdvancedSearchConfigElement ?

Could you point me to an example?

Thanks,

gavinc
Champ in-the-making
Champ in-the-making
Have a look at the create website wizard, this has several examples of using a:selectList and the methods needed to accept the value, the JSPs can be found in /jsp/wcm/create-website-wizard and the java class is org.alfresco.web.bean.wcm.CreateWebsiteWizard.

The way the advanced search is implemented currently will not allow multiselect, to do so you will definitely have to make some code changes. Either use the examples above to see if you can use a:selectList or alternatively see if you can swap the h:selectOneMenu for h:selectManyMenu (the standard JSF multi select component).

gilles
Champ in-the-making
Champ in-the-making
The way the advanced search is implemented currently will not allow multiselect, to do so you will definitely have to make some code changes.
When you say 'code changes' do you mean 'in the bean classes' or just in the jsp? I understand that I can't allow multiselect by just configuring the advansed search, but I would like to only modify the advanced-search.jsp.
I tryed with this (this give no more errors) and I'm just testing the results …
<h:selectManyListbox id="selectManyMenu-folderTypes" value="#{SearchProperties.folderTypes}" converter="org.alfresco.faces.MultiValueConverter">
   <f:selectItems value="#{AdvancedSearchDialog.folderTypes}" />
</h:selectManyListbox>
I keep you posted …

gilles
Champ in-the-making
Champ in-the-making
Actually I tried this:
<h:selectManyCheckbox value="#{SearchProperties.folderTypes}" id="selectFolderTypes" converter="org.alfresco.faces.MultiValueConverter">
  <f:selectItems value="#{AdvancedSearchDialog.folderTypes}" id="folderTypes" />
</h:selectManyCheckbox>
As expected, it displays the list of the space types that I want to (multi-)select, to restrict my search. But when I click on the 'Search', nothing  seams to be done by the server. I just recieve the same 'Advanced Search' form. I'm trying to trace and find an error.
Is the 'SearchProperties.folderTypes' implemented (as I expect,) to let the user restrict his search to a list of folder types?

gavinc
Champ in-the-making
Champ in-the-making
I meant you'll need code changes in the base classes, I don't think you'll be able to do what you want by just changing advanced-search.jsp.

Your example also has some issues i.e. you shouldn't need a converter, try the following:


<h:selectManyCheckbox value="#{SearchProperties.selectedFolders}" id="selectFolderTypes">
  <f:selectItems value="#{AdvancedSearchDialog.folderTypes}" id="folderTypes" />
</h:selectManyCheckbox>

But with this you will need to add a method called setSelectedFolders in the SearchProperties bean that takes a String[] as it's parameter, the array will hold the selected values. Disclaimer: I haven't tried this code, this is what I think should work from memory!