You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Michael Kakuschky <ka...@elbe-net.de> on 2010/04/21 19:23:37 UTC

[TOBAGO] problem selecting current item in tx:selectOneChoice

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

Re: [TOBAGO] problem selecting current item in tx:selectOneChoice

Posted by Udo Schnurpfeil <ud...@schnurpfeil.de>.
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<ka...@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
>>>>>
>>>>
>>>>
>>
>>
>

Re: [TOBAGO] problem selecting current item in tx:selectOneChoice

Posted by Udo Schnurpfeil <ud...@schnurpfeil.de>.
I've fixed it in the current trunk and the current 1.0.x branch, so it 
will be available in version 1.0.26. (See my mail form 23. April, 23:19 
CEST)

Regards

Udo
> I'm not really understanding why the mapping does not works with 
> <tc:selectItem> but for know I have a working solution.
>
>

Re: [TOBAGO] problem selecting current item in tx:selectOneChoice

Posted by Michael Kakuschky <ka...@elbe-net.de>.
Hello Udo, thanks for the comprehensive answer.

I decide to use solution no. 5 and it works fine for me. But I dont't 
use enums because the underlying objects  are also used for hibernates 
and it'makes some trouble to mapped them to the hibernate datatypes.

I'm not really understanding why the mapping does not works with 
<tc:selectItem> but for know I have a working solution.

Thanks & best regards Michael

Udo Schnurpfeil schrieb:
> 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<ka...@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
>>>>>
>>>>
>>>>
>>
>>

Re: [TOBAGO] problem selecting current item in tx:selectOneChoice

Posted by Udo Schnurpfeil <ud...@schnurpfeil.de>.
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<ka...@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
>>>>
>>>
>>>
>
>

Re: [TOBAGO] problem selecting current item in tx:selectOneChoice

Posted by Michael Kakuschky <ka...@elbe-net.de>.
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<ka...@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
>>>
>>>      
>>
>>
>>    


Re: [TOBAGO] problem selecting current item in tx:selectOneChoice

Posted by Udo Schnurpfeil <ud...@schnurpfeil.de>.
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<ka...@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
>>
>>      
>
>
>    

Re: [TOBAGO] problem selecting current item in tx:selectOneChoice

Posted by Michael Kakuschky <ka...@elbe-net.de>.
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 <ka...@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
>>
>>     
>
>
>
>   


Re: [TOBAGO] problem selecting current item in tx:selectOneChoice

Posted by Volker Weber <v....@inexso.de>.
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 <ka...@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
>



-- 
inexso - information exchange solutions GmbH
Bismarckstraße 13      | 26122 Oldenburg
Tel.: +49 441 4082 356 |
FAX:  +49 441 4082 355 | www.inexso.de