3 Replies Latest reply on May 3, 2011 5:45 AM by Tauseef Ahmed

    noSelectionLabel with selectOneRadio

    gebuh Newbie

      I have a list generated from a database table:




      <h:selectOneRadio value="#{bean.areaSelected}">
      <s:selectItems value="#{area}" var="_area" label="#{_area.name}" />
      <s:convertEntity />
      </h:selectOneRadio>





      looks like:


      O north      O south      O east   O west


      User can select one area at a time.
      But when the page loads initially no area is selected and the resultant dataTable displays all areas.
      But what I want is:


      O all areas  O north      O south      O east   O west


      I tried using noSelectionLabel:


      <h:selectOneRadio value="#{bean.areaSelected}"
       noSelectionLabel="All areas" >
      <s:selectItems value="#{area}" var="_area" label="#{_area.name}" />
      <s:convertEntity />
      </h:selectOneRadio>




      The page initially loads normally,  'all areas' radio button is displayed(but not selected by default) and dataTable correctly displays all areas.  But when I select the all areas radio button the page blows up (I will post the exact error when I get back to my computer).  If hit the browser back button, the all areas radio button is selected and correct data is displayed.


      Is there a way I can have an all areas button and have it selected by default at page load?  Or will this not work with radio buttons?

        • 1. Re: noSelectionLabel with selectOneRadio
          Tauseef Ahmed Newbie

          Hi,


          Instead on using noSelectionLabel=All areas you add an object to your bean.areaSelected list with area name as All areas with some value say 0.



          Regards,
          Tauseef

          • 2. Re: noSelectionLabel with selectOneRadio
            gebuh Newbie

            Tauseef Ahmed wrote on May 03, 2011 00:50:


            Hi,

            Instead on using noSelectionLabel=All areas you add an object to your bean.areaSelected list with area name as All areas with some value say 0.


            Regards,
            Tauseef



            area objects consist of an area name and a sysid.  When a user selects an area the sysid is used to search another db table.  If the sysid is null it performs an open search.  I tried creating an object that that just held all areas as an area name and everything else null, but that just generated NPE's.  Maybe if I set the sysid to -1 and catch that in the restrictions?

            • 3. Re: noSelectionLabel with selectOneRadio
              Tauseef Ahmed Newbie

              I didn't understand I tried creating an object that that just held all areas as an area name and everything else null,


              Your list must have values as
                           Name           value(sysid)
                         All areas          0
                         north              1
                         south              2
                         east               3
                         west               4


              On searching you will see that if the sysid is 0 then populate as required.