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

    DataModelSelection always returns with the first element

    Tamas Malatinszki Newbie

      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"
        <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"/>
                      <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"/>

      And here is the action bean:

      public class CountryAction {
         private List<SelectItem> countrys;
         @Out(required=false, value="selected")
         private SelectItem selected;
         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?