我想知道使用EL bean方法调用在JSF 2.0(使用Tomcat 8和El-impl 2.2)中显示数据是不可能的。 我有一张地图。键是Dish的ID和值 - 数量。我需要在Map中显示每个菜的名称及其数量,但我不能通过getNameOfDish(Integer id)方法来实现,其中id是菜ID - 我收到
javax.el.ELException: /KitchenStaff-Main.xhtml @42,67 value="#{o`rderBean.getNameOfDish(item.key)}": Method not found
我的豆是:
@Named
@Scope("session")
public class OrderBean implements Serializable{
private static final long serialVersionUID = 1L;
private List<OrderItems> listForCook;
private Map<Integer, Integer> mapOfChief;
...
@PostConstruct
public void init(){
mapOfChief = new HashMap<>();
listForCook = kitchStaff.viewItems();
for(OrderItems e: listForCook){
mapOfChief.put(e.getId(), e.getQuantity());
}
}
public String getNameOfDish(Integer id){
for(OrderItems e: listForCook){
if(e.getDish().getId()==id){
return e.getDish().getName();
}
}
return null;
}
...
xhtml页面摘录:
...
<h:form>
<p:dataTable value="#{orderBean.mapOfChief.entrySet().toArray()}"
var="item">
<p:column>
<f:facet name="header">#{msg['admin.NameOfDish']}</f:facet>
<h:outputText value="#{orderBean.getNameOfDish(item.key)}"/>
</p:column>
...
除了使用getter / setter创建新变量以及每次使用getNameOfDish方法初始化它之外,还有其他方法可以获取菜名吗?