Hi Michael,

I've thought about that problem and implemented a solution that works for the most cases.
See: https://issues.apache.org/jira/browse/TOBAGO-877

With the current sources your example should work now, without any of the modifications I told you.

Which version of JSF you are using? The f:selectItem works not with JSF 1.1, but the tc:selectItem works with 1.1 and 1.2.

Regards,

Udo

Am 23.04.10 09:59, schrieb Udo Schnurpfeil:
Hi Michael,

there are more than one solution for that, but as far as I know there is not cast operator...

1. use a managed bean
faces-config.xml:
<managed-bean>
<managed-bean-name>intValues</managed-bean-name>
<managed-bean-class>java.util.ArrayList</managed-bean-class>
<managed-bean-scope>application</managed-bean-scope> <!-- or use "none" -->
<list-entries>
<value-class>java.lang.Integer</value-class>
<value>0</value>
<value>1</value>
<value>2</value>
</list-entries>
</managed-bean>
JSP/Facelet:
<tc:selectItem itemValue="#{intValues[1]}" itemLabel="suspended"/>
(simple, scales not good, works with JSF 1.1, 1.2 and JSP and Facelets)

2. write a EL-function
AFAIK: works with facelets and/or JSF 1.2 but may not work with JSP and JSF 1.1.
What do you are using?

3. write a converter that implements the list, or map interface and use it as managed bean (a little bit complicated, scales good, works with JSF 1.1, 1.2 and JSP and Facelets)

4. write an additional getter/setter activeLong.
(needs Java)

5. use <tc:selectItems> (instead of <tc:selectItem>) and you may also want to use enums. (may be the best solution but more work, needs Java 1.5, scales good, refactoring is easy: there is only one position in the code to define the values, type save: use the enum in your Controller, so you know the meaning of the value from the enum)

For a simple application or demo I would prefer #1 or #4, for an enterprise application I would prefer #5...

Regards,

Udo

Am 22.04.10 22:33, schrieb Michael Kakuschky:
Hello Udo, hello Volker,

both together (using braces for EL expression and long data type for getter and setter) helped to get the tx:selectOneChoice working like expected :-)

Since I use many int getters and setters where I want to use the tx:selectOneChoice component it would be nice if there is some way to convert the int to long in EL. It would help to save a lot of work..


Thanks & best regards Michael


Udo Schnurpfeil schrieb:
Hi,

there is still a little problem with that. #{0} is a Long value, so the getter/setter needs be a also a Long and not an Integer.
I don't know, if in EL there is something like a "cast" operator...

Regards,

Udo

Am 22.04.10 18:20, schrieb Volker Weber:
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<kakusc...@elbe-net.de>:
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