You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by tkazmierczak <T....@ecofys.com> on 2008/09/09 16:34:22 UTC

default value in tr:selectOneChoice

Hello,
I've searched half of the Internet, but haven't found an answer to my
question.

I create a tr:selectOneChoice this way:

<tr:selectOneChoice label="Start year" value="1" required="true"
valuePassThru="true">
	<tr:forEach var="year" begin="0" end="10">
		<tr:selectItem label="#{year}" value="#{year}" />
	</tr:forEach>
</tr:selectOneChoice>

and want the resulting HTML combobox to have the value with label "1" set by
default, but what I get is that the combobox is set to an "empty" value and
I get this error message in the server's output:

2008-09-09 15:54:23
org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.SimpleSelectOneRenderer
_getSelectedIndex
WARNING: Could not find selected item matching value "1" in
CoreSelectOneChoice[UIXEditableFacesBeanImpl, id=_idJsp9]

What is wrong/missing in the code?
I'm using Trinidad 1.0.7.
-- 
View this message in context: http://www.nabble.com/default-value-in-tr%3AselectOneChoice-tp19393693p19393693.html
Sent from the MyFaces - Users mailing list archive at Nabble.com.


Re: default value in tr:selectOneChoice

Posted by tkazmierczak <T....@ecofys.com>.
I'm using Java 6. But maybe the problem is caused by the fact that the
version of JSF I'm using is 1.1?
Anyway, I cannot upgrade to a higher version. But I've found a solution -
instead of adding the tr:selectItem tags using tr:foreach, I just hardcoded
the list of tr:selectItem tags into the jspx page, with the value attributes
of the tags set just to, for example, value="2008" (so a plain string
instead of EL). Not the neatest solution, but in my case it was acceptable
and what is the most important thing - it works.


Richard Yee-3 wrote:
> 
> I'm guessing that you are using java 5 and the year variable is  
> getting autoboxed to an Integer object in the selectItem.
> I suggest that you create the list of selectItems in the backing bean,  
> have a getter for the list, and use the f:items tag to retrieve the  
> list. Make sure the type you use for you selectOneChoice matches the  
> type of the value in the selectItem. Is. They are both Integers or  
> Strings.
> 
> -R
> 
> Sent from my iPhone
> 
> On Sep 24, 2008, at 1:35 AM, tkazmierczak <T....@ecofys.com>  
> wrote:
> 
>>
>>
>> Richard Yee-3 wrote:
>>>
>>> As I mentioned in my prior email, you need to set the value attribute
>>> in the tr:selectOneChoice tag to be an el expression that resolves to
>>> a property in a backing bean.
>>>
>>> ie. value="#{myBacking.selectVal}"
>>>
>>> selectVal would be defined as a String and would have a getter and
>>> setter. To select a default select item, you would have the value of
>>> selectVal to the desired selected value
>>>
>>> ie
>>>
>>> String selectVal = "1";
>>
>> It doesn't help. I still get the warning that the value has not been  
>> found
>> in the <tr:selectItem>s.
>> But I've found a workaround (maybe not the neatest, but at least it  
>> works) -
>> I set the first <tr:selectItem> to the same value as the "value"  
>> attribute
>> of <tr:selectOneChoice>, then, I generate the rest of selectItems,  
>> but start
>> the iteration from one year later.
>> -- 
>> View this message in context:
>> http://www.nabble.com/default-value-in-tr%3AselectOneChoice-tp19393693p19644376.html
>> Sent from the MyFaces - Users mailing list archive at Nabble.com.
>>
> 
> 

-- 
View this message in context: http://www.nabble.com/default-value-in-tr%3AselectOneChoice-tp19393693p19990901.html
Sent from the MyFaces - Users mailing list archive at Nabble.com.


Re: default value in tr:selectOneChoice

