tags:

views:

401

answers:

1

I've got a JSF creation form using a selectManyListbox with selectItems inside (it should contain all tags available for projects). The selectItems list though is always empty - when the page renders, there's nothing in the Listbox. Still, the list in the backing bean contains 3 entries (checked that). What am I doing wrong?

The backing bean:

@ManagedBean(name = "createProjectBean")
@RequestScoped
public class CreateProjectBean {

public Project getProject() {
  return project;
}

public void setProject(Project project) {
  this.project = project;
}

private Project project;
private IProjectService projectService;
private FacesContext facesContext;
private MessageFactory mf;
private List<Tag> tags;

public CreateProjectBean() {

 project = new Project();
 projectService = (IProjectService)ServiceFinder.getInstance()
 .findBean("projectService");
 mf = new MessageFactory("properties.projects.messages");
 tags = projectService.getTags();
}

 /* should be the source of tags */
 public void setTags(List<Tag> tags) {
  this.tags = tags;
 }

 public List<Tag> getTags() {
  return tags;
  }
}

And the page:

<f:view> 
   <h:outputText id="error" rendered="false" />
   <h:message styleClass="errorMessage" for="error" />  
<h:form id="creationForm" >
 <h:panelGrid columns="2" width="420">

  /* blah, blah, set name and stuff */

                 <h:selectManyListbox id="box" value = "#{createProjectBean.project.tags}">
                  <f:converter converterId="tag" />
                  <f:selectItems value="@{createProjectBean.tags}"
                   var="tag"
                   itemValue="#{tag}"
                   itemLabel="${tag.name}" />
                 </h:selectManyListbox>

  <f:verbatim><br/></f:verbatim>
  <h:commandButton value="Create" styleClass="formButton" action="#{createProjectBean.create}"/>
 </h:panelGrid>
</h:form>
</f:view>

I tried to do it per analogia to this page: http://digitaljoel.wordpress.com/2010/01/11/jsf-2-custom-converter/

The converter I've written is yet to be tested.

+1  A: 

Your EL is bogus. You should use the #{} notation everywhere. Replace

<f:selectItems value="@{createProjectBean.tags}"
               var="tag"
               itemValue="#{tag}"
               itemLabel="${tag.name}" />

by

<f:selectItems value="#{createProjectBean.tags}"
               var="tag"
               itemValue="#{tag}"
               itemLabel="#{tag.name}" />
BalusC
hah. bogus indeed. What is `@{..}` for, actually? (+1)
Bozho