【问题标题】:JSF2.0 composite add a rich tab for each of the values passedJSF2.0 复合为每个传递的值添加一个丰富的选项卡
【发布时间】:2012-06-08 19:47:36
【问题描述】:

我正在使用 JSF 2.0 复合来拥有一种模板并最小化我的 xhtml 工作,例如我有这个复合 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://java.sun.com/jsf/html"
  xmlns:f="http://java.sun.com/jsf/core"
  xmlns:a4j="http://richfaces.org/a4j"
  xmlns:rich="http://richfaces.org/rich"
  xmlns:ui="http://java.sun.com/jsf/facelets"
  xmlns:cc="http://java.sun.com/jsf/composite"
  >

<cc:interface>

    <cc:attribute name="tableHeadder" />
    <cc:attribute name="fechaValueInicial" />
    <cc:attribute name="fechaValueFinal" />
    <cc:attribute name="nombreSelectOne" />
    <cc:attribute name="valueSelectOne" />
<cc:attribute name="valueSelectList" />
    <cc:attribute name="nombreCommandButton" />
    <cc:attribute name="firstTabName" />
    <cc:attribute name="firstTabValue" />
    <cc:attribute name="secondTabName" />
    <cc:attribute name="secondTabValue" />
    <cc:attribute name="thirdTabName" />
    <cc:attribute name="thirdTabValue" />
    <cc:attribute name="funcionCommandButton" 
        method-signature="java.lang.String action()" />

</cc:interface>

<cc:implementation>

  <a4j:status onstart="#{rich:component('statPane')}.show()"
                onstop="#{rich:component('statPane')}.hide()" />

      <h:form>

        <rich:panel header="#{cc.attrs.tableHeadder}">
            <rich:messages/>

            <div>
                <div>
                    <h:outputText value="Del:"/>
                    <rich:calendar datePattern="dd/MMMM/yyyy" popup="true" mode="ajax"
                                   required="true"
                                   requiredMessage="Selecciona una fecha inicial"
                                   locale="es" value="#{cc.attrs.fechaValueInicial}" />
                    <h:outputText value="Al:"/>
                    <rich:calendar datePattern="dd/MMMM/yyyy" popup="true" mode="ajax"
                                   required="true"
                                   requiredMessage="Selecciona una fecha final"
                                   locale="es" value="#{cc.attrs.fechaValueFinal}" />

                    <br/><br/>

                    <h:outputLabel value="#{cc.attrs.nombreSelectOne}" />
                    <h:selectOneMenu
                        value="#{cc.attrs.valueSelectOne}">
                        <f:selectItems value="#{cc.attrs.valueSelectList}" />
                    </h:selectOneMenu>
                    <br/><br/>


                    <h:commandButton value="#{cc.attrs.nombreCommandButton}" actionListener="#{cc.attrs.funcionCommandButton}" />
                </div>


            </div>
            <br/><br/><br/><br/>

            <rich:tabPanel switchType="server">
                <rich:tab header="#{cc.attrs.firstTabName}">
                    <ui:include src="#{cc.attrs.firstTabValue}" />
                </rich:tab>
                <rich:tab header="#{cc.attrs.secondTabName}">
                    <ui:include src="#{cc.attrs.secondTabValue}" />
                </rich:tab>
                <rich:tab header="#{cc.attrs.thirdTabName}">
                    <ui:include src="#{cc.attrs.thirdTabValue}" />
                </rich:tab>

            </rich:tabPanel>

            <ui:include src="../../waitPopup.xhtml" />

        </rich:panel>
    </h:form>

</cc:implementation>

并以这种方式实现它:

<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:a4j="http://richfaces.org/a4j"
  xmlns:rich="http://richfaces.org/rich"
  xmlns:ui="http://java.sun.com/jsf/facelets"
  xmlns:CT="http://java.sun.com/jsf/composite/CompositeTemplates"
  >

<h:head>
    <title>Reporte de Recepcion de Leche</title>
</h:head>

<body>

    <CT:reportes
        tableHeadder="Reporte Recepcion de Leche"
        fechaValueInicial="#{lecheReporteProveedoresVB.fechaInicial}"
        fechaValueFinal="#{lecheReporteProveedoresVB.fechaFinal}"
        nombreSelectOne="Proveedores: "
        valueSelectOne="#{lecheReporteProveedoresVB.proveedor}"
        valueSelectList="#{CatalogoProveedoresLecheSI.selectList}"
        nombreCommandButton="Consultar"
        funcionCommandButton="#{lecheReporteProveedoresVB.consultar()}"
        firstTabName="Recepcion por Dia"
        firstTabValue="../../leche/lecheReporteProveedoresDia.xhtml"
        secondTabName="Recepcion por Mes"
        secondTabValue="../../leche/lecheReporteProveedoresMes.xhtml"
        thirdTabName="Recepcion por Proveedores"
        thirdTabValue="../../leche/lecheReporteProveedoresRecibido.xhtml"/>



