2
的selectedRestaurant
setter方法的調用,但菜單只是翻轉回來,不渲染<h:outputText>
。菜單包含內容,因此<f:selectItems>
中使用的列表不爲空。正如我使用omnifaces.SelectItemsConverter
我想這不是由於轉換問題。Primefaces selectOneMenu用於翻轉重新選擇
這是我的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;
}
}
沒有錯誤消息,沒有#equals()和#hashcode()實現。應該不需要使用'omnifaces.SelectItemsConverter',應該嗎? – Lester
不需要進行轉換,但需要selectOneMenu。 Primefaces selectOneMenu檢查,如果選擇了餐廳在您的選擇列表中。如果#equals()沒有實現,這可能不起作用。 – stg
它從數據庫表生成的實體。我可以如何實現這些,而無需在新生成它們時手動進行編輯? – Lester