Ajax-chained selectManyListBoxes
maciekpazur Mar 26, 2009 9:34 PMHello.
I do realize that the problem of ajax-chained selects has been discussed a number of times.
But I tried to follow all the advice and didn't manage to make my application work.
I am trying to implement searching UI for my application (issue management system).
User can select some projects in selectManyListBox.
<a4j:region id="projectsPanel"> <h:selectManyListbox value="#{searchIssue.selectedProjects}" size="5"> <s:selectItems value="#{allProjects.resultList}" var="proj" label="#{proj.name}" /> <s:convertEntity /> <a4j:support event="onchange" action="#{searchIssue.projectsSelected()}" reRender="modulesPanel" /> </h:selectManyListbox> </a4j:region>
Then relevant modules should appear in another selectManyListbox.
<a4j:outputPanel id="modulesPanel"> <h:selectManyListbox value="#{searchIssue.selectedModules}" size="5"> <s:selectItems value="#{searchIssue.availableModules}" var="module" label="#{module.name}" /> <s:convertEntity /> </h:selectManyListbox> </a4j:outputPanel>
The view is supported with a backing bean SearchIssuesAction:
@Scope(CONVERSATION) @Name("searchIssue") @Stateful public class SearchIssuesAction implements SearchIssues { @In(create = true, value = "#{allProjects.resultList}") @SuppressWarnings(value = { "unused" }) private List<Project> allProjects; private List<Project> selectedProjects; private List<Module> selectedModules; private List<Module> availableModules; (...) public void projectsSelected() { List<Module> available = new LinkedList<Module>(); if (selectedProjects != null) for (Project project : selectedProjects) { available.addAll(project.getModules()); } availableModules = available; } (...getters and setter for selectedProjects, selectedModules, availableModules...)
I run into a number of problems
The only way to display the page, without getting an error
Expected a child component type of UISelectItem/UISelectItems for component type javax.faces.SelectMany(j_id57). Found null.
is to render the modules select only if availableModules list size is greater than 0.
I want this select to be empty unless any projects with modules have been selected.
If I make the above-mentioned workaround, the modules appear on the list, but
when I submit the form it turns out that selectedModules is null.
I would greatly appreciate any help.