1 Reply Latest reply on Mar 19, 2009 5:34 PM by Franco Fernandes

    Problems gettings the local value of JSF component

    Franco Fernandes Novice

      I have 2 components on my page in this order

      <h:selectOneMenu value="#{itemHome.instance.itemType}" required="true" id="itemType" 
           label="Item type"valueChangeListener="#{itemHome.itemTypeChangeEvent}">
           <s:selectItems value="#{activeItemTypeList.resultList}" var="_itemType" label="#{_itemType.itemType}" 
                 noSelectionLabel="[Select]" />
           <s:convertEntity />
           <a4j:support event="onblur" reRender="itemLocationDecoration" 
                bypassUpdates="true" ajaxSingle="true"      />
      <s:decorate id="itemLocationDecoration" >
      <h:selectOneMenu value="#{itemHome.instance.location}" 
           id="location" label="Location" required="true"  >
           <s:selectItems value="#{activeLocationList.resultList}" var="_location" label="#{_location.locationName}" noSelectionLabel="[Select]"/>
           <s:convertEntity />
           <a4j:support event="onblur"  bypassUpdates="true" ajaxSingle="true" 
                    reRender="itemLocationDecoration" /> 

      If the user picks the noselection value is list 2, the required validator is fired as expected.

      He ignores it and now picks an item type from itemType dropdown (list 1). What I am trying to do in the valueChangeListener event of this field is to check the component current value of location field for a null value. This is what I have in my valueChangeListener event

      protected Map<String, UIComponent> uiComponent;   
      public void itemTypeChangeEvent(ValueChangeEvent event) 
      Object newValue = event.getNewValue();
      if ( newValue instanceof ItemType) {
           //Get default location for this item type
           newValue = (ItemType) newValue;
           Location location = ((ItemType) newValue).getLocation(); 
           if ( location != null ) {
                //check current location value on form
                UIComponent component = uiComponent.get("itemEditForm:itemLocationDecoration:location");
                Object currentLocation = component.getAttributes().get("value");
                //if current location on form is null reset location with default location
                if ( currentLocation == null   ) {

      currentLocation always returns the last valid value and not a null as I am expecting.

      Is my code wrong ?
      What is the correct way to get the local value of another component on the page?