myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Kakuschky <kakusc...@elbe-net.de>
Subject [TOBAGO] problem selecting current item in tx:selectOneChoice
Date Wed, 21 Apr 2010 17:23:37 GMT
Hello,

I have a strange problem selecting the correct item of 
tx:selectOneChoice boxes if the  itemValue of the tc:selectItem item is 
an Integer.

Storing the selected values works fine as aspected. I will find the 
correct values in mybackend database

What does not work is that after rerendering the correct value is 
selected. If in my example the MyController.active Integer attribute has 
a value of 1 "suspended" should be selected. But it's always the first 
value of the tc:selectItem elements selected.

I tried already to use a converter because  I guessed that  there is an 
conversion problem between Integer  and String but it does not help.

If the selectItem bind to a String  it works fine (sure without the 
integerConverter). With the tomahawk h:selectOneMenu component it works 
also with Integers.

Knows anybody how to solve this problem for tobago to use an Integer as 
value attribute?

 <tc:cell>
     <tx:selectOneChoice value="#{myController.active}" label="active"  
converter="integerConverter">
         <tc:selectItem itemValue="2" itemLabel="active"/>
         <tc:selectItem itemValue="1" itemLabel="suspended"/>
         <tc:selectItem itemValue="0" itemLabel="inactice"/>
     </tx:selectOneChoice>
 </tc:cell>

public class MyController{
    private Integer active = 1;

    public Integer getActive() {
        return active;
    }
    public void setActive(Integer active) {
        this.active = active;
    }
}

public class IntegerConverter  implements Converter {

  public Object getAsObject(FacesContext context, UIComponent component, 
String value) throws ConverterException {
    return Integer.getInteger(value);
  }

public String getAsString(FacesContext context, UIComponent component, 
Object value) throws ConverterException {
    if (value instanceof Integer) {
      return ((Integer) value).toString();
    }
    return "";
  }
}

Thanks and best regards

Michael

Mime
View raw message