使用reRender时,如果没有页面刷新,渲染对象将不会更新

时间:2012-11-19 20:45:56

标签: jsf datatable richfaces ajax4jsf

我有一个由列表填充的h:selectonemenu。选择特定值时,应呈现h:datatable。当我选择“特定”值时,h:datatable在我刷新页面之前不会呈现。我做错了什么?

<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}" />
            <a4j:support event="onchange" ajaxsingle = "true" reRender="customTable" ></a4j:support>  
        </h:selectOneMenu>
    </td>
</tr>



<h:panelGroup id="customTable">
<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%" rendered="#{CRUDOperatorProgram.selectedNextGenWorkflow == 0}">
    <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>
</h:panelGroup> 

更新代码:

<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}" valueChangeListener="#{CRUDOperatorProgram.nextGenWorkflowChanged}">
            <f:selectItems value="#{CRUDOperatorProgram.nextGenWorkflowList}" />
            <a4j:support event="onchange" reRender="customTable"></a4j:support>  
    </h:selectOneMenu>
    </td>
</tr>

<h:panelGroup id="customTable">
<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>
</h:panelGroup>

Back Bean(相关部分)......

private List<WorkflowConfig> workflowConfigList = new ArrayList<WorkflowConfig>();
private List<SelectItem> nextGenWorkflowList;

public void nextGenWorkflowChanged(ValueChangeEvent event) {

    workflowConfigList.clear();
    //the value is a long, so make it a string and check
    if(event.getNewValue() != null && event.getNewValue().toString().equals("0")){
        loadWorkFlowConfigs();
    }else{
        //Do not show the datatable
        workflowConfigList.clear();
    }   
}
public List<WorkflowConfig> getWorkflowConfigList(){

    return this.workflowConfigList;
}
private void loadWorkFlowConfigs() {

    Query query = em.createNamedQuery("findAllWorkflowSteps");
    List<WorkflowStep> step = (List<WorkflowStep>) query.getResultList();

    for(WorkflowStep workflowStep : step){
        WorkflowConfig workflowConfig = new WorkflowConfig();
        workflowConfig.setWorkflowStep( workflowStep );
        workflowConfigList.add(workflowConfig);
    }
}

我像你说的那样实施了valueChangeListener。我尝试了这个示例(使用h:panelGroup)和文档中解释的没有h:panelGroup的示例。每个都需要页面刷新...你能看到我做错了吗?

1 个答案:

答案 0 :(得分:1)

通过添加<a4j:support>代码属性或在action=#{someBean.someMethod}中添加valueChangeListener来更改<h:selectOneMenu>组件的行为。 IMO,我不敢添加valueChangeListener。请参阅the official documentation中的示例。

作为旁注,为什么使用${...}代替#{...}