Posted by Richard Yee <ri...@gmail.com>.
I'm guessing that you are using java 5 and the year variable is  
getting autoboxed to an Integer object in the selectItem.
I suggest that you create the list of selectItems in the backing bean,  
have a getter for the list, and use the f:items tag to retrieve the  
list. Make sure the type you use for you selectOneChoice matches the  
type of the value in the selectItem. Is. They are both Integers or  
Strings.

-R

Sent from my iPhone

On Sep 24, 2008, at 1:35 AM, tkazmierczak <T....@ecofys.com>  
wrote:

>
>
> Richard Yee-3 wrote:
>>
>> As I mentioned in my prior email, you need to set the value attribute
>> in the tr:selectOneChoice tag to be an el expression that resolves to
>> a property in a backing bean.
>>
>> ie. value="#{myBacking.selectVal}"
>>
>> selectVal would be defined as a String and would have a getter and
>> setter. To select a default select item, you would have the value of
>> selectVal to the desired selected value
>>
>> ie
>>
>> String selectVal = "1";
>
> It doesn't help. I still get the warning that the value has not been  
> found
> in the <tr:selectItem>s.
> But I've found a workaround (maybe not the neatest, but at least it  
> works) -
> I set the first <tr:selectItem> to the same value as the "value"  
> attribute
> of <tr:selectOneChoice>, then, I generate the rest of selectItems,  
> but start
> the iteration from one year later.
> -- 
> View this message in context: http://www.nabble.com/default-value-in-tr%3AselectOneChoice-tp19393693p19644376.html
> Sent from the MyFaces - Users mailing list archive at Nabble.com.
>

Re: default value in tr:selectOneChoice

Posted by tkazmierczak <T....@ecofys.com>.

Richard Yee-3 wrote:
> 
> As I mentioned in my prior email, you need to set the value attribute
> in the tr:selectOneChoice tag to be an el expression that resolves to
> a property in a backing bean.
> 
> ie. value="#{myBacking.selectVal}"
> 
> selectVal would be defined as a String and would have a getter and
> setter. To select a default select item, you would have the value of
> selectVal to the desired selected value
> 
> ie
> 
> String selectVal = "1";

It doesn't help. I still get the warning that the value has not been found
in the <tr:selectItem>s.
But I've found a workaround (maybe not the neatest, but at least it works) -
I set the first <tr:selectItem> to the same value as the "value" attribute
of <tr:selectOneChoice>, then, I generate the rest of selectItems, but start
the iteration from one year later.
-- 
View this message in context: http://www.nabble.com/default-value-in-tr%3AselectOneChoice-tp19393693p19644376.html
Sent from the MyFaces - Users mailing list archive at Nabble.com.


Re: default value in tr:selectOneChoice

Posted by Richard Yee <ri...@gmail.com>.
As I mentioned in my prior email, you need to set the value attribute
in the tr:selectOneChoice tag to be an el expression that resolves to
a property in a backing bean.

ie. value="#{myBacking.selectVal}"

selectVal would be defined as a String and would have a getter and
setter. To select a default select item, you would have the value of
selectVal to the desired selected value

ie

String selectVal = "1";


-Richard

