Lester
Lester

Reputation: 1870

Primefaces SelectOneMenu with Objects from List flips back on selection

The setter method of selectedRestaurant is called but the menu just flips back and doesn't render the <h:outputText>. The Menu has content, so the List used in <f:selectItems> is not empty. As I am using omnifaces.SelectItemsConverter I suppose it is not due to a conversion problem.

This is my JSF Code:

<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.org/ui">
<h:head />
<h:body>
    <h:panelGroup id="adminOneMenu" layout="block">
    <h:form>

    <p:selectOneMenu value="#{bugBean.selectedRestaurant}" converter="omnifaces.SelectItemsConverter">
        <f:selectItem itemValue="" itemLabel="Restaurant wählen"/> 
        <f:selectItems value="#{bugBean.restaurants('London')}" var="restaurant" itemLabel="#{restaurant.screenName}"/>
        <p:ajax update=":adminOneMenu"/>
    </p:selectOneMenu>  

    <h:outputText value="#{bugBean.selectedRestaurant.screenName}" />
    </h:form>
    </h:panelGroup>

</h:body>
</html>

This is the backing bean:

package huhu.main.managebean;

import java.io.Serializable;
import java.util.List;

import javax.ejb.EJB;
import javax.enterprise.context.SessionScoped;
import javax.inject.Named;

import huhu.model.generated.Restaurant;
import huhu.service.RestaurantService;

@Named
@SessionScoped
public class BugBean implements Serializable {

   private static final long serialVersionUID = 1L;
   private Restaurant selectedRestaurant;

   @EJB
   RestaurantService rs;

   public List<Restaurant> getRestaurants(String city){
       List<Restaurant> restaurants;
       restaurants = rs.getRestaurantsInCity(city);
       return restaurants;
   }

   public Restaurant getSelectedRestaurant() {
      return selectedRestaurant;
   }

   public void setSelectedRestaurant(Restaurant selectedRestaurant) {
      this.selectedRestaurant = selectedRestaurant;
   }
}

Upvotes: 2

Views: 7171

Answers (1)

stg
stg

Reputation: 2797

If there would be a conversion error, you should get an error message.

Did you implement #equals() and #hashcode() in class Restaurant?

Upvotes: 3

Related Questions