在不更新整个数据表的情况下,是否可以在数据表中对条件进行条件渲染

时间:2012-01-10 00:56:20

标签: jsf primefaces

<h:dataTable value="#{bean.listOfRows}" var="eachRow" id="theDataTable">
  <h:column>
        <p:outputPanel rendered="#{eachRow.visible}">
              <h:selectManyCheckbox 
                    value="#{xxxx}"
                    label="#{xxxx}">
                    <f:selectItems value="#{checkBoxItems}" var="eachItem" itemLabel="#{eachItem.label}" itemValue="#{eachItem.value}" />
                    <p:ajax event="change" update="theDataTable" />
              </h:selectManyCheckbox>
        </p:outputPanel>
        <p:outputPanel rendered="#{eachRow.visible}">
              <h:selectOneRadio 
                    value="#{xxxx}"
                    label="#{xxxx}">
                    <f:selectItems value="#{radioItems}" var="eachItem" itemLabel="#{eachItem.label}" itemValue="#{eachItem.value}" />
                    <p:ajax event="change" update="theDataTable" />
              </h:selectOneRadio>
        </p:outputPanel>

        <p:outputPanel rendered="#{eachRow.visible}">
        </p:outputPanel>
        <p:outputPanel rendered="#{eachRow.visible}">
        </p:outputPanel>
        <p:outputPanel rendered="#{eachRow.visible}">
        </p:outputPanel>
        <p:outputPanel rendered="#{eachRow.visible}">
        </p:outputPanel>
    .
    .
    .

  </h:column>                                     
</h:dataTable>

在数据表的行集内,将根据前一行输入组件上的VALUE CHANGE EVENTS(使用AJAX请求处理)有条件地呈现某些行。我可以在不重新渲染整个数据表的情况下使这些行可见吗? ? ? 我在PrimeFaces 2.2.1中使用JSF 2.0.6。

1 个答案:

答案 0 :(得分:0)

正如BalusC对此问题link所建议的那样,在数据表列中使用填充。

<h:dataTable id="mainDatatable" value="#{bean.listOfRows}" var="eachRow" id="theDataTable">
  <h:column>
    <h:panelGroup id="padding" layout="block">
      <p:outputPanel rendered="#{eachRow.visible}">
          <h:selectManyCheckbox 
                value="#{xxxx}"
                label="#{xxxx}">
                <f:selectItems value="#{checkBoxItems}" var="eachItem" itemLabel="#{eachItem.label}" itemValue="#{eachItem.value}" />
                <p:ajax event="change" update="theDataTable" />
          </h:selectManyCheckbox>
      </p:outputPanel>
    <p:outputPanel rendered="#{eachRow.visible}">
          <h:selectOneRadio 
                value="#{xxxx}"
                label="#{xxxx}">
                <f:selectItems value="#{radioItems}" var="eachItem" itemLabel="#{eachItem.label}" itemValue="#{eachItem.value}" />
                <p:ajax event="change" update="theDataTable" />
          </h:selectOneRadio>
    </p:outputPanel>

    <p:outputPanel rendered="#{eachRow.visible}">
    </p:outputPanel>
    <p:outputPanel rendered="#{eachRow.visible}">
    </p:outputPanel>
    <p:outputPanel rendered="#{eachRow.visible}">
    </p:outputPanel>
    <p:outputPanel rendered="#{eachRow.visible}">
    </p:outputPanel>
.
.
.
    </h:panelGroup>
  </h:column>                                     
</h:dataTable>

无论是否呈现,数据表都会在列中的每个组件上创建填充。现在它取决于您的依赖逻辑。如果要更新数据表的特定行,请使用从支持bean生成的客户端ID,或者按照BalusC在此question中的建议将组件绑定到bean。客户端ID的格式为mainDatatable:rowIndex:padding。干杯!