【问题标题】:What happens with tabView Primefaces componenttabView Primefaces 组件会发生什么
【发布时间】: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


    【解决方案1】:

    您不会在 tabview 中使用 ui:repeat 来生成选项卡。 Tabview 有自己的迭代功能:

    <p:tabView value="#{cart.items}" var="item">
        <p:tab title="#{item}">
            <h:outputText value="#{item}"/>
            ... etc.
        </p:tab>
    </p:tabView>
    

    【讨论】:

    • 我之前已经尝试过,但我得到一个错误:com.sun.faces.facelets.compiler.UIInstructions cannot be cast to org.primefaces.component.tabview.Tab
    【解决方案2】:

    解决了使用 tabView 所有者迭代器而不是 ui:repeat 并将其添加到 web.xml 文件:

    <context-param>
          <param-name>javax.faces.FACELETS_SKIP_COMMENTS</param-name>
          <param-value>true</param-value>   
    </context-param>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-10-03
      • 2015-01-06
      • 2014-12-30
      • 2012-02-28
      • 2011-07-10
      • 1970-01-01
      • 1970-01-01
      • 2013-04-02
      相关资源
      最近更新 更多