On Wed, Sep 17, 2008 at 2:30 AM, Rafa Pérez <ra...@gmail.com> wrote:
> Try changing
>
>>        <tr:forEach var="year" begin="#0" end="10">
>>                <tr:selectItem label="#{year}" value="#{year}" />
>>        </tr:forEach>
>
> for:
>
> <f:selectItems value="#{bean.selectItemArray}"  />
>
> And in the bean add (with its getter and setter):
>
> private SelectItem[] selectItemArray;
>
>
> Then, to load the array you just have to do:
>
> selectItemArray = new SelectItemArray[1];
>
> selectItemArray[0] = new SelectItem(year, year.toString());
>
>
> HTH
>
>
> On Wed, Sep 17, 2008 at 11:19 AM, tkazmierczak <T....@ecofys.com> wrote:
>>
>> Ok, now my code looks like this:
>>
>> <tr:selectOneChoice label="Start year" value="#{bean.initialValue}"
>> required="true" valuePassThru="true">
>>        <tr:forEach var="year" begin="#0" end="10">
>>                <tr:selectItem label="#{year}" value="#{year}" />
>>        </tr:forEach>
>> </tr:selectOneChoice>
>>
>> the bean.initialValue is set to 1 in the declaration of the member (private
>> int initialValue = 1;)
>> but this doesn't help. I get such warning:
>>
>> 2008-09-17 11:08:18
>> org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.SimpleSelectOneRenderer
>> _getSelectedIndex
>> WARNING: Could not find selected item matching value "1" in
>> CoreSelectOneChoice[UIXEditableFacesBeanImpl, id=_idJsp9]
>>
>> As you might have noticed, the combo-box will store years, so the values
>> will be greater than 1000. When I put, for example, 2008 as the
>> initialValue, and iterate from 2008 to 2050, the warning says:
>> Could not find selected item matching value "2 008" in CoreSelectOneChoice
>> So it seems that the value is converted from an integer to a string... Maybe
>> that's the problem? If so, then how to force the selectOneChoice and
>> selectItem to compare the values as integers?
>>
>>
>> Richard Yee-3 wrote:
>>>
>>> You should have the value attribute in the selectOneChoice be an EL
>>> expression that references a field in your backing bean. If you do
>>> this and set the value of the field to "1" when the bean is created,
>>> it will be defaulted as you expect. With your current code, there is
>>> no way of submitting the value of the selectOneChoice.
>>>
>>> -Richard
>>>
>>> On Tue, Sep 9, 2008 at 7:34 AM, tkazmierczak <T....@ecofys.com>
>>> wrote:
>>>>
>>>> Hello,
>>>> I've searched half of the Internet, but haven't found an answer to my
>>>> question.
>>>>
>>>> I create a tr:selectOneChoice this way:
>>>>
>>>> <tr:selectOneChoice label="Start year" value="1" required="true"
>>>> valuePassThru="true">
>>>>        <tr:forEach var="year" begin="0" end="10">
>>>>                <tr:selectItem label="#{year}" value="#{year}" />
>>>>        </tr:forEach>
>>>> </tr:selectOneChoice>
>>>>
>>>> and want the resulting HTML combobox to have the value with label "1" set
>>>> by
>>>> default, but what I get is that the combobox is set to an "empty" value
>>>> and
>>>> I get this error message in the server's output:
>>>>
>>>> 2008-09-09 15:54:23
>>>> org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.SimpleSelectOneRenderer
>>>> _getSelectedIndex
>>>> WARNING: Could not find selected item matching value "1" in
>>>> CoreSelectOneChoice[UIXEditableFacesBeanImpl, id=_idJsp9]
>>>>
>>>> What is wrong/missing in the code?
>>>> I'm using Trinidad 1.0.7.
>>>> --
>>>> View this message in context:
>>>> http://www.nabble.com/default-value-in-tr%3AselectOneChoice-tp19393693p19393693.html
>>>> Sent from the MyFaces - Users mailing list archive at Nabble.com.
>>>>
>>>>
>>>
>>>
>>
>> --
>> View this message in context: http://www.nabble.com/default-value-in-tr%3AselectOneChoice-tp19393693p19527785.html
>> Sent from the MyFaces - Users mailing list archive at Nabble.com.
>>
>>
>

Re: default value in tr:selectOneChoice

Posted by tkazmierczak <T....@ecofys.com>.
Unfortunately this didn't help.

But this helps:

          <tr:selectItem label="2008" value="2008" />
          <tr:selectItem label="2009" value="2009" />
          <tr:selectItem label="2010" value="2010" />
          <tr:selectItem label="2011" value="2011" />


Rafa Pérez wrote:
> 
> Try changing
> 
>>        <tr:forEach var="year" begin="#0" end="10">
>>                <tr:selectItem label="#{year}" value="#{year}" />
>>        </tr:forEach>
> 
> for:
> 
> <f:selectItems value="#{bean.selectItemArray}"  />
> 
> And in the bean add (with its getter and setter):
> 
> private SelectItem[] selectItemArray;
> 
> 
> Then, to load the array you just have to do:
> 
> selectItemArray = new SelectItemArray[1];
> 
> selectItemArray[0] = new SelectItem(year, year.toString());
> 
> 
> HTH
> 

