简体   繁体   English

如何禁用/启用h:datatable

[英]How to disable/enable h:datatable

I have a page with ah:selectOneMenu and a data table. 我有一个页面啊:selectOneMenu和一个数据表。 I want to load/render/enable my h:datatable based on what I select in the h:selectOneMenu. 我想根据我在h:selectOneMenu中选择的内容加载/渲染/启用我的h:datatable。 Is this possible? 这可能吗?

Here's some code 这是一些代码

<tr class="portlet-table-body" >
<td width="20%" class="porlet-padding-left"><h:outputText value="${operatorProgramBundle.NextGenerationWorkflow}" /></td>
<td width="450px">
    <h:selectOneMenu id="ngw" styleClass="portlet-dropdown"  value="${CRUDOperatorProgram.selectedNextGenWorkflow}">
        <f:selectItems value="${CRUDOperatorProgram.nextGenWorkflowList}" />
    </h:selectOneMenu>
</td>

<h:dataTable id="DispatchConfigurationCustom" columnClasses="portlet-table-same portlet-table-cell"
headerClass="portlet-table-same portlet-table-cell" value="#{CRUDOperatorProgram.workflowConfigList}" var="workflowConfig" width="100%" >
<h:column>
    <f:facet name="header">
        <h:outputText value="Include" />
    </f:facet>
    <h:selectBooleanCheckbox id="includeInd" value="#{workflowConfig.isIncludedInd}"/>
</h:column>
<h:column>
    <f:facet name="header">
        <h:outputText value="Automate" />
    </f:facet>
    <h:selectOneRadio id="onOff" value="#{workflowConfig.isAutomatedInd}">
        <f:selectItem id="onButton" itemLabel="On" itemValue="0" />
        <f:selectItem id="offButton" itemLabel="Off" itemValue="0" />
    </h:selectOneRadio>
</h:column>
</h:dataTable>

Given that you're using JSF 2.x, just use <f:ajax> in the dropdown to update the closest parent of the datatable and let the rendered attribute of the datatable evaluate true or false accordingly depending on the selected item. 鉴于您正在使用JSF 2.x,只需在下拉列表中使用<f:ajax>来更新数据表的最近父项,并让数据表的rendered属性根据所选项目相应地评估为truefalse

Assuming that you'd like to show the datatable only when item value "foo" is selected, do so: 假设您只想在选择项目值“foo”时显示数据表,请执行以下操作:

<h:selectOneMenu value="#{bean.selectedItem}">
    <f:selectItems value="#{bean.availableItems}" />
    <f:ajax render="table" />
</h:selectOneMenu>

<h:panelGroup id="table">
    <h:dataTable rendered="#{bean.selectedItem == 'foo'}">
        ...
    </h:dataTable>
</h:panelGroup>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM