13 Replies Latest reply on Dec 3, 2012 1:19 AM by xermag

    rich:select and AJAX

    barmic

      Hello,

       

      I work on a project with tomcat 7 and richfaces 4 (M6 for the moment) and mojarra.

      I want use an tow <rich:select> and when the fisrt is modify, modify the second. Actually my facelets is as it :

      <rich:select value="#{search.product}" id="id0"

                                   defaultLabel="#{search.products[0]}" >

          <f:selectItems value="#{search.products}" />

          <a4j:ajax execute="@form" render="id1" immediate="true" />

      </rich:select>

       

      <rich:select value="#{search.id}" id="id1"

                                   defaultLabel="#{search.ids[0]}" >

          <f:selectItems value="#{search.ids}" />

      </rich:select>

       

      And it work ! ... But the first <rich:select> must lost the focus for that the second be updated.

       

      It's possible to make the update on click or I must use the <f:selectOneMenu> ?

       

      Thanks for your answer

        • 1. Re: rich:select and AJAX
          ilya_shaikovsky

          try onselectitem. by default ajax uses onchange and onchange works just accordng to standard

          • 2. Re: rich:select and AJAX
            barmic

            Thanks for your answer

            My form work with <h:selectOneMenu>

            <h:selectOneMenu value="#{find.product}" id="product">

                <f:selectItems value="#{find.products}" />

                <a4j:ajax execute="@form" render="id1" immediate="true" />

            </h:selectOneMenu>

            • 3. Re: rich:select and AJAX
              ilya_shaikovsky

              If I'm not mistaken in FireFox it will have the same behavior as for rich:select.

              • 4. Re: rich:select and AJAX
                serbec

                Hello,

                 

                I work on a project with tomcat 6, richfaces 4 Final and mojarra. I want to make the same use-case like 'barmic': update any html-content on click event without 'lost the focus' of the element rich:select itself. I have tried the event 'selectitem' and it works fine but:

                the handling of the event 'selectitem' of the element 'select' in conjunction with a standard-ajax-tag <f:ajax> seems to be sometimes incorrect.

                                    <h:form id="formid">

                                         <rich:select value="#{table.atomicNumberFilter}" label="Atomic Number Range">

                                                <f:ajax event="selectitem" render=":formid:tableid" />

                                                <f:selectItem itemValue="0" itemLabel="0..n" />

                                                <f:selectItem itemValue="20" itemLabel="20..n" />

                                                <f:selectItem itemValue="40" itemLabel="40..n" />

                                            </rich:select>

                                         <myNs:table value="#{table.rareEarthElements}" var="elem" id="tableid" >

                                             ...

                The ajax request don't work always and the event-handling of the element 'select' seems to be sometimes incorrect and lost the selectitem-event!

                 

                Is event-handling of the event 'selectitem' incorrect?

                Or is this an issue-tracker subject?

                 

                Thanks for your answer

                • 5. Re: rich:select and AJAX
                  ilya_shaikovsky
                  The ajax request don't work always

                  cant confirm.. just added your code to the test page and ajax request works fine for me. changed to a4j:ajax and it also works.

                   

                  and the event-handling of the element 'select' seems to be sometimes incorrect and lost the selectitem-event!

                  Not sure that understand that. you mean you added both ajax behavior and js handler as attribute? Then show original code for the problem and not simplified.

                  • 6. Re: rich:select and AJAX
                    serbec

                    ... and the event-handling of the element 'select' seems to be sometimes incorrect and lost the selectitem-event!

                    I mean here the same that

                    ... The ajax request don't work always

                     

                    You have to play with my samle durable to reproduce my problem:

                    If I choose the options of the element 'select' and do this durable then I can see in Firebug-Console that the ajax-request is not occurred always and my table element was not rendered.

                     

                    I hope you can reproduce it. If not, I paste here my original code.

                    • 7. Re: rich:select and AJAX
                      serbec

                      Hello Ilya,

                       

                      could you reproduce the problem? It is very important to me. You have to play with my sample durable and with more select items.

                       

                      Thanks for your support

                      • 8. Re: rich:select and AJAX
                        ilya_shaikovsky

                        really I'm not able unfortunatelly.. I added select items and played with the list a lot and seeing dependent component updated on every selection..

                         

                        Do you have any js errors when requests stopping to be sent?

                        • 9. Re: rich:select and AJAX
                          serbec

                          Do you have any js errors when requests stopping to be sent?

                          No, the firebug says me, that all is fine.

                           

                           

                          really I'm not able unfortunatelly.. I added select items and played with the list a lot and seeing dependent component updated on every selection..

                          hmm... curious. I'm not alone in my team, who can reproduce this.

                          • 10. rich:select and AJAX
                            delacroyx

                            Hi, I have a similar problem.

                                        <table>

                                            <tr>

                                                <rich:panel style="width:220px;">

                                                    <f:facet name="header">

                                                        <h:outputText value="Select provincia"></h:outputText>

                                                    </f:facet>

                                                    <rich:select enableManualInput="true"

                                                        value="#{indexController.currentProv}">

                                                        <f:selectItems value="#{indexController.provincias}" />

                                                    </rich:select>

                                                </rich:panel>

                                                <br></br>

                                                <h:commandButton id="vericurrentProv"

                                                    action="#{indexController.buscardep}"

                                                    value="ver currentProv" />

                                             </tr>

                                        </table>

                             

                                private Provincia currentProv;

                                public void buscardep() throws Exception {

                                   

                                    System.out.println(currentProv );

                                }

                             

                             

                            javax.el.ELException: / index.xhtml 55.47 @ value = "# {indexController.currentProv}" I can not convert 2, CATAMARCA from type class java.lang.String to class ar.org.osdop.rdp.model . Provincias

                             

                            Thanks for your answer

                             


                            • 11. rich:select and AJAX
                              ilya_shaikovsky

                              eugenio martin, you problem is not the same at all. in your case select just do not able to populate the currentProv object because you probably not implemented proper converter for it. try to replace rich:select with h:selectOne* and check. And his problem is about ajax request events which getting lost sometimes.

                              • 12. Re: rich:select and AJAX
                                kh.ramana

                                Below is the exact senerio where the problem exists.... This can be identified only when you try to implement as mentioned below....

                                 

                                Consider 3 rich:select items.... in which on selection of first 2 ... the 3rd will be displayed....

                                 

                                Consider the values for 1st drop-down as (ALL,A,B,C)

                                Consider the values for 2st drop-down as (ALL,X,Y,Z)

                                 

                                 

                                <rich:select id="productLine" defaultLabel="ALL"

                                                                                  value="#{....}">

                                                                                  <a4j:ajax render="members" event="selectitem" />

                                                                                  <f:selectItems value="#{.......}" />

                                                                        </rich:select>

                                 

                                <rich:select defaultLabel="ALL"

                                                                                  value="#{.....}"

                                                                                  id="location">

                                                                                  <a4j:ajax render="members" event="selectitem" />

                                                                                  <f:selectItems value="#{.................}" />

                                                                        </rich:select>

                                 

                                <h:selectManyListbox id="members" size="6"

                                                                                  value="#{..................}">

                                                                                  <f:selectItems value="#{....................}" />

                                                                        </h:selectManyListbox>

                                 

                                Exact Problem :  Initially the first 2 drop-down values are ALL & ALL...

                                I have selected the First Drop-down value as "A" ----- Rendering Works fine

                                I have selected the Second Drop-down value as "X" ----- Rendering Works fine

                                I have selected the First Drop-down value as "B" ----- Rendering Works fine

                                I have selected the Second Drop-down value as "Y" ----- Rendering Works fine

                                I have selected the Second Drop-down value as "X" ----- Problem occured (Rendered doesn't happened.)

                                I have selected the First Drop-down value as "A" ----- Rendering Works fine

                                I have selected the First Drop-down value as "B" ----- Problem occured (Rendered doesn't happened.)

                                 

                                From now X and B will not works..........



                                This is the problem where i have seen in some posts.. where the people doesn't explained clearly to the Experts in the community....

                                 

                                Can any one try to give the solution for this............... Is this the framework problem?

                                 

                                Ilya Shaikovsky you need to look into it..............

                                • 13. Re: rich:select and AJAX
                                  xermag

                                  Hi,

                                   

                                  I think is a framework problem, cause, I have the same situation, I have One f:selectOneMenu and Three rich:autocomplete nested and when I add the event="selectitem" and test, the second one don't execute the ajax, like if the event is disconnected, but if I don't add it, it works excellent. In some cases it apparently works if I reload the page without event="selectitem" and I include it latter. I attach my code:

                                   

                                  <tr>

                                    <td><h:outputLabel value="#{msgs['createCustomer.personalData.countryOfResidence']}:" /></td>

                                                      <td>

                                    <h:selectOneMenu id="countriesOfResidence" style="width: 150px;" value="#{individualCustomerBean.individualPersonalDataBean.countryOfResidence}" label="#{msgs['createCustomer.personalData.countryOfResidence']}" required="false">

                                    <f:selectItem itemValue="#{null}" itemLabel="" noSelectionOption="true"/>

                                    <f:selectItems value="#{individualCustomerBean.customerCatalogsBean.countriesList}" var="country" itemValue="#{country.countryId}"  itemLabel="#{country.countryName}"/>

                                    <a4j:ajax listener="#{individualCustomerBean.countryChanged(individualCustomerBean.individualPersonalDataBean.countryOfResidence)}" onbeforesubmit="updateState(true)" oncomplete="updateState(false);" />

                                    </h:selectOneMenu>        

                                    </td>

                                    <td><h:outputLabel value="#{msgs['createCustomer.personalData.state']}:" /></td>

                                                      <td>

                                    <rich:autocomplete disabled="#{individualCustomerBean.individualPersonalDataBean.stateEnabled}" id="states" mode="client" selectFirst="false" showButton="true" inputClass="autoCompleteCustomer" var="state" fetchValue="#{state.stateName}" autocompleteList="#{individualCustomerBean.customerCatalogsBean.states}" value="#{individualCustomerBean.individualPersonalDataBean.state}" autofill="true" label="#{msgs['createCustomer.personalData.state']}" required="false">

                                    <rich:column>

                                                                                    #{state.stateName}

                                    </rich:column>

                                    <a4j:ajax listener="#{individualCustomerBean.stateChanged(individualCustomerBean.individualPersonalDataBean.state)}" event="selectitem" onbeforesubmit="updateCounty(true)" oncomplete="updateCounty(false);"/>    

                                    </rich:autocomplete>    

                                                      </td> 

                                    </tr>

                                    <tr>

                                    <td><h:outputLabel value="#{msgs['createCustomer.personalData.county']}:" /></td>

                                                      <td>    

                                    <rich:autocomplete disabled="#{individualCustomerBean.individualPersonalDataBean.countyEnabled}" selectFirst="false" id="counties" mode="client" showButton="true" inputClass="autoCompleteCustomer" var="county"  fetchValue="#{county.countyName}" autocompleteList="#{individualCustomerBean.customerCatalogsBean.counties}" value="#{individualCustomerBean.individualPersonalDataBean.county}" autofill="true" label="#{msgs['createCustomer.personalData.county']}" required="false">

                                    <rich:column>

                                                                                    #{county.countyName}

                                    </rich:column>

                                    <a4j:ajax listener="#{individualCustomerBean.countyChanged(individualCustomerBean.individualPersonalDataBean.county)}" event="selectitem" onbeforesubmit="updateDistrict(true)" oncomplete="updateDistrict(false)" />

                                    </rich:autocomplete>

                                                      </td> 

                                    <td><h:outputLabel value="#{msgs['createCustomer.personalData.district']}:" /></td>

                                                      <td>

                                    <rich:autocomplete disabled="#{individualCustomerBean.individualPersonalDataBean.districtEnabled}" selectFirst="false" id="districts" mode="client" showButton="true" inputClass="autoCompleteCustomer" var="district" fetchValue="#{district.districtName}" autocompleteList="#{individualCustomerBean.customerCatalogsBean.districts}" value="#{individualCustomerBean.individualPersonalDataBean.district}" autofill="true" label="#{msgs['createCustomer.personalData.distrit']}" required="false">

                                    <rich:column>

                                                                                    #{district.districtName}

                                    </rich:column>

                                    </rich:autocomplete>

                                                      </td> 

                                  </tr>

                                   


                                  Please let me know if someone find a soluction.

                                   

                                  Thanks and regards.