0

I have a h:selectonemenu that is populated by a list. When a specific value is selected, a h:datatable should be rendered. When I select that "specific" value, the h:datatable does not render until I refresh the page. What am I doing wrong?

<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> 

Updated 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}" 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 (Relevant parts) ...

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);
    }
}

I implemented a valueChangeListener like you said. I tried this example (with the h:panelGroup) and the example without a h:panelGroup explained in the documentation. Each require a page refresh... Can you see anything I'm doing wrong?

Zack
  • 5,108
  • 4
  • 27
  • 39

1 Answers1

1

Change the behavior of the <a4j:support> component by adding adding the action=#{someBean.someMethod} tag attribute or add a valueChangeListener in your <h:selectOneMenu>. IMO, I preffer to add a valueChangeListener. See the example in the official documentation.

As a side note, why you use ${...} instead of #{...}?

Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
  • Thank you for the response first off! So the two options you provided me call a method in the bean correct? I like your idea and documentation of the `valueChangeListener`, but how will this refresh my page or in other words, automatically render/un-render my `h:datatable`? – Zack Nov 20 '12 at 12:33
  • @Zack it will reRender the `` after executing the action declared in the `` or in the `valueChangeListener`. Of course, I'm assuming you're changing the value of the list (in any of these methods) that will be in your datatable too. – Luiggi Mendoza Nov 20 '12 at 14:27
  • @Zak what's the scope of your bean? Also, have you debugged to see if the `valueChangeListener` is actually being executed? – Luiggi Mendoza Nov 20 '12 at 14:52
  • It is being executed. Scope wise, it's tied directly into my .xhtml page – Zack Nov 20 '12 at 14:55
  • Very strange. It looks like RichFaces can't find the `customTable` component or the bean scope is recreating the list after executing the `loadWorkFlowConfigs` method. Don't you have a `@PostConstruct` method or anything that could change the list value anywhere (even the `getworkflowConfigList` method)? – Luiggi Mendoza Nov 20 '12 at 15:02
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/19831/discussion-between-zack-and-luiggi-mendoza) – Zack Nov 20 '12 at 15:19
  • The list gets populated, or not, on page load. The `valueChangeListener` is clearing that populated list or adding items when you select something in the `h:selecOneMenu` – Zack Nov 20 '12 at 16:16