使用List中的对象的Primefaces SelectOneMenu将在选择时翻转

时间:2012-11-06 22:12:35

标签: jsf-2 primefaces omnifaces

调用了selectedRestaurant的setter方法,但菜单只是翻转而不呈现<h:outputText>。菜单包含内容,因此<f:selectItems>中使用的列表不为空。当我使用omnifaces.SelectItemsConverter时,我认为这不是由于转换问题。

这是我的JSF代码:

<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>

这是支持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;
   }
}

1 个答案:

答案 0 :(得分:3)

如果存在转换错误,则应收到错误消息。

你是否在Class餐厅实现了#equals()和#hashcode()?