Hello Volker,

thanks for reply. Now my tx:selectOneChoice box looks like the following. Converter is away and values in braces
            <tx:selectOneChoice value="#{myController.active}" label="active">

<f:selectItem itemValue="#{0}" itemLabel="inactiv" /> <f:selectItem itemValue="#{1}" itemLabel="activ" />

                       </tx:selectOneChoice>

but now nothing works even not storing the values in the Controller.

if I use the version without the braces I can store the value but the old problem is there that rendering the current id of active is not selected in the tx:selectOneChoice :

            <tx:selectOneChoice value="#{myController.active}" label="active">

<f:selectItem itemValue="0" itemLabel="inactiv" /> <f:selectItem itemValue="1" itemLabel="activ" />

                       </tx:selectOneChoice>

The getter and Setter definition looks like the these ones:

   private Integer active;

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

Any idea else?

Best regards Michael

Volker Weber schrieb:
Hi Michael,

(btw yes i work together with Dirk Fangohr. sorry for the delay, was a
bit busy last Friday)

the problem is you has int as value in getActive() but String in select items.

Try
       <tc:selectItem itemValue="#{2}" itemLabel="active"/>
       <tc:selectItem itemValue="#{1}" itemLabel="suspended"/>
       <tc:selectItem itemValue="#{0}" itemLabel="inactice"/>

you don't need a converter!


Regards,
    Volker

2010/4/21 Michael Kakuschky <[email protected]>:
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





Reply via email to