2

的 setter 方法selectedRestaurant被调用,但菜单只是向后翻转并且不呈现<h:outputText>. Menu 有内容,所以使用的 List<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;
   }
}
4

1 回答 1

3

如果出现转换错误,您应该会收到一条错误消息。

你在餐厅类中实现了#equals() 和#hashcode() 吗?

于 2012-11-06T22:29:48.050 回答