</body>

我想,而不是声明 firstTab secondTab thirdTab,只给出 3 个 firstTab 值,并且复合创建 3 个richTab 组件,这有可能吗?

【问题讨论】:

    标签: java jsf-2 composite-component


    【解决方案1】:

    你可以做的一件事是动态使用和创建标签。第一种方法(你可以改进它..)会做这样的事情..

    在你的组件中:

    <?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://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:a4j="http://richfaces.org/a4j"
      xmlns:rich="http://richfaces.org/rich"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:cc="http://java.sun.com/jsf/composite"
      >
    <cc:interface>
    
        <cc:attribute name="tableHeadder" />
        <cc:attribute name="fechaValueInicial" />
        <cc:attribute name="fechaValueFinal" />
        <cc:attribute name="nombreSelectOne" />
        <cc:attribute name="valueSelectOne" />
    <cc:attribute name="valueSelectList" />
        <cc:attribute name="nombreCommandButton" />
    
        <cc:attribute name="tabList" />
    
        <cc:attribute name="funcionCommandButton" 
            method-signature="java.lang.String action()" />
    
    </cc:interface>
    
    <cc:implementation>
    
      <a4j:status onstart="#{rich:component('statPane')}.show()"
                    onstop="#{rich:component('statPane')}.hide()" />
    
          <h:form>
    
            <rich:panel header="#{cc.attrs.tableHeadder}">
                <rich:messages/>
    
                <div>
                    <div>
                        <h:outputText value="Del:"/>
                        <rich:calendar datePattern="dd/MMMM/yyyy" popup="true" mode="ajax"
                                       required="true"
                                       requiredMessage="Selecciona una fecha inicial"
                                       locale="es" value="#{cc.attrs.fechaValueInicial}" />
                        <h:outputText value="Al:"/>
                        <rich:calendar datePattern="dd/MMMM/yyyy" popup="true" mode="ajax"
                                       required="true"
                                       requiredMessage="Selecciona una fecha final"
                                       locale="es" value="#{cc.attrs.fechaValueFinal}" />
    
                        <br/><br/>
    
                        <h:outputLabel value="#{cc.attrs.nombreSelectOne}" />
                        <h:selectOneMenu
                            value="#{cc.attrs.valueSelectOne}">
                            <f:selectItems value="#{cc.attrs.valueSelectList}" />
                        </h:selectOneMenu>
                        <br/><br/>
    
    
                        <h:commandButton value="#{cc.attrs.nombreCommandButton}" actionListener="#{cc.attrs.funcionCommandButton}" />
                    </div>
    
    
                </div>
                <br/><br/><br/><br/>
    
                <rich:tabPanel switchType="server">
                   <ui:repeat var="tab" value="#{cc.attrs.tabList}" >
                     <rich:tab header="#{tab.header}">
                        <ui:include src="#{tab.src}" />
                     </rich:tab>
                   </ui:repeat>
    
                </rich:tabPanel>
    
                <ui:include src="../../waitPopup.xhtml" />
    
            </rich:panel>
        </h:form>
    
    </cc:implementation>
    

    现在.. 你应该创建一个 POJO 来保存标签数据:

    公共类 TabData 实现可序列化 {

     private static final long serialVersionUID = 1L;
    
    
      private String header;
      private String src;
    
      public TabData(String header, String src) {
          this.header = header;
          this.src = src;
      }
    
      /* getters & setters */
    

    }

    在你的 bean 中.. 只需添加一个 List 并填充它...

    ...
    
    private List<TabData> tabs = new ArrayList<TabData>();
    
    @PostConstrunct
    public void init() {
       tabs.add(new TabData("Recepcion por Dia","../../leche/lecheReporteProveedoresDia.xhtml"));
       ...
    }
    
    /* Getter & Setter */
    

    最后..使用组件:

    <CT:reportes
            tableHeadder="Reporte Recepcion de Leche"
            fechaValueInicial="#{lecheReporteProveedoresVB.fechaInicial}"
            fechaValueFinal="#{lecheReporteProveedoresVB.fechaFinal}"
            nombreSelectOne="Proveedores: "
            valueSelectOne="#{lecheReporteProveedoresVB.proveedor}"
            valueSelectList="#{CatalogoProveedoresLecheSI.selectList}"
            nombreCommandButton="Consultar"
            funcionCommandButton="#{lecheReporteProveedoresVB.consultar()}"
            tabList="#{bean.tabs}" />
    

    我从来没有真正用 Richfaces 尝试过这种方法,我已经用它来创建 jQuery,它工作得很好......再次,你可以改进这个......

    问候

    【讨论】:

    猜你喜欢
    • 2013-01-07
    • 1970-01-01
    • 2021-04-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-02
    相关资源
    最近更新 更多