-- 
View this message in context: http://www.nabble.com/default-value-in-tr%3AselectOneChoice-tp19393693p19990967.html
Sent from the MyFaces - Users mailing list archive at Nabble.com.


Re: default value in tr:selectOneChoice

Posted by Rafa Pérez <ra...@gmail.com>.
Try changing

>        <tr:forEach var="year" begin="#0" end="10">
>                <tr:selectItem label="#{year}" value="#{year}" />
>        </tr:forEach>

for:

<f:selectItems value="#{bean.selectItemArray}"  />

And in the bean add (with its getter and setter):

private SelectItem[] selectItemArray;


Then, to load the array you just have to do:

selectItemArray = new SelectItemArray[1];

selectItemArray[0] = new SelectItem(year, year.toString());


HTH


On Wed, Sep 17, 2008 at 11:19 AM, tkazmierczak <T....@ecofys.com> wrote:
>
> Ok, now my code looks like this:
>
> <tr:selectOneChoice label="Start year" value="#{bean.initialValue}"
> required="true" valuePassThru="true">
>        <tr:forEach var="year" begin="#0" end="10">
>                <tr:selectItem label="#{year}" value="#{year}" />
>        </tr:forEach>
> </tr:selectOneChoice>
>
> the bean.initialValue is set to 1 in the declaration of the member (private
> int initialValue = 1;)
> but this doesn't help. I get such warning:
>
> 2008-09-17 11:08:18
> org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.SimpleSelectOneRenderer
> _getSelectedIndex
> WARNING: Could not find selected item matching value "1" in
> CoreSelectOneChoice[UIXEditableFacesBeanImpl, id=_idJsp9]
>
> As you might have noticed, the combo-box will store years, so the values
> will be greater than 1000. When I put, for example, 2008 as the
> initialValue, and iterate from 2008 to 2050, the warning says:
> Could not find selected item matching value "2 008" in CoreSelectOneChoice
> So it seems that the value is converted from an integer to a string... Maybe
> that's the problem? If so, then how to force the selectOneChoice and
> selectItem to compare the values as integers?
>
>
> Richard Yee-3 wrote:
>>
>> You should have the value attribute in the selectOneChoice be an EL
>> expression that references a field in your backing bean. If you do
>> this and set the value of the field to "1" when the bean is created,
>> it will be defaulted as you expect. With your current code, there is
>> no way of submitting the value of the selectOneChoice.
>>
>> -Richard
>>
>> On Tue, Sep 9, 2008 at 7:34 AM, tkazmierczak <T....@ecofys.com>
>> wrote:
>>>
>>> Hello,
>>> I've searched half of the Internet, but haven't found an answer to my
>>> question.
>>>
>>> I create a tr:selectOneChoice this way:
>>>
>>> <tr:selectOneChoice label="Start year" value="1" required="true"
>>> valuePassThru="true">
>>>        <tr:forEach var="year" begin="0" end="10">
>>>                <tr:selectItem label="#{year}" value="#{year}" />
>>>        </tr:forEach>
>>> </tr:selectOneChoice>
>>>
>>> and want the resulting HTML combobox to have the value with label "1" set
>>> by
>>> default, but what I get is that the combobox is set to an "empty" value
>>> and
>>> I get this error message in the server's output:
>>>
>>> 2008-09-09 15:54:23
>>> org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.SimpleSelectOneRenderer
>>> _getSelectedIndex
>>> WARNING: Could not find selected item matching value "1" in
>>> CoreSelectOneChoice[UIXEditableFacesBeanImpl, id=_idJsp9]
>>>
>>> What is wrong/missing in the code?
>>> I'm using Trinidad 1.0.7.
>>> --
>>> View this message in context:
>>> http://www.nabble.com/default-value-in-tr%3AselectOneChoice-tp19393693p19393693.html
>>> Sent from the MyFaces - Users mailing list archive at Nabble.com.
>>>
>>>
>>
>>
>
> --
> View this message in context: http://www.nabble.com/default-value-in-tr%3AselectOneChoice-tp19393693p19527785.html
> Sent from the MyFaces - Users mailing list archive at Nabble.com.
>
>

