【发布时间】:2012-10-26 22:48:28
【问题描述】:
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;
}
}
【问题讨论】:
标签: jsf-2 primefaces omnifaces