3 Replies Latest reply on Mar 17, 2009 5:27 PM by Steffen Persch

    h:selectOneMenu and null value

    Roman Rodov Newbie

      Strange problem with h:selectOneMenu. The view has:


      <h:selectOneMenu id="state" value="#{situation.state}">
                                          <s:selectItems var="state"
                                                         itemValue="#{state.codeValue}"
                                                         label="#{state.shortDescription}"
                                                         value="#{referenceDataStore.states}"
                                                         noSelectionLabel="Select..."/>
                                      </h:selectOneMenu>



      The view also has a bunch of text boxes for other properties of the situation. When I navigate away from the page by clicking and action button, without changing the selected item in the drop down, the null value gets persisted to #{situation.state}. If I select a value in the drop down and navigate away from the page, the selected value is also successfully persisted to #{situation.state}. When I navigate back to the page the previously select value is shown as selected in the drop down.


      Now, if I select the Select... option (effectively I want null to be stored into #{situation.state}) and try to navigate away from the page, it seems that the value available in the action is NOT null, but the original value.


      Here is the Situation entity (all other fields in it are set correctly):


      @Entity
      @Table( name = "SITUATION", schema = "PUBLIC" )
      @AttributeOverride( name = "id", column = @Column( name = "Situation_Id" ) )
      @DiscriminatorColumn( name = "DISCRIMINATOR", discriminatorType = DiscriminatorType.STRING, length = 100 )
      @SequenceGenerator( sequenceName = "SQ_SITUATION", name = "idGenerator" )
      public class Situation
              extends BaseItem
              implements java.io.Serializable, TemplateClass
      {
          @OneToMany( mappedBy = "situation", cascade = CascadeType.ALL, fetch = FetchType.LAZY )
          private List<Cover> covers = new ArrayList<Cover>();
      
          @OneToMany( mappedBy = "situation", cascade = CascadeType.ALL, fetch = FetchType.LAZY )
          private List<Item> items = new ArrayList<Item>();
      
          @OneToMany( mappedBy = "situation", cascade = CascadeType.ALL, fetch = FetchType.LAZY )
          private List<SituationAttribute> situationAttributes =
                  new ArrayList<SituationAttribute>();
      
          @ManyToOne( fetch = FetchType.LAZY, cascade = CascadeType.ALL, targetEntity = ProductSpecificType.class )
          @JoinColumn( name = "Product_Specific_Type_Id" )
          private ProductSpecificType productSpecificType;
      
          @ManyToOne( fetch = FetchType.LAZY )
          @JoinColumn( name = "Section_Id" )
          private Section section;
      
          @Column( name = "ADDRESS_LINE_1", length = 200 )
          @Length( max = 200 )
          private String addressLine1;
          @Column( name = "ADDRESS_LINE_2", length = 200 )
          @Length( max = 200 )
          private String addressLine2;
          @Column( name = "SUBURB", length = 200 )
          @Length( max = 200 )
          private String suburb;
          @Column( name = "POSTCODE", length = 8 )
          @Length( max = 8 )
          private String postcode;
          @Column( name = "STATE", length = 4 )
          @Length( max = 4 )
          private String state;
      
          public Situation()
          {
              propertyValueAccessor = new PropertyValueAccessor<SituationAttribute>();
          }
      
          @Transient
          private PropertyValueAccessor<SituationAttribute> propertyValueAccessor;
      
          public void setPropertyValue( String name, Object value )
          {
              propertyValueAccessor.setPropertyValue(
                  new PropertyValueContext<SituationAttribute>(
                      name, value, situationAttributes, SituationAttribute.class, this ) );
          }
      
          public String getPropertyValue( String name )
          {
              return propertyValueAccessor.getPropertyValue( name, situationAttributes );
          }
      
          public List<Cover> getCovers()
          {
              return covers;
          }
      
          public List<Item> getItems()
          {
              return items;
          }
      
          public <T extends BaseAttribute> void addAttribute( T attribute )
          {
              situationAttributes.add( ( SituationAttribute )attribute );
          }
      
          public ProductSpecificType getProductSpecificType()
          {
              return productSpecificType;
          }
      
          public void setProductSpecificType( ProductSpecificType productSpecificType )
          {
              this.productSpecificType = productSpecificType;
          }
      
          public Section getSection()
          {
              return section;
          }
      
          public void setSection( Section section )
          {
              this.section = section;
          }
      
          public String getAddressLine1()
          {
              return addressLine1;
          }
      
          public void setAddressLine1( String addressLine1 )
          {
              this.addressLine1 = addressLine1;
          }
      
          public String getAddressLine2()
          {
              return addressLine2;
          }
      
          public void setAddressLine2( String addressLine2 )
          {
              this.addressLine2 = addressLine2;
          }
      
          public String getSuburb()
          {
              return suburb;
          }
      
          public void setSuburb( String suburb )
          {
              this.suburb = suburb;
          }
      
          public String getPostcode()
          {
              return postcode;
          }
      
          public void setPostcode( String postcode )
          {
              this.postcode = postcode;
          }
      
          public String getState()
          {
              return state;
          }
      
          public void setState( String state )
          {
              this.state = state;
          }
      }