Re: default value in tr:selectOneChoice

Posted by tkazmierczak <T....@ecofys.com>.
Ok, now my code looks like this:

<tr:selectOneChoice label="Start year" value="#{bean.initialValue}"
required="true" valuePassThru="true">
	<tr:forEach var="year" begin="#0" end="10">
		<tr:selectItem label="#{year}" value="#{year}" />
	</tr:forEach>
</tr:selectOneChoice>

the bean.initialValue is set to 1 in the declaration of the member (private
int initialValue = 1;)
but this doesn't help. I get such warning:

2008-09-17 11:08:18
org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.SimpleSelectOneRenderer
_getSelectedIndex
WARNING: Could not find selected item matching value "1" in
CoreSelectOneChoice[UIXEditableFacesBeanImpl, id=_idJsp9]

As you might have noticed, the combo-box will store years, so the values
will be greater than 1000. When I put, for example, 2008 as the
initialValue, and iterate from 2008 to 2050, the warning says:
Could not find selected item matching value "2 008" in CoreSelectOneChoice
So it seems that the value is converted from an integer to a string... Maybe
that's the problem? If so, then how to force the selectOneChoice and
selectItem to compare the values as integers?


Richard Yee-3 wrote:
> 
> You should have the value attribute in the selectOneChoice be an EL
> expression that references a field in your backing bean. If you do
> this and set the value of the field to "1" when the bean is created,
> it will be defaulted as you expect. With your current code, there is
> no way of submitting the value of the selectOneChoice.
> 
> -Richard
> 
> On Tue, Sep 9, 2008 at 7:34 AM, tkazmierczak <T....@ecofys.com>
> wrote:
>>
>> Hello,
>> I've searched half of the Internet, but haven't found an answer to my
>> question.
>>
>> I create a tr:selectOneChoice this way:
>>
>> <tr:selectOneChoice label="Start year" value="1" required="true"
>> valuePassThru="true">
>>        <tr:forEach var="year" begin="0" end="10">
>>                <tr:selectItem label="#{year}" value="#{year}" />
>>        </tr:forEach>
>> </tr:selectOneChoice>
>>
>> and want the resulting HTML combobox to have the value with label "1" set
>> by
>> default, but what I get is that the combobox is set to an "empty" value
>> and
>> I get this error message in the server's output:
>>
>> 2008-09-09 15:54:23
>> org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.SimpleSelectOneRenderer
>> _getSelectedIndex
>> WARNING: Could not find selected item matching value "1" in
>> CoreSelectOneChoice[UIXEditableFacesBeanImpl, id=_idJsp9]
>>
>> What is wrong/missing in the code?
>> I'm using Trinidad 1.0.7.
>> --
>> View this message in context:
>> http://www.nabble.com/default-value-in-tr%3AselectOneChoice-tp19393693p19393693.html
>> Sent from the MyFaces - Users mailing list archive at Nabble.com.
>>
>>
> 
> 

-- 
View this message in context: http://www.nabble.com/default-value-in-tr%3AselectOneChoice-tp19393693p19527785.html
Sent from the MyFaces - Users mailing list archive at Nabble.com.


Re: default value in tr:selectOneChoice

Posted by Richard Yee <ri...@gmail.com>.
You should have the value attribute in the selectOneChoice be an EL
expression that references a field in your backing bean. If you do
this and set the value of the field to "1" when the bean is created,
it will be defaulted as you expect. With your current code, there is
no way of submitting the value of the selectOneChoice.

-Richard

