2 Replies Latest reply on May 20, 2015 5:28 AM by martam

    rich:select null value problem

    martam Newbie

      After upgrade to RichFaces 4.5 I have a problem with null value in rich:select.

       

      My xhtml looks like this:

      <rich:select id="id1" value="#{object.property}" converter="#{propertyConverter}">
           <f:selectItem itemLabel="-- no value --" itemValue="#{null}" />
           <f:selectItems value="#{myBean.propertyValues}" var="prop" itemValue="#{prop}" itemLabel="#{prop.description}" />
      </rich:select>
      

       

      And the converter:

      public class PropertyConverter extends Converter {
      
        @Override
        public Object getAsObject(FacesContext facesContext, UIComponent component, String s) {
             return dao.findByKey(Long.valueOf(s));
        }
        
        @Override
        public String getAsString(FacesContext facesContext, UIComponent component, Object value) {
           if (value == null || value.equals("")) {
                return "";
           } else {
                return (Property) value).getId().toString();
           }
        }
      }
      

       

      The class Property has id of type Long and it has equals and hashCode methods overriden.


      When I used RichFaces 4.3.6, everything worked fine. When I use h:selectOneMenu instead of rich:select, everything works fine. When I replace itemLabel="-- no value --" with and empty string (itemLabel=""), everything works fine. But rich:select (which I'd like to use because of layout) with not empty label (which I'd like to use because it's more readable to end user) does not work. When I choose no value option and try to submit, I get an error that the value is invalid.

       

      Do you have any idea where is the error? I use RichFaces 4.5.4 Final and Mojarra 2.2.10.

        • 1. Re: rich:select null value problem
          Michal Petrov Master

          There is a validator in place that invalidates null values if the label is not empty or if it's not the default one. In 4.3.x if you selected a null value the input would be blank (it wouldn't show the label), I don't know if that was intentional but the method that did it is not executed in 4.5.x.

          1 of 1 people found this helpful
          • 2. Re: rich:select null value problem
            martam Newbie

            I haven't noticed the defaultLabel parameter before. When I add defaultLabel parameter to my rich:select with the value same as for null value, it seems to work correctly.

             

            <rich:select id="id1" value="#{object.property}" converter="#{propertyConverter}" defaultLabel="-- no value --">
                 <f:selectItem itemLabel="-- no value --" itemValue="#{null}" />
                 <f:selectItems value="#{myBean.propertyValues}" var="prop" itemValue="#{prop}" itemLabel="#{prop.description}" />
            </rich:select>
            

             

            Is this a right way of using this parameter?