Updating values of selectOneMenu inside a datatable using JSF 1.2 and Tomahawk

861 views Asked by At

There's a datatable (Tomahawk's datatable - https://myfaces.apache.org/tomahawk-project/tomahawk/tagdoc/t_dataTable.html) and inside this datatable there are several columns with a dropdown menu (Tomahawk's selectOneMenu - https://myfaces.apache.org/tomahawk-project/tomahawk12/tagdoc/t_selectOneMenu.html) inside them. When I select a dropdown menu, there's an onchange attribute on it that triggers a ValueChangeListener (a method in a Managed Bean). I did that because I want the second dropdown menu to load dinamically, based on the value of the first menu. The problem is that when I select a value in the first menu of the first row of the datable the value on the second gets loaded, but if I do the same in the second row the dropdown menu doesn't trigger the ValueChangeListener. Worse: it doesn't hold the selected value in the first dropdown menu. So, the ValueChangeListener is ONLY triggered in the first row.

What I want: - The second dropdown menu in every row of the datable to get loaded when the first dropdown menu in the same row select a new value - Keep the selected values in any dropdown menu when reloading/refreshing the page

The Datatable:

<t:dataTable id="tabAnAn" var="anls" value="#{mybean.analyze}"
                    rowClasses="even,odd"
                    columnClasses="center,center,left,center,center,center,center, center, center"         
                    headerClass="hdmain"                
                    styleClass="sz90" >

                        <t:column headerstyleClass="headercls">
                            <f:facet name="header">
                                <h:selectBooleanCheckbox id="js_masterSelect" value="#{mybean.markall}" />
                            </f:facet>
                            <h:selectBooleanCheckbox styleClass="js_selectable" value="#{anls.dstb}" />
                        </t:column>

                        <t:column headerstyleClass="headercls">
                            <f:facet name="header">#{label.excs}</f:facet>
                            <h:outputText value="#{anls.excs}" />
                        </t:column>

                        <t:column headerstyleClass="headercls">
                            <f:facet name="header">#{label.ente}</f:facet>
                            <h:outputText value="#{anls.nm}" />
                        </t:column>

                        <t:column headerstyleClass="headercls">
                            <f:facet name="header">#{label.tpdc}</f:facet>
                            <h:outputText value="#{anls.tpdcnm}" />
                        </t:column>


                        <t:column headerstyleClass="headercls">
                            <f:facet name="header">Type</f:facet>
                            <h:selectOneMenu id="typeX" label="Type:" styleClass="tm8" 
                                    value="#{anls.tipoAnaliseSelecionada}" converter="cmbcon" 
                                    onchange="submit()" immediate="true" valueChangeListener="#{mybean.callListener}" >
                                 <f:selectItem itemValue="#{null}" itemLabel="" />
                                 <t:selectItems var="typeX" itemValue="#{typeX}" itemLabel="#{typeX.nome}" 
                                     value="#{mybean.tiposAnalises}"  />
                                <f:attribute name="thisAzy" value="#{anls}"/>
                             </h:selectOneMenu>
                        </t:column>


                        <t:column headerstyleClass="headercls">
                            <f:facet name="header">#{label.ps0n}</f:facet>
                            <h:selectOneMenu id="slctd" label="ps0n:" style="width:200px;" 
                                    value="#{anls.slctd}" converter="alzcon">
                                 <f:selectItem itemValue="#{null}" itemLabel="" />
                                 <t:selectItems var="az1n" itemValue="#{az1n}" itemLabel="#{az1n.usr.nm}" 
                                     value="#{anls.azixpo}" />
                             </h:selectOneMenu>
                        </t:column>

                    </t:dataTable>

The ValueChangeListener method:

public void callListener(ValueChangeEvent event){
            FacesContext context = FacesContext.getCurrentInstance();
            TpzAzy ta = (TpzAzy)event.getNewValue();
            AnlDb ad = (AnlDb)event.getComponent().getAttributes().get("thisAzy");

            ad.setAnlDbTpzAzy(ta);

            if(mapType.containsKey(ta)){
                ad.setAzyCand(mapType.get(ta));
            } else {
                ad.setAzyCand(this.svc.getAzy(ta));
                this.mapType.put(ta, ad.getAzyCand());
            }

            this.showScreen = true;
            context.renderResponse();
        }

An example of the page:

the page

0

There are 0 answers