On Tue, Sep 9, 2008 at 7:34 AM, tkazmierczak <T....@ecofys.com> wrote:
>
> Hello,
> I've searched half of the Internet, but haven't found an answer to my
> question.
>
> I create a tr:selectOneChoice this way:
>
> <tr:selectOneChoice label="Start year" value="1" required="true"
> valuePassThru="true">
>        <tr:forEach var="year" begin="0" end="10">
>                <tr:selectItem label="#{year}" value="#{year}" />
>        </tr:forEach>
> </tr:selectOneChoice>
>
> and want the resulting HTML combobox to have the value with label "1" set by
> default, but what I get is that the combobox is set to an "empty" value and
> I get this error message in the server's output:
>
> 2008-09-09 15:54:23
> org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.SimpleSelectOneRenderer
> _getSelectedIndex
> WARNING: Could not find selected item matching value "1" in
> CoreSelectOneChoice[UIXEditableFacesBeanImpl, id=_idJsp9]
>
> What is wrong/missing in the code?
> I'm using Trinidad 1.0.7.
> --
> View this message in context: http://www.nabble.com/default-value-in-tr%3AselectOneChoice-tp19393693p19393693.html
> Sent from the MyFaces - Users mailing list archive at Nabble.com.
>
>

Re: default value in tr:selectOneChoice

Posted by tkazmierczak <T....@ecofys.com>.
This seems to help, but partially - the form indeed has now the value set to
1, but it is no longer a combobox, but rather an outputText. I think that
this is caused by the fact that when you set the value this way
(value="#{1}") then it is read-only.


Stephen Friedrich-4 wrote:
> 
> Just a guess: Try value="#{1}"
> 
> tkazmierczak wrote:
>> Hello,
>> I've searched half of the Internet, but haven't found an answer to my
>> question.
>> 
>> I create a tr:selectOneChoice this way:
>> 
>> <tr:selectOneChoice label="Start year" value="1" required="true"
>> valuePassThru="true">
>> 	<tr:forEach var="year" begin="0" end="10">
>> 		<tr:selectItem label="#{year}" value="#{year}" />
>> 	</tr:forEach>
>> </tr:selectOneChoice>
>> 
>> and want the resulting HTML combobox to have the value with label "1" set
>> by
>> default, but what I get is that the combobox is set to an "empty" value
>> and
>> I get this error message in the server's output:
>> 
>> 2008-09-09 15:54:23
>> org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.SimpleSelectOneRenderer
>> _getSelectedIndex
>> WARNING: Could not find selected item matching value "1" in
>> CoreSelectOneChoice[UIXEditableFacesBeanImpl, id=_idJsp9]
>> 
>> What is wrong/missing in the code?
>> I'm using Trinidad 1.0.7.
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/default-value-in-tr%3AselectOneChoice-tp19393693p19527792.html
Sent from the MyFaces - Users mailing list archive at Nabble.com.


Re: default value in tr:selectOneChoice

Posted by Stephen Friedrich <tr...@eekboom.com>.
Just a guess: Try value="#{1}"

tkazmierczak wrote:
> Hello,
> I've searched half of the Internet, but haven't found an answer to my
> question.
> 
> I create a tr:selectOneChoice this way:
> 
> <tr:selectOneChoice label="Start year" value="1" required="true"
> valuePassThru="true">
> 	<tr:forEach var="year" begin="0" end="10">
> 		<tr:selectItem label="#{year}" value="#{year}" />
> 	</tr:forEach>
> </tr:selectOneChoice>
> 
> and want the resulting HTML combobox to have the value with label "1" set by
> default, but what I get is that the combobox is set to an "empty" value and
> I get this error message in the server's output:
> 
> 2008-09-09 15:54:23
> org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.SimpleSelectOneRenderer
> _getSelectedIndex
> WARNING: Could not find selected item matching value "1" in
> CoreSelectOneChoice[UIXEditableFacesBeanImpl, id=_idJsp9]
> 
> What is wrong/missing in the code?
> I'm using Trinidad 1.0.7.