0 Replies Latest reply on Oct 8, 2008 2:58 PM by tmalatinszki

    DataModelSelection always returns with the first element

    tmalatinszki

      Hi All,


      I just started to use Seam, and now I have a very weird issue with it. I'm using an action bean (called CountryAction) and a xhtml file which contains a h:selectOneListBox component.


      Here is the xhtml:


      <ui:composition xmlns="http://www.w3.org/1999/xhtml"
              xmlns:ui="http://java.sun.com/jsf/facelets"
              xmlns:h="http://java.sun.com/jsf/html"
              xmlns:f="http://java.sun.com/jsf/core"
              xmlns:a4j="http://richfaces.org/a4j"
              xmlns:rich="http://richfaces.org/rich"
              xmlns:s="http://jboss.com/products/seam/taglib">
       
        <a4j:loadStyle src="/stylesheet/common.css"/>
              <a4j:region id="menuRegion"> 
          <f:loadBundle basename="messages" var="messages" />
              <a4j:form id="menuForm">
       
            <rich:panel id="menuPanel" styleClass="rsPanel" style=" height:155px; width:220px">
              <f:facet name="header">
                <h:outputLabel value="Select" for="menuPanel"/>
              </f:facet>
       
                      <rich:spacer height="8px"/>
       
                        <h:selectOneListbox value="#{selected}" size="1">
                          <s:selectItems var="cons" value="#{countrys}" label="#{cons.label}" noSelectionLabel=""/>
                      <a4j:support event="onchange" actionListener="#{countryAction.changeCountry}" reRender="menuPanel"/>
                        </h:selectOneListbox>
       
            </rich:panel>
         </a4j:form>
         </a4j:region>
      </ui:composition>
      



      And here is the action bean:


      @Name("countryAction")
      @Scope(ScopeType.SESSION)
      public class CountryAction {
       
         @DataModel
         private List<SelectItem> countrys;
       
         @DataModelSelection(value="countrys")
         @Out(required=false, value="selected")
         private SelectItem selected;
              
         @SuppressWarnings("unchecked")
         @Factory("countrys")
         public void loadCountrys(){
             this.countrys= new ArrayList<SelectItem>();
             this.countrys.add(new SelectItem(1,"Hungary"));
             this.countrys.add(new SelectItem(2,"United Kingdom"));
         }
              
         public List<SelectItem> getCountrys() {
            return this.countrys;
         }
       
         public void setCountrys(List<SelectItem> countrys) {
            this.countrys = countrys;
         }
       
         public SelectItem getSelected() {
            return selected;
         }
       
         public void setSelected(SelectItem selected) {
            this.selected = selected;
         }
       
         public void changeCountry(ActionEvent event) {
            logger.info("changeCountry() has been called");
            logger.info("country is: "+selected.getValue()+":"+selected.getLabel());
         }
              
      }
      



      As You can see there is a a4j:support in the h:selectOneListBox element that calls changeCountry() method if You selects an item.
      The problem is when I'm selecting a value from the selectOneListBox the selected item always will be the FIRST element of the countrys list (so if You select the United Kingdom or anything else the selected value always will be Hungary, so the first element of the list). I've tried to use entities instead of SelectItem objects, but the failure was the same. There is no any error message, it's just works wrong.
      I'm using JBoss 4.2.2 and Seam 2.0.1 with JSF 1.2.


      Is there anyone else who had the same issue before?


      Thanks,
      Tamas