【发布时间】:2014-12-17 16:10:35
【问题描述】:
拥有这个 xhtml 代码:
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:c="http://xmlns.jcp.org/jsp/jstl/core"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>Simple JSF</title>
</h:head>
<h:body>
<h:form>
<ui:repeat value="#{cart.items}" var="item">
<h:panelGrid columns="2" cellpadding="10">
<h:outputText value="#{item}" />
</h:panelGrid>
</ui:repeat>
</h:form>
</h:body>
</html>
还有豆子:
import java.util.ArrayList;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
@ManagedBean(name = "cart")
@SessionScoped
public class CartBean {
private List<String> items;
public CartBean() {
items = new ArrayList<>();
items.add("shirt");
items.add("skirt");
items.add("trouser");
}
public List<String> getItems() {
return items;
}
}
在输出文本中显示三个对应的项目:“衬衫”、“裙子”和“裤子” 但是,改变 xhtml 的正文就像显示:
<h:body>
<h:form>
<p:tabView >
<ui:repeat value="#{cart.items}" var="item">
<p:tab title="#{item}">
<h:panelGrid columns="2" cellpadding="10">
<h:outputText value="#{item}" />
</h:panelGrid>
</p:tab>
</ui:repeat>
</p:tabView>
</h:form>
</h:body>
仅显示一个选项卡(而不是三个)且选项卡中没有文本的 tabView。 我不明白为什么会丢失数据?
【问题讨论】:
标签: jsf-2 primefaces tabview